Skip to content

Commit

Permalink
Pass on lights that are not managed by AL, closes #638 (#639)
Browse files Browse the repository at this point in the history
* Pass on lights that are not managed by AL, closes #638

* Rename exception
  • Loading branch information
basnijholt authored Jul 20, 2023
1 parent 1b31b26 commit fd5f6bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion custom_components/adaptive_lighting/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
15 changes: 12 additions & 3 deletions custom_components/adaptive_lighting/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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'."
Expand Down Expand Up @@ -1840,7 +1844,12 @@ async def _service_interceptor_turn_on_handler(
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

Expand Down

0 comments on commit fd5f6bf

Please sign in to comment.