Skip to content

Commit fc3a74c

Browse files
committed
add function for fetching scenes by name
1 parent 1f9040c commit fc3a74c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/dirigera/hub/hub.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,16 @@ def get_scene_by_id(self, scene_id: str) -> Scene:
343343
data = self.get(f"/scenes/{scene_id}")
344344
return dict_to_scene(data, self)
345345

346+
def get_scene_by_name(self, scene_name: str) -> Scene:
347+
"""
348+
Fetches all scenes and returns the first result that matches scene_name
349+
"""
350+
scenes = self.get_scenes()
351+
scenes = list(filter(lambda x: x.info.name == scene_name, scenes))
352+
if len(scenes) == 0:
353+
raise AssertionError(f"No Scene found with name {scene_name}")
354+
return scenes[0]
355+
346356
def get_water_sensors(self) -> List[WaterSensor]:
347357
"""
348358
Fetches all water sensors registered in the Hub

0 commit comments

Comments
 (0)