Skip to content

Commit

Permalink
Merge pull request #62 from sanjoyg/patch-3
Browse files Browse the repository at this point in the history
Update hub.py
  • Loading branch information
Leggin authored Apr 4, 2024
2 parents 18a2a9e + 3ce4de3 commit 5cb95db
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/dirigera/hub/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
from ..devices.open_close_sensor import OpenCloseSensor, dict_to_open_close_sensor
from ..devices.scene import Scene, dict_to_scene


urllib3.disable_warnings(category=InsecureRequestWarning)


class Hub(AbstractSmartHomeHub):
def __init__(
self,
Expand Down Expand Up @@ -128,6 +126,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 +198,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 +212,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, id_: str) -> 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_sensor(motion_sensor, self)

def get_open_close_sensors(self) -> List[OpenCloseSensor]:
"""
Fetches all open/close sensors registered in the Hub
Expand All @@ -210,6 +226,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 @@ -228,6 +250,12 @@ def get_blind_by_name(self, blind_name: str) -> Blind:
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 5cb95db

Please sign in to comment.