Commit graph

64 commits

Author SHA1 Message Date
Bas Nijholt
68feb3d931
Make instantaneous light.turn_on adaptation configurable with intercept (#750)
* Make intercept configurable

* Update README.md, strings.json, and services.yaml

* import

* skip

* split

* do not pass config_entry

* add to conf

* Update README.md, strings.json, and services.yaml

* spacing

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-08-15 12:23:56 -07:00
Bas Nijholt
435b2ce5d0
Fix adapt_only_on_bare_turn_on and apply does not result in manual_control (#729)
* Fix adapt_only_on_bare_turn_on and apply does not result in manual_control

Closes #723

* fix style
2023-08-09 21:48:18 +00:00
Bas Nijholt
f8e7880a96
Split up SunLightSettings and improve https://basnijholt.github.io/adaptive-lighting/ (#719)
* Split up SunLightSettings

* Renames

* factor out SunEvents

* more renames

* rewrite

* rewrite more

* simpler

* refactor

* refact

* raise

* refact

* rename

* move method

* clean

* Move to new module 'sun.py'

* make sun independent of HA

* rename

* Move to webapp/homeassistant_util_color.py

* Rework app

* Add link

* new plotting

* app changes

* fix tests

* test clean

* tz fixes

* fix

* use sed

* verbose

* fix tz

* fix

* tiem
2023-08-08 21:31:17 +00:00
Bas Nijholt
cb9ae39ee4
Fix adaptive_lighting.change_switch_settings service (#712)
* Fix adaptive_lighting.change_switch_settings service

Closes #623

* filter defaults

* fix mutable

* Revert debugging logs
2023-08-06 11:15:14 -07:00
Bas Nijholt
d44cb66148
Add adapt_only_on_bare_turn_on which instantly triggers manual_control when turning on with brightness or color (#709) 2023-08-05 20:56:32 -07:00
Bas Nijholt
a1cec19351
feat: add different brightness ramping mechanisms (#699)
* feat: add different brightness ramping mechanisms

* Rephrase

* Fix curves

* update images

* link to other graphs

* update images
2023-08-05 20:14:21 +00:00
Bas Nijholt
1ef7ed507e
Implement call intercept for multiple lights (#679)
* Implement call intercept for multiple lights

* remove comment

* skip if no eids

* add comment

* fix type

* Fix skipped

* indentation

* Add logging and fix error

* Fix for HA ≤2023.04

* simplify

* remove unused ignores

* Debug mode

* Add test

* Make test failing

* rename switch

* rename lights

* Fix tests

* Rename lights in tests

* Remove unused dependencies

* Improve tests

* More tests

* Remove the DEBUG_MODE

* Add doc-string

* Extra test

* assert

* extra test

* Comments

* fix

* fix

* expand light groups

* more logging

* sort

* Revert is_proactively_adapting checks
This reverts commit 39fd8f2be0.

* simplify the mapping

* Revert "Revert is_proactively_adapting checks"

This reverts commit 18803e8e50.

* test

* no light groups

* do not expand

* Do not expand_light_groups in intercept

* more logging

* Fix

* add comment

* Add multi_light_intercept config option

* Update README.md, strings.json, and services.yaml

* add light group

* fix platform

* add simple test

* turn off again

* Test without take over control

* improve test and fix it in one way

* Fixes

* add cleanup fixture

* format

* Update test_switch.py

* add __str__

* remove unneeded call

* simplify service_data construction

* Generalize is_our_context

* Fix multi_light_intercept: false

* add comments

* add docs

* Update README.md, strings.json, and services.yaml

* Add feature line

* move function

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-08-03 17:47:09 -07:00
Bas Nijholt
e0e04da0f6
Before scheduling turn_on do a last-minute check if lights are off (#671)
* Before scheduling turn_on do a last-minute check if lights are off

* Pass force

* add comment

* fix for proactive

* commetn

* No default for force

* rm newline

* no force

* Return bool
2023-08-02 23:11:45 -07:00
Bas Nijholt
e513393653
Keep on and off state tracking in Manager and listen to toggle (#689)
* Keep on and off state tracking in Manager

* Move manual_control code

* add todo

* check is_on

* Track toggle

* handle toggle

* fix debug

* test

* add comment

* better log

* Fix comment

* log

* test

* get

* check

* cancel early

* rephrase

* add assert

* Remove check
2023-07-31 18:40:32 -07:00
Bas Nijholt
d588a5984a
Refactor _update_attrs_and_maybe_adapt_lights (#688)
* Do not call self.manager.significant_change when not needed

* refact

* fix

* fix

* Add more logging to tests

* remove
2023-07-31 04:57:30 +00:00
Bas Nijholt
f4d872a540
Make sure that SimpleSwitches are added before AdaptiveSwitch (#686) 2023-07-30 20:01:08 +00:00
Bas Nijholt
68985199f6
Rename lights in tests (#681)
* Rename lights in tests

* Remove unused dependencies
2023-07-30 04:48:45 +00:00
Bas Nijholt
5c897f76da
More typing fixes (#675) 2023-07-29 00:17:26 +00:00
Bas Nijholt
89c90adde0
Only start adapting on light.turn_on when detect_non_ha_changes: false to prevent unwanted light turn ons (#663)
* Fixes in maybe_cancel_adjusting to possibly fix accidental turn on

* simplify logic in maybe_cancel_adjusting

* Add logging statements

* only control if turn_on called

* more logs

* add TODO

* Add _state_event_is_from_our_turn_on

* Ignore off->on state switches that are not accociated with light.turn_on

* improve logging

* rename

* Update docs

* Update README.md, strings.json, and services.yaml

* Add caution message to README

* Change order of emojis

* Update README.md, strings.json, and services.yaml

* Check that platform is not None

* log the call

* fix args

* Do not re-add already added configs

* Do not re-add already added configs

* Use async_remove

* remove unused code

* [pre-commit.ci] pre-commit autoupdate (#627)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.279 → v0.0.280](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.279...v0.0.280)
- [github.com/psf/black: 23.3.0 → 23.7.0](https://github.com/psf/black/compare/23.3.0...23.7.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bas Nijholt <basnijholt@gmail.com>

* Extra logging statement

* Add to README

* log context_id

* return right indent

* move comment

* Skip on self.manager.is_proactively_adapting

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-07-28 15:17:17 -07:00
Bas Nijholt
8696092879
Avoid adapting lights with nothing in service_data, closes #661 (#662) 2023-07-26 02:17:11 +00:00
Bas Nijholt
f9b6753e6d
Ensure that interpolation is in [0, 1], fixes #624 (#660)
* Ensure that interpolation is in [0, 1], fixes #624

* Bump to 1.17.1

* Add assert

* Interpolate via HSV space

* Add test
2023-07-25 10:46:34 -07:00
Bas Nijholt
97f388608a
With transition_until_sleep and sleep_rgb, after sunset, use RGB colors (#656)
* With transition_until_sleep and sleep_rgb, after sunset, use RGB colors

Closes #624

* Add comment

* Add test
2023-07-23 13:40:03 -07:00
Bas Nijholt
c1528ec10a
Refactor, simplify code, rename, and set minimal HA core ≥2022.11 (#655)
* Rename TurnOnOffListener to AdaptiveLightingManager

* Bump Python version

* Refactor and unify methods that are called once

* Simplify adaptation_utils.py

* Improve readability in adaptation_utils.py

* More renames

* Simplify

* More renames and simplifications

* fix test

* simplify _supported_features

* rename

* walrus

* drop old astral support

* Only support HA  ≥2021.06

* Require 2016.06

* Try 2023.1

* even more old versions

* test

* more versions

* verify that only ≥2022.11 works

* named args

* setdefault

* no astral v1

* var

* simplify

* no need to pass adapt_brightness and adapt_color

* Add comment
2023-07-22 21:19:01 -07:00
Bas Nijholt
69592938db
Rename TurnOnOffListener to AdaptiveLightingManager (#654)
* Rename TurnOnOffListener to AdaptiveLightingManager

* Bump Python version
2023-07-22 17:57:49 -07:00
Bas Nijholt
49857632cc
Fix multiple switches controlling one light (reactive path) (#644)
* Fix multiple switches controlling one light

* WIP

* Keep length in AdaptationData

* Do not proceed if there is nothing to do

* Simplify

* Set tasks correctly

* log more

* WIP

* realize that intercept and double switch not possible

* Remove which from find_switch_for_lights

* Rephrase

* Check which one to cancel

* length -> max_length

* Implement test_two_switches_for_single_light

* Clean up

* Simplify is_color_brightness_or_both

* Improve test

* no wait

* logging

* just block

* make test such that it fails on main
2023-07-21 14:46:18 -07:00
Bas Nijholt
19d503b4d7
Revert supported_features from #565 and #575, fixes #601 (#637) 2023-07-20 13:59:19 -07:00
Mario Guggenberger
ed80bd7829
feat: service call adaptation (#628)
* feat: service call adaptation

* feat: toggle-on service call adaptation

* feat: prefer service call transition
2023-07-19 09:10:21 +02:00
Mario Guggenberger
72e140e293
feat: skip redundant adaptation commands (#615)
* feat: skip redundant adaptation commands

* update README

* style

* Remove "experimental"

---------

Co-authored-by: Bas Nijholt <basnijholt@gmail.com>
Co-authored-by: Bas Nijholt <bas@nijho.lt>
2023-07-02 15:26:07 -07:00
Mario Guggenberger
6283158ff7
VS Code Dev Container (dev & test environment) (#605)
* build: dev container

Add a VS Code Dev Container from the blueprint at bceaae212f

* build: dev container test setup

Add support for unit testing in the dev container environment with debugging and code coverage.

* ci: adjust to dev container test restructuring

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* ci: fix coverage collection

* build: add dummy light to HA config

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* build: update dev container to Python 3.11 (for HA 2023.6)

* Add VS Code tasks

* Use pre-commit hooks for linting

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Unpin HA version

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bas Nijholt <basnijholt@gmail.com>
2023-06-11 15:33:07 -07:00
Mario Guggenberger
2c8a45604a
feat: brightness prioritization (#598)
* feat: optional brightness prioritization

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove config flag and change default split order

* Fix test

* Fix edge case

* Add tests

* Backwards compatiblity

* Fix another edge case

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-06-08 16:01:19 -07:00
Benjamin Auquite
47c5ea93e0
Add test_supported_features and fix the problem introduced in #565 (#575)
* Update test_switch.py

* Update test_switch.py

* test is now done.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix the test only.

test is backwards compatible with the old method.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix _supported_to_attributes

everything works now.

* pre-commit fixes

cannot fix the `function too complex` problem.

* ignore test_switch.py in `pre-commit-config.yaml`

* Add ignore C901 to test_supported_features

* remove commented out code

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bas Nijholt <basnijholt@gmail.com>
Co-authored-by: Bas Nijholt <bas@nijho.lt>
2023-04-27 12:56:49 -07:00
Bas Nijholt
fe7bdd3940
Add auto_reset_time_remaining attribute (#558)
* Add auto_reset_time_remaining attribute

* fix attr

* Add test
2023-04-08 05:39:08 -05:00
Bas Nijholt
c0c363136b
Test multiple Home Assistant releases and the dev branch (#552)
* Test for multiple Home Assistant versions

* Install ulid-transform

* remove unnecessary unsafe `async_set` from test

* Skip test_state_change_handlers in <2023.4

* Revert "Skip test_state_change_handlers in <2023.4"

This reverts commit 8d01b6ec4e.

---------

Co-authored-by: Benjamin Auquite <halomastar@gmail.com>
2023-04-06 16:36:57 -07:00
Bas Nijholt
59877a0343
Make sure context_id is 26 chars and partially conform to ULID standard (#550) 2023-04-06 12:37:02 -07:00
Benjamin Auquite
cb967aeeb7
Create intentionally over-redundant state_change tests and fix #541 (#544)
* add transition_timer test and debug

* syntax error

* test

* Update switch.py

* Revert "test"

This reverts commit b8009e0a1a.

* Update test_switch.py

* add `create_transition_events` to tests.

nearly done

* tests are done!

* pop is for dictionaries

* Update test_switch.py

* combine the tests

* pin markdown-code-runner

* Pin with '=='

* Update test_switch.py

* pin in the correct place 😅

* Update test_switch.py

* Use timer.is_running

* Update test_switch.py

* ensure timer is running in tests

* this passes the test

* Update test_switch.py

* Do not create new list when not needed

* Remove empty deps

* Remove CONF_ULID_MAX_LENGTH (which is not configurable)

* this shouldn't pass the test but it does.

---------

Co-authored-by: Bas Nijholt <basnijholt@gmail.com>
Co-authored-by: Bas Nijholt <bas@nijho.lt>
2023-04-06 13:53:23 -05:00
Benjamin Auquite
03a2d9cbf6
Fix RGB Color Temp Swaps (#514)
* cherry pick from 486

* Refactor `_add_missing_attributes`

---------

Co-authored-by: Bas Nijholt <bas@nijho.lt>
2023-04-05 18:39:31 -05:00
Benjamin Auquite
f5abf034c4
Fix the docker tests instructions (#543)
* Tested on multiple hardware

Turns out windows 10 and 11 can't use `$(pwd):/app` OR `%cd%:/app` in PowerShell (which replaced cmd prompt), so I looked up the docs and made the necessary changes (again, sorry!)

These changes have been tested on all terminal environments except macOS (the docs say it'll work there)

* allow use of --exitfirst for faster debug

* Remove install in actions

---------

Co-authored-by: Bas Nijholt <basnijholt@gmail.com>
Co-authored-by: Bas Nijholt <bas@nijho.lt>
2023-04-05 09:13:57 -07:00
Benjamin Auquite
e4d06476fd
Add windows command for Docker test instructions (#536)
* ( Tiny Change ) Add windows command for dockertest

You said it earlier but the correct command for running the Docker image on windows is:
```bash
docker run -v %cd%:/app basnijholt/adaptive-lighting:latest
```

* Update README.md

---------

Co-authored-by: Bas Nijholt <basnijholt@gmail.com>
2023-04-03 23:47:08 -07:00
Benjamin Auquite
c7f44e472f
Correctly wait for transitions (#510)
* Add auto_reset_manual_control with async timer

* cherry-pick wait for transition stuff

* Update switch.py

* not renamed in this branch yet.

* Update switch.py

* update tests

* Update switch.py

* merge related fix

* cleanup

* Revert "cleanup"

This reverts commit 3aa2f3242b.

* Update switch.py

* Update switch.py

* Update switch.py

* Small refactor

* Move test to old position for better diffs

* Revert "Small refactor"

This reverts commit b986b3f77c.

* Update README.md

* fix the test

last_state_change isn't updated quick enough.

* #510 changes (#516)

* Change (WIP)

* Update test_switch.py

* Refactor

* Revert "Revert "Small refactor""

This reverts commit 3731c99936.

* Update README.md

* Fix the test

* Bump to 1.9.0 (#518)

* Basic community fixes PR (#460)

* Fixes #423

#423

* Do not adapt lights turned on with custom payloads.

* Update switch.py

* Issue fixes

#423, #378, #403, #449

* quickly test #274

* Revert feature requests, this branch only has fixes.

Reverted FR 274

* pre-commit fix

* Create automerge.yaml

* test

* Delete automerge.yaml

My bad.

* Fix #460 and #408

* see @basnijholt 's comment in #450.

* @basnijholt requested changes.

---------

Co-authored-by: Bas Nijholt <bas@nijho.lt>

* Undo accidental changes introduced in #509, but adds the changes from #460 (#521)

* Release 1.9.1 (#522)

* Bump to 1.9.1

* Add CODEOWNERS

---------

Co-authored-by: Benjamin Auquite <halomastar@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* No need to wrap the reset

* Remove unused attrs

* Shorter log message

* revert unrelated tests change

* remove unused function

* Use patch

* Bump to 1.10.0

---------

Co-authored-by: Bas Nijholt <bas@nijho.lt>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Bas Nijholt <basnijholt@gmail.com>
2023-04-03 17:04:06 -07:00
Benjamin Auquite
c6a6cd323f
Basic community fixes PR (#460)
* Fixes #423

#423

* Do not adapt lights turned on with custom payloads.

* Update switch.py

* Issue fixes

#423, #378, #403, #449

* quickly test #274

* Revert feature requests, this branch only has fixes.

Reverted FR 274

* pre-commit fix

* Create automerge.yaml

* test

* Delete automerge.yaml

My bad.

* Fix #460 and #408

* see @basnijholt 's comment in #450.

* @basnijholt requested changes.

---------

Co-authored-by: Bas Nijholt <bas@nijho.lt>
2023-04-03 08:02:06 +00:00
Bas Nijholt
ea2a6b0173
Add auto_reset_manual_control with async timer (#487)
* Add auto_reset_manual_control with async timer

* Add failing test

* Debugging

* Refactor find_switch_for_lights

* Revert changes in is_manually_controlled

* style

* Fix test_manual_control

* add types

* fixes

* dict

* make all tests pass

* text

* Rework find_switch_for_lights

* Style

* Better check

* revert, do in other test!

* No need to log when raising

* Add type hint

* Suggestion https://github.com/basnijholt/adaptive-lighting/pull/488/files#r1152408541 by @th3w1zard1

* Small fixes

* document new config everywhere (#496)

* chore(docs): update TOC

* undo change

* fi

* Update README.md

* Update README.md

* chore(docs): update TOC

* Update README.md

* Use markdown-code-runner

* Remove

* Use markdown-code-runner instead of packaged solution

* fix comment

* Only commit when needed

---------

Co-authored-by: Benjamin Auquite <halomastar@gmail.com>
Co-authored-by: basnijholt <basnijholt@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-04-03 02:22:23 +00:00
Bas Nijholt
1ca3bf0f6a
Retroactive review changes for #443 (#485)
* Retroactive review changes for #443

* Move up __init__

* Add test for test_change_switch_settings_service

* Add docs

* Add test for defaults

* Remove unused function

* Add skip var

* move pylint marker

* Refactor validate

* Update README.md

---------

Co-authored-by: Benjamin Auquite <halomastar@gmail.com>
2023-03-27 20:56:54 -05:00
Bas Nijholt
0127496441
Add example of how to pass command line args (#483) 2023-03-27 05:47:50 +00:00
Bas Nijholt
85461ea856
Always color the logs and print coverage report (#481) 2023-03-27 04:37:21 +00:00
Bas Nijholt
aa282c83b2
Fix Markdown URL (#479) 2023-03-26 19:50:40 -07:00
Bas Nijholt
a523cccb04
Add command to print pytest with colors in Docker (#473) 2023-03-27 01:46:36 +00:00
Bas Nijholt
1b08e8e6ba
Add testing Dockerfile (#470)
* Add testing Dockerfile

* Add comments

* Format table

* Add tests/README.md

* Rephrase

* add note in dockerfile
2023-03-27 01:18:18 +00:00
Benjamin Auquite
06dcdbb4a4
Fix the broken tests (#467)
* Update test_dependencies.py

pytest reversion todo in later commit

* increase verbosity for analysis

* "instance" was created in the basic features PR.

* Can't stand the deprecation warnings.

* add testing steps to workflow action in logs.

Help the next person running into this issue again.

* wording in new messages.

* Manifest keys should be sorted: domain, name, then alphabetical order

* return basnijholt's original settings.

replaced `-v` with `-qq` again in `pytest.yaml`,
returned `branches: [master]` in both yaml files.

* Forgot a comma

* Update version in manifest to 1.6.0

* @th3w1zard1 is a code owner!

* Update .gitignore

* Revert "Update .gitignore"

This reverts commit 172841d356.
2023-03-26 15:04:13 -07:00
Bas Nijholt
1ef55ca180
Use Kelvin instead of Mired, default since core=2022.11 (#375)
* Use Kelvin instead of Mired, default since core=2022.11

* Fix attributes

* Use ATTR_COLOR_TEMP_KELVIN in tests

* use kelvin in tests

* no duplicate

* Round to nearest 5
2022-12-11 16:54:57 -08:00
Bas Nijholt
70899dfe22 Remove area_id from entity_registry.async_get_or_create, closes #356 2022-11-06 15:17:58 -08:00
Bas Nijholt
48b7bc4398 Fix test_area 2022-08-29 19:36:15 -07:00
Bas Nijholt
7bcd70cbec Add TODO to the test 2022-08-29 19:25:04 -07:00
Bas Nijholt
b64c44fc8d Use area_entities to extract entity_ids from area 2022-08-29 18:51:24 -07:00
Bas Nijholt
17061f360f Add test_area test, reproduce issue of #75 2022-08-29 18:28:54 -07:00
Bas Nijholt
6b3686696b Fix pre-commit issues 2022-08-29 09:25:38 -07:00