Skip to content

Commit

Permalink
Update hub.py
Browse files Browse the repository at this point in the history
Updated by_id methods for other devices
  • Loading branch information
sanjoyg authored Apr 3, 2024
1 parent e08f1d6 commit 30fddfd
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/dirigera/hub/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ def get_air_purifiers(self) -> List[AirPurifier]:
airpurifiers = list(filter(lambda x: x["type"] == "airPurifier", devices))
return [dict_to_air_purifier(air_p, self) for air_p in airpurifiers]

def get_air_purifier_by_id(self, id_: str) -> AirPurifier:
air_purifier_device = self._get_device_data_by_id(id_)
if air_purifier_device["deviceType"] != "airPurifier":
raise ValueError("Device is not an Air Purifier")
return dict_to_air_purifier(air_purifier_device, self)

def get_lights(self) -> List[Light]:
"""
Fetches all lights registered in the Hub
Expand Down Expand Up @@ -194,6 +200,12 @@ def get_environment_sensors(self) -> List[EnvironmentSensor]:
)
return [dict_to_environment_sensor(sensor, self) for sensor in sensors]

def get_environment_sensor_by_id(self, id_: str) -> EnvironmentSensor:
environment_sensor = self._get_device_data_by_id(id_)
if environment_sensor["deviceType"] != "environmentSensor":
raise ValueError("Device is not an EnvironmentSensor")
return dict_to_environment_sensor(environment_sensor, self)

def get_motion_sensors(self) -> List[MotionSensor]:
"""
Fetches all motion sensors registered in the Hub
Expand All @@ -202,6 +214,12 @@ def get_motion_sensors(self) -> List[MotionSensor]:
sensors = list(filter(lambda x: x["deviceType"] == "motionSensor", devices))
return [dict_to_motion_sensor(sensor, self) for sensor in sensors]

def get_motion_sensor_by_id(self) -> MotionSensor:
motion_sensor = self._get_device_data_by_id(id_)
if motion_sensor["deviceType"] != "motionSensor":
raise ValueError("Device is not an MotionSensor")
return dict_to_motion_sensorx(motion_sensor, self)

def get_open_close_sensors(self) -> List[OpenCloseSensor]:
"""
Fetches all open/close sensors registered in the Hub
Expand All @@ -210,6 +228,12 @@ def get_open_close_sensors(self) -> List[OpenCloseSensor]:
sensors = list(filter(lambda x: x["deviceType"] == "openCloseSensor", devices))
return [dict_to_open_close_sensor(sensor, self) for sensor in sensors]

def get_open_close_by_id(self, id_: str) -> OpenCloseSensor:
open_close_sensor = self._get_device_data_by_id(id_)
if open_close_sensor["deviceType"] != "openCloseSensor":
raise ValueError("Device is not an OpenCloseSensor")
return dict_to_open_close_sensor(open_close_sensor, self)

def get_blinds(self) -> List[Blind]:
"""
Fetches all blinds registered in the Hub
Expand All @@ -227,7 +251,13 @@ def get_blind_by_name(self, blind_name: str) -> Blind:
if len(blinds) == 0:
raise AssertionError(f"No blind found with name {blind_name}")
return blinds[0]


def get_blinds_by_id(self, id_: str) -> Blind:
blind_sensor = self._get_device_data_by_id(id_)
if blind_sensor["deviceType"] != "blinds":
raise ValueError("Device is not a Blind")
return dict_to_blind(blind_sensor, self)

def get_controllers(self) -> List[Controller]:
"""
Fetches all controllers registered in the Hub
Expand Down

0 comments on commit 30fddfd

Please sign in to comment.