@@ -305,6 +305,10 @@ def _get_switches_with_lights(
305
305
return switches
306
306
307
307
308
+ class NoSwitchFoundError (ValueError ):
309
+ """No switches found for lights."""
310
+
311
+
308
312
def find_switch_for_lights (
309
313
hass : HomeAssistant ,
310
314
lights : list [str ],
@@ -318,13 +322,13 @@ def find_switch_for_lights(
318
322
if len (on_switches ) == 1 :
319
323
# Of the multiple switches, only one is on
320
324
return on_switches [0 ]
321
- raise ValueError (
325
+ raise NoSwitchFoundError (
322
326
f"find_switch_for_lights: Light(s) { lights } found in multiple switch configs"
323
327
f" ({ [s .entity_id for s in switches ]} ). You must pass a switch under"
324
328
f" 'entity_id'."
325
329
)
326
330
else :
327
- raise ValueError (
331
+ raise NoSwitchFoundError (
328
332
f"find_switch_for_lights: Light(s) { lights } not found in any switch's"
329
333
f" configuration. You must either include the light(s) that is/are"
330
334
f" in the integration config, or pass a switch under 'entity_id'."
@@ -1840,7 +1844,12 @@ async def _service_interceptor_turn_on_handler(
1840
1844
return
1841
1845
1842
1846
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
+
1844
1853
if entity_id not in adaptive_switch .lights :
1845
1854
return
1846
1855
0 commit comments