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
This commit is contained in:
Bas Nijholt 2023-07-20 11:53:38 -07:00 committed by GitHub
commit fd5f6bf310
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -8,5 +8,5 @@
"iot_class": "calculated",
"issue_tracker": "https://github.com/basnijholt/adaptive-lighting/issues",
"requirements": ["ulid-transform"],
"version": "1.15.1"
"version": "1.15.2"
}

View file

@ -305,6 +305,10 @@ def _get_switches_with_lights(
return switches
class NoSwitchFoundError(ValueError):
"""No switches found for lights."""
def find_switch_for_lights(
hass: HomeAssistant,
lights: list[str],
@ -318,13 +322,13 @@ def find_switch_for_lights(
if len(on_switches) == 1:
# Of the multiple switches, only one is on
return on_switches[0]
raise ValueError(
raise NoSwitchFoundError(
f"find_switch_for_lights: Light(s) {lights} found in multiple switch configs"
f" ({[s.entity_id for s in switches]}). You must pass a switch under"
f" 'entity_id'."
)
else:
raise ValueError(
raise NoSwitchFoundError(
f"find_switch_for_lights: Light(s) {lights} not found in any switch's"
f" configuration. You must either include the light(s) that is/are"
f" in the integration config, or pass a switch under 'entity_id'."
@ -1840,7 +1844,12 @@ class TurnOnOffListener:
return
entity_id = entity_ids[0]
adaptive_switch = find_switch_for_lights(self.hass, [entity_id])
try:
adaptive_switch = find_switch_for_lights(self.hass, [entity_id])
except NoSwitchFoundError:
# This might be a light that is not managed by this AL instance.
return
if entity_id not in adaptive_switch.lights:
return