From c1bdebacfe0bee223df113989954c585e7e6b6c0 Mon Sep 17 00:00:00 2001 From: fiva Date: Sun, 6 Dec 2020 21:50:10 +0100 Subject: [PATCH] add switched-fans --- custom_components/nhc2/__init__.py | 2 +- custom_components/nhc2/fan.py | 72 ++++++++++++++++++++++++++++ custom_components/nhc2/manifest.json | 2 +- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/custom_components/nhc2/__init__.py b/custom_components/nhc2/__init__.py index a3f8debb..7b43ea99 100644 --- a/custom_components/nhc2/__init__.py +++ b/custom_components/nhc2/__init__.py @@ -12,7 +12,7 @@ from .const import DOMAIN, KEY_GATEWAY, CONF_SWITCHES_AS_LIGHTS from .helpers import extract_versions -REQUIREMENTS = ['nhc2-coco==1.3.2'] +REQUIREMENTS = ['nhc2-coco==1.3.3'] _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/nhc2/fan.py b/custom_components/nhc2/fan.py index a33faffa..47f3b354 100644 --- a/custom_components/nhc2/fan.py +++ b/custom_components/nhc2/fan.py @@ -7,6 +7,7 @@ from nhc2_coco.coco_device_class import CoCoDeviceClass from nhc2_coco.coco_fan import CoCoFan from nhc2_coco.coco_fan_speed import CoCoFanSpeed +from nhc2_coco.coco_switched_fan import CoCoSwitchedFan from .const import DOMAIN, KEY_GATEWAY, BRAND, FAN from .helpers import nhc2_entity_processor @@ -31,6 +32,13 @@ async def async_setup_entry(hass, config_entry, async_add_entities): KEY_ENTITY, lambda x: NHC2HassFan(x)) ) + gateway.get_devices(CoCoDeviceClass.SWITCHED_FANS, + nhc2_entity_processor(hass, + config_entry, + async_add_entities, + KEY_ENTITY, + lambda x: NHC2HassSwitchedFan(x)) + ) class NHC2HassFan(FanEntity): @@ -137,3 +145,67 @@ def _convert_fan_speed_hass2nhc2(self, fan_speed: str) -> CoCoFanSpeed: return CoCoFanSpeed.MEDIUM if fan_speed == SPEED_BOOST: return CoCoFanSpeed.BOOST + + +class NHC2HassSwitchedFan(FanEntity): + """Representation of an NHC2 Fan.""" + + def __init__(self, nhc2switched_fan: CoCoSwitchedFan): + """Initialize a light.""" + self._nhc2switched_fan = nhc2switched_fan + self._is_on = nhc2switched_fan.is_on + nhc2switched_fan.on_change = self._on_change + + def set_speed(self, speed: str) -> None: + pass + + def set_direction(self, direction: str) -> None: + pass + + def turn_on(self, speed: str = None, **kwargs) -> None: + self._nhc2switched_fan.turn_on() + + def turn_off(self, **kwargs: Any) -> None: + self._nhc2switched_fan.turn_off() + + def _on_change(self): + self._is_on = self._nhc2switched_fan.is_on + self.schedule_update_ha_state() + + @property + def unique_id(self): + """Return the lights UUID.""" + return self._nhc2switched_fan.uuid + + @property + def uuid(self): + """Return the lights UUID.""" + return self._nhc2switched_fan.uuid + + @property + def should_poll(self): + """Return false, since the light will push state.""" + return False + + @property + def name(self): + """Return the lights name.""" + return self._nhc2switched_fan.name + + @property + def available(self): + """Return true if the light is online.""" + return self._nhc2switched_fan.online + + @property + def device_info(self): + """Return the device info.""" + return { + 'identifiers': { + (DOMAIN, self.unique_id) + }, + 'name': self.name, + 'manufacturer': BRAND, + 'model': FAN, + 'via_hub': (DOMAIN, self._nhc2switched_fan.profile_creation_id), + } diff --git a/custom_components/nhc2/manifest.json b/custom_components/nhc2/manifest.json index 3ebbe2cd..3d3f2485 100644 --- a/custom_components/nhc2/manifest.json +++ b/custom_components/nhc2/manifest.json @@ -1,7 +1,7 @@ { "domain": "nhc2", "name": "Niko Home Control II", - "requirements": ["nhc2-coco==1.3.2"], + "requirements": ["nhc2-coco==1.3.3"], "config_flow": true, "issue_tracker": "https://github.com/filipvh/hass-nhc2/issues", "documentation": "https://github.com/filipvh/hass-nhc2/blob/master/README.md",