Skip to content

Commit fd5f6bf

Browse files
authored
Pass on lights that are not managed by AL, closes #638 (#639)
* Pass on lights that are not managed by AL, closes #638 * Rename exception
1 parent 1b31b26 commit fd5f6bf

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

custom_components/adaptive_lighting/manifest.json

Lines changed: 1 addition & 1 deletion
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.15.1"
11+
"version": "1.15.2"
1212
}

custom_components/adaptive_lighting/switch.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ def _get_switches_with_lights(
305305
return switches
306306

307307

308+
class NoSwitchFoundError(ValueError):
309+
"""No switches found for lights."""
310+
311+
308312
def find_switch_for_lights(
309313
hass: HomeAssistant,
310314
lights: list[str],
@@ -318,13 +322,13 @@ def find_switch_for_lights(
318322
if len(on_switches) == 1:
319323
# Of the multiple switches, only one is on
320324
return on_switches[0]
321-
raise ValueError(
325+
raise NoSwitchFoundError(
322326
f"find_switch_for_lights: Light(s) {lights} found in multiple switch configs"
323327
f" ({[s.entity_id for s in switches]}). You must pass a switch under"
324328
f" 'entity_id'."
325329
)
326330
else:
327-
raise ValueError(
331+
raise NoSwitchFoundError(
328332
f"find_switch_for_lights: Light(s) {lights} not found in any switch's"
329333
f" configuration. You must either include the light(s) that is/are"
330334
f" in the integration config, or pass a switch under 'entity_id'."
@@ -1840,7 +1844,12 @@ async def _service_interceptor_turn_on_handler(
18401844
return
18411845

18421846
entity_id = entity_ids[0]
1843-
adaptive_switch = find_switch_for_lights(self.hass, [entity_id])
1847+
try:
1848+
adaptive_switch = find_switch_for_lights(self.hass, [entity_id])
1849+
except NoSwitchFoundError:
1850+
# This might be a light that is not managed by this AL instance.
1851+
return
1852+
18441853
if entity_id not in adaptive_switch.lights:
18451854
return
18461855

0 commit comments

Comments
 (0)