Skip to content

Commit 01610a3

Browse files
authored
Merge branch 'main' into new-service-calls
2 parents 5f08706 + 4683f08 commit 01610a3

File tree

7 files changed

+67
-33
lines changed

7 files changed

+67
-33
lines changed

.all-contributorsrc

+9
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,15 @@
440440
"contributions": [
441441
"code"
442442
]
443+
},
444+
{
445+
"login": "protyposis",
446+
"name": "Mario Guggenberger",
447+
"avatar_url": "https://avatars.githubusercontent.com/u/189372?v=4",
448+
"profile": "http://protyposis.net",
449+
"contributions": [
450+
"code"
451+
]
443452
}
444453
],
445454
"contributorsPerLine": 7,

.github/workflows/pytest.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
python-version: ["3.10"]
17-
core-version: ["2023.2.5", "2023.3.6", "2023.4.6", "dev"]
17+
core-version: ["2023.2.5", "2023.3.6", "2023.4.6", "2023.5.2", "dev"]
1818
steps:
1919
- name: Check out code from GitHub
2020
uses: actions/checkout@v3
@@ -54,6 +54,7 @@ jobs:
5454
run: |
5555
cd core
5656
python3 -X dev -m pytest \
57+
-vvv \
5758
-qq \
5859
--timeout=9 \
5960
--durations=10 \

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
hooks:
1717
- id: black
1818
- repo: https://github.com/asottile/pyupgrade
19-
rev: v3.3.1
19+
rev: v3.3.2
2020
hooks:
2121
- id: pyupgrade
2222
args: ["--py39-plus"]

README.md

+34-26
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg?style=for-the-badge)](https://github.com/hacs/integration)
22
![Version](https://img.shields.io/github/v/release/basnijholt/adaptive-lighting?style=for-the-badge)
33
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
4-
[![All Contributors](https://img.shields.io/badge/all_contributors-47-orange.svg?style=flat-square)](#contributors-)
4+
[![All Contributors](https://img.shields.io/badge/all_contributors-48-orange.svg?style=flat-square)](#contributors-)
55
<!-- ALL-CONTRIBUTORS-BADGE:END -->
66

77
# 🌞 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
4141
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
4242
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
4343

44-
- [:gear: Configuration](#gear-configuration)
45-
- [:memo: Options](#memo-options)
46-
- [:hammer_and_wrench: Services](#hammer_and_wrench-services)
47-
- [`adaptive_lighting.apply`](#adaptive_lightingapply)
48-
- [`adaptive_lighting.set_manual_control`](#adaptive_lightingset_manual_control)
49-
- [`adaptive_lighting.change_switch_settings`](#adaptive_lightingchange_switch_settings)
50-
- [:robot: Automation examples](#robot-automation-examples)
44+
- [:gear: Configuration](#gear-configuration)
45+
- [:memo: Options](#memo-options)
46+
- [:hammer_and_wrench: Services](#hammer_and_wrench-services)
47+
- [`adaptive_lighting.apply`](#adaptive_lightingapply)
48+
- [`adaptive_lighting.set_manual_control`](#adaptive_lightingset_manual_control)
49+
- [`adaptive_lighting.change_switch_settings`](#adaptive_lightingchange_switch_settings)
50+
- [:robot: Automation examples](#robot-automation-examples)
5151
- [Additional Information](#additional-information)
5252
- [:sos: Troubleshooting](#sos-troubleshooting)
5353
- [:exclamation: Common Problems & Solutions](#exclamation-common-problems--solutions)
5454
- [:bulb: Lights Not Responding or Turning On by Themselves](#bulb-lights-not-responding-or-turning-on-by-themselves)
55-
- [:signal_strength: WiFi Networks](#signal_strength-wifi-networks)
56-
- [:spider_web: Zigbee, Z-Wave, and Other Mesh Networks](#spider_web-zigbee-z-wave-and-other-mesh-networks)
55+
- [:signal_strength: WiFi Networks](#signal_strength-wifi-networks)
56+
- [:spider_web: Zigbee, Z-Wave, and Other Mesh Networks](#spider_web-zigbee-z-wave-and-other-mesh-networks)
5757
- [:rainbow: Light Colors Not Matching](#rainbow-light-colors-not-matching)
5858
- [:bulb: Bulb-Specific Issues](#bulb-bulb-specific-issues)
59-
- [:bar_chart: Graphs!](#bar_chart-graphs)
60-
- [:sunny: Sun Position](#sunny-sun-position)
61-
- [:thermometer: Color Temperature](#thermometer-color-temperature)
62-
- [:high_brightness: Brightness](#high_brightness-brightness)
63-
- [While using `transition_until_sleep: true`](#while-using-transition_until_sleep-true)
64-
- [:busts_in_silhouette: Contributors](#busts_in_silhouette-contributors)
59+
- [:bar_chart: Graphs!](#bar_chart-graphs)
60+
- [:sunny: Sun Position](#sunny-sun-position)
61+
- [:thermometer: Color Temperature](#thermometer-color-temperature)
62+
- [:high_brightness: Brightness](#high_brightness-brightness)
63+
- [While using `transition_until_sleep: true`](#while-using-transition_until_sleep-true)
64+
- [:eyes: See also](#eyes-see-also)
65+
- [:busts_in_silhouette: Contributors](#busts_in_silhouette-contributors)
6566

6667
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
6768

@@ -310,13 +311,13 @@ iphone_carly_wakeup:
310311

311312
</details>
312313

313-
# Additional Information
314+
## Additional Information
314315

315316
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/).
316317

317318
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.
318319

319-
# :sos: Troubleshooting
320+
## :sos: Troubleshooting
320321

321322
Encountering issues? Enable debug logging in your `configuration.yaml`:
322323

@@ -329,9 +330,9 @@ logger:
329330

330331
After the issue occurs, create a new issue report with the log (`/config/home-assistant.log`).
331332

332-
## :exclamation: Common Problems & Solutions
333+
### :exclamation: Common Problems & Solutions
333334

334-
### :bulb: Lights Not Responding or Turning On by Themselves
335+
#### :bulb: Lights Not Responding or Turning On by Themselves
335336

336337
Adaptive Lighting sends more commands to lights than a typical human user would. If your light control network is unhealthy, you may experience:
337338

@@ -353,7 +354,7 @@ For most Zigbee networks, **using groups is essential for optimal performance**.
353354

354355
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.
355356

356-
### :rainbow: Light Colors Not Matching
357+
#### :rainbow: Light Colors Not Matching
357358

358359
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.
359360

@@ -362,7 +363,7 @@ To resolve this:
362363
1. Include only bulbs of the same make and model in a single Adaptive Lighting configuration.
363364
2. Rearrange bulbs so that different color temperatures are not visible simultaneously.
364365

365-
### :bulb: Bulb-Specific Issues
366+
#### :bulb: Bulb-Specific Issues
366367

367368
Certain bulbs may have issues with long light transition commands:
368369

@@ -372,18 +373,23 @@ Certain bulbs may have issues with long light transition commands:
372373
## :bar_chart: Graphs!
373374
These graphs were generated using the values calculated by the Adaptive Lighting sensor/switch(es).
374375

375-
#### :sunny: Sun Position
376+
### :sunny: Sun Position
376377
![cl_percent|690x131](https://community-home-assistant-assets.s3.dualstack.us-west-2.amazonaws.com/original/3X/6/5/657ff98beb65a94598edeb4bdfd939095db1a22c.PNG)
377378

378-
#### :thermometer: Color Temperature
379+
### :thermometer: Color Temperature
379380
![cl_color_temp|690x129](https://community-home-assistant-assets.s3.dualstack.us-west-2.amazonaws.com/original/3X/5/9/59e84263cbecd8e428cb08777a0413672c48dfcd.PNG)
380381

381-
#### :high_brightness: Brightness
382+
### :high_brightness: Brightness
382383
![cl_brightness|690x130](https://community-home-assistant-assets.s3.dualstack.us-west-2.amazonaws.com/original/3X/5/8/58ebd994b62a8b1abfb3497a5288d923ff4e2330.PNG)
383384

384-
#### While using `transition_until_sleep: true`
385+
### While using `transition_until_sleep: true`
385386
![image](https://user-images.githubusercontent.com/2219836/228949675-f9699624-8abc-466c-bb04-250ce0f495b8.png)
386387

388+
## :eyes: See also
389+
390+
- [*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 📜)
391+
- [*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 📺)
392+
- [*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 📺)
387393

388394
## :busts_in_silhouette: Contributors
389395

@@ -423,6 +429,7 @@ These graphs were generated using the values calculated by the Adaptive Lighting
423429
<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>
424430
<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>
425431
<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>
432+
<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>
426433
<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>
427434
<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>
428435
<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
451458
<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>
452459
<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>
453460
<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>
461+
<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>
454462
</tr>
455463
</tbody>
456464
<tfoot>

custom_components/adaptive_lighting/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
"iot_class": "calculated",
99
"issue_tracker": "https://github.com/basnijholt/adaptive-lighting/issues",
1010
"requirements": ["ulid-transform"],
11-
"version": "1.11.0"
11+
"version": "1.12.0"
1212
}

custom_components/adaptive_lighting/switch.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ async def _async_update_at_interval(self, now=None) -> None:
12111211
context=self.create_context("interval"),
12121212
)
12131213

1214-
async def _adapt_light(
1214+
async def _adapt_light( # noqa: C901
12151215
self,
12161216
light: str,
12171217
transition: int | None = None,
@@ -1300,9 +1300,7 @@ async def turn_on(service_data):
13001300
context=context,
13011301
)
13021302

1303-
if not self._separate_turn_on_commands:
1304-
await turn_on(service_data)
1305-
else:
1303+
async def turn_on_split():
13061304
# Could be a list of length 1 or 2
13071305
service_datas = _split_service_data(
13081306
service_data, adapt_brightness, adapt_color
@@ -1315,6 +1313,18 @@ async def turn_on(service_data):
13151313
await asyncio.sleep(self._send_split_delay / 1000.0)
13161314
await turn_on(service_datas[1])
13171315

1316+
if not self._separate_turn_on_commands:
1317+
await turn_on(service_data)
1318+
else:
1319+
split_tasks = self.turn_on_off_listener.split_adaptation_tasks
1320+
if (previous_task := split_tasks.get(light)) is not None:
1321+
previous_task.cancel()
1322+
try:
1323+
split_tasks[light] = asyncio.ensure_future(turn_on_split())
1324+
await split_tasks[light]
1325+
except asyncio.CancelledError:
1326+
_LOGGER.debug("Split adaptation of %s cancelled", light)
1327+
13181328
async def _update_attrs_and_maybe_adapt_lights(
13191329
self,
13201330
lights: list[str] | None = None,
@@ -1785,6 +1795,8 @@ def __init__(self, hass: HomeAssistant):
17851795
self.last_state_change: dict[str, list[State]] = {}
17861796
# Track last 'service_data' to 'light.turn_on' resulting from this integration
17871797
self.last_service_data: dict[str, dict[str, Any]] = {}
1798+
# Track ongoing split adaptations to be able to cancel them
1799+
self.split_adaptation_tasks: dict[str, asyncio.Task] = {}
17881800

17891801
# Track auto reset of manual_control
17901802
self.auto_reset_manual_control_timers: dict[str, _AsyncSingleShotTimer] = {}
@@ -1901,6 +1913,9 @@ def reset(self, *lights, reset_manual_control=True) -> None:
19011913
self.last_state_change.pop(light, None)
19021914
self.last_service_data.pop(light, None)
19031915

1916+
if (task := self.split_adaptation_tasks.get(light)) is not None:
1917+
task.cancel()
1918+
19041919
async def turn_on_off_event_listener(self, event: Event) -> None:
19051920
"""Track 'light.turn_off' and 'light.turn_on' service calls."""
19061921
domain = event.data.get(ATTR_DOMAIN)

test_dependencies.py

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"components.http",
2626
"components.stream",
2727
"components.conversation",
28+
"components.cloud",
2829
]
2930
to_install = []
3031
for r in required:

0 commit comments

Comments
 (0)