Skip to content

Commit

Permalink
Added support for air_purifier and a bug fix for env_sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
c503ghosh committed Feb 28, 2024
1 parent 0bbacc0 commit 26b7ae6
Show file tree
Hide file tree
Showing 14 changed files with 677 additions and 27 deletions.
14 changes: 8 additions & 6 deletions custom_components/dirigera_platform/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ async def async_setup_entry(hass: core.HomeAssistant, entry: config_entries.Conf
hass.data[DOMAIN][entry.entry_id] = hass_data

# Setup the entities
hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, "light"))
hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, "switch"))
hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, "binary_sensor"))
hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, "sensor"))
hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, "cover"))
#hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, "light"))
#hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, "switch"))
#hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, "binary_sensor"))
#hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, "sensor"))
#hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, "cover"))
hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, "fan"))

logger.debug("Complete async_setup_entry...")

Expand All @@ -97,7 +98,8 @@ async def async_unload_entry(hass: core.HomeAssistant, entry: config_entries.Con
hass.config_entries.async_forward_entry_unload(entry, "switch"),
hass.config_entries.async_forward_entry_unload(entry, "binary_sensor"),
hass.config_entries.async_forward_entry_unload(entry, "sensor"),
hass.config_entries.async_forward_entry_unload(entry, "cover")
hass.config_entries.async_forward_entry_unload(entry, "cover"),
hass.config_entries.async_forward_entry_unload(entry, "fan")
]
)]
)
Expand Down
8 changes: 4 additions & 4 deletions custom_components/dirigera_platform/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ async def async_setup_entry(
# If mock then start with mocks
if config[CONF_IP_ADDRESS] == "mock":
logger.warning("Setting up mock motion sensors")
mock_motion_sensor1 = ikea_motion_sensor_mock(hub,"mock_motion_sensor1")
mock_motion_sensor2 = ikea_motion_sensor_mock(hub,"mock_motion_sensor2")
mock_motion_sensor1 = ikea_motion_sensor_mock()
mock_motion_sensor2 = ikea_motion_sensor_mock()
motion_sensors = [mock_motion_sensor1,mock_motion_sensor2]

logger.warning("Setting up mock open/close sensors")
mock_open_close_sensor1 = ikea_open_close_mock(hub,"mock_open_close_sensor1")
mock_open_close_sensor2 = ikea_open_close_mock(hub,"mock_open_close_sensor2")
mock_open_close_sensor1 = ikea_open_close_mock()
mock_open_close_sensor2 = ikea_open_close_mock()
open_close_sensors = [mock_open_close_sensor1,mock_open_close_sensor2]

else:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/dirigera_platform/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def set_cover_position(self, **kwargs):
self._json_data.set_target_position(position)

def update(self):
logger.debug("outlet update...")
logger.debug("cover update...")
try:
self._json_data = self._hub.get_blinds_by_id(self._json_data.id)
except Exception as ex:
Expand Down
9 changes: 8 additions & 1 deletion custom_components/dirigera_platform/dirigera_lib_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dirigera.devices.motion_sensor import MotionSensor
from dirigera.devices.open_close_sensor import OpenCloseSensor, dict_to_open_close_sensor
from dirigera.devices.environment_sensor import EnvironmentSensor, dict_to_environment_sensor
from dirigera.devices.air_purifier import AirPurifier, dict_to_air_purifier
from dirigera.hub.abstract_smart_home_hub import AbstractSmartHomeHub
from typing import Any, Dict, List

Expand Down Expand Up @@ -50,4 +51,10 @@ def get_blinds_by_id(self, id_: str) -> OpenCloseSensor:
blind_sensor = self._get_device_data_by_id(id_)
if blind_sensor["deviceType"] != "blinds":
raise ValueError("Device is not a Blind")
return dict_to_environment_sensor(blind_sensor, self)
return dict_to_environment_sensor(blind_sensor, self)

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)
Loading

0 comments on commit 26b7ae6

Please sign in to comment.