Merge branch 'main' into new-service-calls

This commit is contained in:
Benjamin Auquite 2023-05-26 00:45:57 -05:00 committed by GitHub
commit 01610a32a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 67 additions and 33 deletions

View file

@ -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,

View file

@ -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 \

View file

@ -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"]

View file

@ -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-BADGE:START - Do not remove or modify this section -->
[![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-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
# 🌞 Adaptive Lighting: Enhance Your Home's Atmosphere with Smart, Sun-Synchronized Lighting 🌙
@ -41,27 +41,28 @@ The `adaptive_lighting.manual_control` event is fired when a light is marked as
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
- [: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)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@ -310,13 +311,13 @@ iphone_carly_wakeup:
</details>
# 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
@ -423,6 +429,7 @@ These graphs were generated using the values calculated by the Adaptive Lighting
<td align="center" valign="top" width="14.28%"><a href="http://medium.com/@hudsonbrendon"><img src="https://avatars.githubusercontent.com/u/5201888?v=4?s=100" width="100px;" alt="Hudson Brendon"/><br /><sub><b>Hudson Brendon</b></sub></a><br /><a href="#translation-hudsonbrendon" title="Translation">🌍</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/gvssr"><img src="https://avatars.githubusercontent.com/u/61377476?v=4?s=100" width="100px;" alt="Gabriel Visser"/><br /><sub><b>Gabriel Visser</b></sub></a><br /><a href="https://github.com/basnijholt/adaptive-lighting/commits?author=gvssr" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/glebsterx"><img src="https://avatars.githubusercontent.com/u/8779304?v=4?s=100" width="100px;" alt="Gleb"/><br /><sub><b>Gleb</b></sub></a><br /><a href="#translation-glebsterx" title="Translation">🌍</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ghost"><img src="https://avatars.githubusercontent.com/u/10137?v=4?s=100" width="100px;" alt="Deleted user"/><br /><sub><b>Deleted user</b></sub></a><br /><a href="#translation-ghost" title="Translation">🌍</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://omg.dje.li/"><img src="https://avatars.githubusercontent.com/u/103232?v=4?s=100" width="100px;" alt="Avi Miller"/><br /><sub><b>Avi Miller</b></sub></a><br /><a href="https://github.com/basnijholt/adaptive-lighting/commits?author=Djelibeybi" title="Documentation">📖</a> <a href="https://github.com/basnijholt/adaptive-lighting/commits?author=Djelibeybi" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/denysdovhan"><img src="https://avatars.githubusercontent.com/u/3459374?v=4?s=100" width="100px;" alt="Denys Dovhan"/><br /><sub><b>Denys Dovhan</b></sub></a><br /><a href="#translation-denysdovhan" title="Translation">🌍</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://davidstenbeck.com/"><img src="https://avatars.githubusercontent.com/u/3330933?v=4?s=100" width="100px;" alt="David Stenbeck"/><br /><sub><b>David Stenbeck</b></sub></a><br /><a href="https://github.com/basnijholt/adaptive-lighting/commits?author=Davst" title="Documentation">📖</a></td>
@ -451,6 +458,7 @@ These graphs were generated using the values calculated by the Adaptive Lighting
<td align="center" valign="top" width="14.28%"><a href="https://github.com/firstof9"><img src="https://avatars.githubusercontent.com/u/1105672?v=4?s=100" width="100px;" alt="Chris"/><br /><sub><b>Chris</b></sub></a><br /><a href="https://github.com/basnijholt/adaptive-lighting/commits?author=firstof9" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/raman325"><img src="https://avatars.githubusercontent.com/u/7243222?v=4?s=100" width="100px;" alt="Raman Gupta"/><br /><sub><b>Raman Gupta</b></sub></a><br /><a href="https://github.com/basnijholt/adaptive-lighting/commits?author=raman325" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/igiannakas"><img src="https://avatars.githubusercontent.com/u/59056762?v=4?s=100" width="100px;" alt="igiannakas"/><br /><sub><b>igiannakas</b></sub></a><br /><a href="https://github.com/basnijholt/adaptive-lighting/commits?author=igiannakas" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://protyposis.net"><img src="https://avatars.githubusercontent.com/u/189372?v=4?s=100" width="100px;" alt="Mario Guggenberger"/><br /><sub><b>Mario Guggenberger</b></sub></a><br /><a href="https://github.com/basnijholt/adaptive-lighting/commits?author=protyposis" title="Code">💻</a></td>
</tr>
</tbody>
<tfoot>

View file

@ -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"
}

View file

@ -1211,7 +1211,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,
@ -1300,9 +1300,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
@ -1315,6 +1313,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,
@ -1785,6 +1795,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] = {}
@ -1901,6 +1913,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)

View file

@ -25,6 +25,7 @@ required = [
"components.http",
"components.stream",
"components.conversation",
"components.cloud",
]
to_install = []
for r in required: