mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Philips Hue Scene Activation: Simplified scene lookup logic, improved error handling (#15175)
* Simplified scene lookup logic, improved error handling * Lint
This commit is contained in:
parent
742144f401
commit
9066ac44fe
@ -124,24 +124,16 @@ class HueBridge(object):
|
||||
(group for group in self.api.groups.values()
|
||||
if group.name == group_name), None)
|
||||
|
||||
# The same scene name can exist in multiple groups.
|
||||
# In this case, activate first scene that contains the
|
||||
# the exact same light IDs as the group
|
||||
scenes = []
|
||||
for scene in self.api.scenes.values():
|
||||
if scene.name == scene_name:
|
||||
scenes.append(scene)
|
||||
if len(scenes) == 1:
|
||||
scene_id = scenes[0].id
|
||||
else:
|
||||
group_lights = sorted(group.lights)
|
||||
for scene in scenes:
|
||||
if group_lights == scene.lights:
|
||||
scene_id = scene.id
|
||||
break
|
||||
# Additional scene logic to handle duplicate scene names across groups
|
||||
scene = next(
|
||||
(scene for scene in self.api.scenes.values()
|
||||
if scene.name == scene_name
|
||||
and group is not None
|
||||
and sorted(scene.lights) == sorted(group.lights)),
|
||||
None)
|
||||
|
||||
# If we can't find it, fetch latest info.
|
||||
if not updated and (group is None or scene_id is None):
|
||||
if not updated and (group is None or scene is None):
|
||||
await self.api.groups.update()
|
||||
await self.api.scenes.update()
|
||||
await self.hue_activate_scene(call, updated=True)
|
||||
@ -151,11 +143,11 @@ class HueBridge(object):
|
||||
LOGGER.warning('Unable to find group %s', group_name)
|
||||
return
|
||||
|
||||
if scene_id is None:
|
||||
if scene is None:
|
||||
LOGGER.warning('Unable to find scene %s', scene_name)
|
||||
return
|
||||
|
||||
await group.set_action(scene=scene_id)
|
||||
await group.set_action(scene=scene.id)
|
||||
|
||||
|
||||
async def get_bridge(hass, host, username=None):
|
||||
|
Loading…
x
Reference in New Issue
Block a user