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()
|
(group for group in self.api.groups.values()
|
||||||
if group.name == group_name), None)
|
if group.name == group_name), None)
|
||||||
|
|
||||||
# The same scene name can exist in multiple groups.
|
# Additional scene logic to handle duplicate scene names across groups
|
||||||
# In this case, activate first scene that contains the
|
scene = next(
|
||||||
# the exact same light IDs as the group
|
(scene for scene in self.api.scenes.values()
|
||||||
scenes = []
|
if scene.name == scene_name
|
||||||
for scene in self.api.scenes.values():
|
and group is not None
|
||||||
if scene.name == scene_name:
|
and sorted(scene.lights) == sorted(group.lights)),
|
||||||
scenes.append(scene)
|
None)
|
||||||
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
|
|
||||||
|
|
||||||
# If we can't find it, fetch latest info.
|
# 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.groups.update()
|
||||||
await self.api.scenes.update()
|
await self.api.scenes.update()
|
||||||
await self.hue_activate_scene(call, updated=True)
|
await self.hue_activate_scene(call, updated=True)
|
||||||
@ -151,11 +143,11 @@ class HueBridge(object):
|
|||||||
LOGGER.warning('Unable to find group %s', group_name)
|
LOGGER.warning('Unable to find group %s', group_name)
|
||||||
return
|
return
|
||||||
|
|
||||||
if scene_id is None:
|
if scene is None:
|
||||||
LOGGER.warning('Unable to find scene %s', scene_name)
|
LOGGER.warning('Unable to find scene %s', scene_name)
|
||||||
return
|
return
|
||||||
|
|
||||||
await group.set_action(scene=scene_id)
|
await group.set_action(scene=scene.id)
|
||||||
|
|
||||||
|
|
||||||
async def get_bridge(hass, host, username=None):
|
async def get_bridge(hass, host, username=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user