From 9caf64509349958a340f8cef9207fdb0ea35dbef Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 May 2023 16:56:03 -0700 Subject: [PATCH 1/5] [pre-commit.ci] pre-commit autoupdate (#584) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v3.3.1 β†’ v3.3.2](https://github.com/asottile/pyupgrade/compare/v3.3.1...v3.3.2) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 462e0dc2..1dbf741d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: hooks: - id: black - repo: https://github.com/asottile/pyupgrade - rev: v3.3.1 + rev: v3.3.2 hooks: - id: pyupgrade args: ["--py39-plus"] From 29e54185e3218d0692cd7a3f3be7607f411cc71c Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Fri, 12 May 2023 11:36:24 -0700 Subject: [PATCH 2/5] Add "See also" to README (#591) * Add "See also" section * Add date * chore(docs): update TOC * Add YouTube videos * Add components.cloud * verbose loggin --------- Co-authored-by: basnijholt --- .github/workflows/pytest.yaml | 3 +- README.md | 56 +++++++++++++++++++---------------- test_dependencies.py | 1 + 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index 394acef3..4973849f 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: python-version: ["3.10"] - core-version: ["2023.2.5", "2023.3.6", "2023.4.6", "dev"] + core-version: ["2023.2.5", "2023.3.6", "2023.4.6", "2023.5.2", "dev"] steps: - name: Check out code from GitHub uses: actions/checkout@v3 @@ -54,6 +54,7 @@ jobs: run: | cd core python3 -X dev -m pytest \ + -vvv \ -qq \ --timeout=9 \ --durations=10 \ diff --git a/README.md b/README.md index 9ba7cc03..d1895b91 100644 --- a/README.md +++ b/README.md @@ -41,27 +41,28 @@ The `adaptive_lighting.manual_control` event is fired when a light is marked as - - [:gear: Configuration](#gear-configuration) - - [:memo: Options](#memo-options) - - [:hammer_and_wrench: Services](#hammer_and_wrench-services) - - [`adaptive_lighting.apply`](#adaptive_lightingapply) - - [`adaptive_lighting.set_manual_control`](#adaptive_lightingset_manual_control) - - [`adaptive_lighting.change_switch_settings`](#adaptive_lightingchange_switch_settings) - - [:robot: Automation examples](#robot-automation-examples) +- [:gear: Configuration](#gear-configuration) + - [:memo: Options](#memo-options) + - [:hammer_and_wrench: Services](#hammer_and_wrench-services) + - [`adaptive_lighting.apply`](#adaptive_lightingapply) + - [`adaptive_lighting.set_manual_control`](#adaptive_lightingset_manual_control) + - [`adaptive_lighting.change_switch_settings`](#adaptive_lightingchange_switch_settings) +- [:robot: Automation examples](#robot-automation-examples) - [Additional Information](#additional-information) - [:sos: Troubleshooting](#sos-troubleshooting) - [:exclamation: Common Problems & Solutions](#exclamation-common-problems--solutions) - [:bulb: Lights Not Responding or Turning On by Themselves](#bulb-lights-not-responding-or-turning-on-by-themselves) - - [:signal_strength: WiFi Networks](#signal_strength-wifi-networks) - - [:spider_web: Zigbee, Z-Wave, and Other Mesh Networks](#spider_web-zigbee-z-wave-and-other-mesh-networks) + - [:signal_strength: WiFi Networks](#signal_strength-wifi-networks) + - [:spider_web: Zigbee, Z-Wave, and Other Mesh Networks](#spider_web-zigbee-z-wave-and-other-mesh-networks) - [:rainbow: Light Colors Not Matching](#rainbow-light-colors-not-matching) - [:bulb: Bulb-Specific Issues](#bulb-bulb-specific-issues) - - [:bar_chart: Graphs!](#bar_chart-graphs) - - [:sunny: Sun Position](#sunny-sun-position) - - [:thermometer: Color Temperature](#thermometer-color-temperature) - - [:high_brightness: Brightness](#high_brightness-brightness) - - [While using `transition_until_sleep: true`](#while-using-transition_until_sleep-true) - - [:busts_in_silhouette: Contributors](#busts_in_silhouette-contributors) +- [:bar_chart: Graphs!](#bar_chart-graphs) + - [:sunny: Sun Position](#sunny-sun-position) + - [:thermometer: Color Temperature](#thermometer-color-temperature) + - [:high_brightness: Brightness](#high_brightness-brightness) + - [While using `transition_until_sleep: true`](#while-using-transition_until_sleep-true) +- [:eyes: See also](#eyes-see-also) +- [:busts_in_silhouette: Contributors](#busts_in_silhouette-contributors) @@ -310,13 +311,13 @@ iphone_carly_wakeup: -# Additional Information +## Additional Information For more details on adding the integration and setting options, refer to the [documentation of the PR](https://deploy-preview-14877--home-assistant-docs.netlify.app/integrations/adaptive_lighting/) and [this video tutorial on Reddit](https://www.reddit.com/r/homeassistant/comments/jabhso/ha_has_it_before_apple_has_even_finished_it_i/). Adaptive Lighting was initially inspired by @claytonjn's [hass-circadian\_lighting](https://github.com/claytonjn/hass-circadian_lighting), but has since been entirely rewritten and expanded with new features. -# :sos: Troubleshooting +## :sos: Troubleshooting Encountering issues? Enable debug logging in your `configuration.yaml`: @@ -329,9 +330,9 @@ logger: After the issue occurs, create a new issue report with the log (`/config/home-assistant.log`). -## :exclamation: Common Problems & Solutions +### :exclamation: Common Problems & Solutions -### :bulb: Lights Not Responding or Turning On by Themselves +#### :bulb: Lights Not Responding or Turning On by Themselves Adaptive Lighting sends more commands to lights than a typical human user would. If your light control network is unhealthy, you may experience: @@ -353,7 +354,7 @@ For most Zigbee networks, **using groups is essential for optimal performance**. As a rule of thumb, if you always control lights together (e.g., bulbs in a ceiling fixture), they should be in a Zigbee group. Expose only the group (not individual bulbs) in Home Assistant Dashboards and external systems like Google Home or Apple HomeKit. -### :rainbow: Light Colors Not Matching +#### :rainbow: Light Colors Not Matching Bulbs from different manufacturers or models may have varying color temperature specifications. For instance, if you have two Adaptive Lighting configurationsβ€”one with only Philips Hue White Ambiance bulbs and another with a mix of Philips Hue White Ambiance and Sengled bulbsβ€”the Philips Hue bulbs may appear to have different color temperatures despite having identical settings. @@ -362,7 +363,7 @@ To resolve this: 1. Include only bulbs of the same make and model in a single Adaptive Lighting configuration. 2. Rearrange bulbs so that different color temperatures are not visible simultaneously. -### :bulb: Bulb-Specific Issues +#### :bulb: Bulb-Specific Issues Certain bulbs may have issues with long light transition commands: @@ -372,18 +373,23 @@ Certain bulbs may have issues with long light transition commands: ## :bar_chart: Graphs! These graphs were generated using the values calculated by the Adaptive Lighting sensor/switch(es). -#### :sunny: Sun Position +### :sunny: Sun Position ![cl_percent|690x131](https://community-home-assistant-assets.s3.dualstack.us-west-2.amazonaws.com/original/3X/6/5/657ff98beb65a94598edeb4bdfd939095db1a22c.PNG) -#### :thermometer: Color Temperature +### :thermometer: Color Temperature ![cl_color_temp|690x129](https://community-home-assistant-assets.s3.dualstack.us-west-2.amazonaws.com/original/3X/5/9/59e84263cbecd8e428cb08777a0413672c48dfcd.PNG) -#### :high_brightness: Brightness +### :high_brightness: Brightness ![cl_brightness|690x130](https://community-home-assistant-assets.s3.dualstack.us-west-2.amazonaws.com/original/3X/5/8/58ebd994b62a8b1abfb3497a5288d923ff4e2330.PNG) -#### While using `transition_until_sleep: true` +### While using `transition_until_sleep: true` ![image](https://user-images.githubusercontent.com/2219836/228949675-f9699624-8abc-466c-bb04-250ce0f495b8.png) +## :eyes: See also + +- [*Sleep better with Adaptive Lighting in Home Assistant*](https://wartner.io/sleep-better-with-adaptive-lightning-in-home-assistant/) by Florian Wartner on 2023-02-23 (blog post πŸ“œ) +- [*Automatic smart light brightness and color based on the sun*](https://www.youtube.com/watch?v=Rg3zI1Oyk3c) by Home Automation Guy on 2022-08-31 (YouTube video πŸ“Ί) +- [*Adaptive Lighting Blew My Mind in Home Assistant - How to set it up*](https://www.youtube.com/watch?v=c1cnccmgl3k) by Smart Home Junkie on 2022-06-26 (YouTube video πŸ“Ί) ## :busts_in_silhouette: Contributors diff --git a/test_dependencies.py b/test_dependencies.py index a4dc0e89..58b4718f 100644 --- a/test_dependencies.py +++ b/test_dependencies.py @@ -25,6 +25,7 @@ required = [ "components.http", "components.stream", "components.conversation", + "components.cloud", ] to_install = [] for r in required: From 2033fcebe9d6edb0c792f0c7c505d21362629599 Mon Sep 17 00:00:00 2001 From: Mario Guggenberger Date: Sun, 21 May 2023 19:36:16 +0200 Subject: [PATCH 3/5] fix: lights unexpectedly turn back on after switch-off (#590) --- custom_components/adaptive_lighting/switch.py | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index f933f068..9ed3e0da 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1111,7 +1111,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): context=self.create_context("interval"), ) - async def _adapt_light( + async def _adapt_light( # noqa: C901 self, light: str, transition: int | None = None, @@ -1200,9 +1200,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): context=context, ) - if not self._separate_turn_on_commands: - await turn_on(service_data) - else: + async def turn_on_split(): # Could be a list of length 1 or 2 service_datas = _split_service_data( service_data, adapt_brightness, adapt_color @@ -1215,6 +1213,18 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): await asyncio.sleep(self._send_split_delay / 1000.0) await turn_on(service_datas[1]) + if not self._separate_turn_on_commands: + await turn_on(service_data) + else: + split_tasks = self.turn_on_off_listener.split_adaptation_tasks + if (previous_task := split_tasks.get(light)) is not None: + previous_task.cancel() + try: + split_tasks[light] = asyncio.ensure_future(turn_on_split()) + await split_tasks[light] + except asyncio.CancelledError: + _LOGGER.debug("Split adaptation of %s cancelled", light) + async def _update_attrs_and_maybe_adapt_lights( self, lights: list[str] | None = None, @@ -1685,6 +1695,8 @@ class TurnOnOffListener: self.last_state_change: dict[str, list[State]] = {} # Track last 'service_data' to 'light.turn_on' resulting from this integration self.last_service_data: dict[str, dict[str, Any]] = {} + # Track ongoing split adaptations to be able to cancel them + self.split_adaptation_tasks: dict[str, asyncio.Task] = {} # Track auto reset of manual_control self.auto_reset_manual_control_timers: dict[str, _AsyncSingleShotTimer] = {} @@ -1801,6 +1813,9 @@ class TurnOnOffListener: self.last_state_change.pop(light, None) self.last_service_data.pop(light, None) + if (task := self.split_adaptation_tasks.get(light)) is not None: + task.cancel() + async def turn_on_off_event_listener(self, event: Event) -> None: """Track 'light.turn_off' and 'light.turn_on' service calls.""" domain = event.data.get(ATTR_DOMAIN) From bf3b709ba62d57f70ff5d04c9416cb35b1bd7eb9 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 21 May 2023 13:35:45 -0700 Subject: [PATCH 4/5] docs: add protyposis as a contributor for code (#597) --- .all-contributorsrc | 9 +++++++++ README.md | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 6c825dad..33b875f2 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -440,6 +440,15 @@ "contributions": [ "code" ] + }, + { + "login": "protyposis", + "name": "Mario Guggenberger", + "avatar_url": "https://avatars.githubusercontent.com/u/189372?v=4", + "profile": "http://protyposis.net", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7, diff --git a/README.md b/README.md index d1895b91..1a0830b0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg?style=for-the-badge)](https://github.com/hacs/integration) ![Version](https://img.shields.io/github/v/release/basnijholt/adaptive-lighting?style=for-the-badge) -[![All Contributors](https://img.shields.io/badge/all_contributors-47-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-48-orange.svg?style=flat-square)](#contributors-) # 🌞 Adaptive Lighting: Enhance Your Home's Atmosphere with Smart, Sun-Synchronized Lighting πŸŒ™ @@ -429,6 +429,7 @@ These graphs were generated using the values calculated by the Adaptive Lighting Hudson Brendon
Hudson Brendon

🌍 Gabriel Visser
Gabriel Visser

πŸ“– Gleb
Gleb

🌍 + Deleted user
Deleted user

🌍 Avi Miller
Avi Miller

πŸ“– πŸ’» Denys Dovhan
Denys Dovhan

🌍 David Stenbeck
David Stenbeck

πŸ“– @@ -457,6 +458,7 @@ These graphs were generated using the values calculated by the Adaptive Lighting Chris
Chris

πŸ’» Raman Gupta
Raman Gupta

πŸ’» igiannakas
igiannakas

πŸ’» + Mario Guggenberger
Mario Guggenberger

πŸ’» From 4683f083f69952af7e9c26f9064305a62eddfe1a Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Mon, 22 May 2023 12:16:40 -0700 Subject: [PATCH 5/5] Update version to 1.12.0 in manifest.json (#596) --- custom_components/adaptive_lighting/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/adaptive_lighting/manifest.json b/custom_components/adaptive_lighting/manifest.json index 2dec4c83..85aa0c08 100644 --- a/custom_components/adaptive_lighting/manifest.json +++ b/custom_components/adaptive_lighting/manifest.json @@ -8,5 +8,5 @@ "iot_class": "calculated", "issue_tracker": "https://github.com/basnijholt/adaptive-lighting/issues", "requirements": ["ulid-transform"], - "version": "1.11.0" + "version": "1.12.0" }