From 613006bf91ebf924bb3ec6388178fd507ab5c0d1 Mon Sep 17 00:00:00 2001 From: Edward Brown Date: Fri, 8 Sep 2023 13:22:09 +0100 Subject: [PATCH] Implement Fan object --- haco/__init__.py | 2 ++ haco/fan.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 haco/fan.py diff --git a/haco/__init__.py b/haco/__init__.py index 615f096..8787f1e 100644 --- a/haco/__init__.py +++ b/haco/__init__.py @@ -2,6 +2,7 @@ from haco import tuya from .button import Button from .callback import Response from .climate import Climate +from .fan import Fan from .number import Number from .pulldown import Select from .sensor import Sensor @@ -21,6 +22,7 @@ __all__ = [ "Password", "Update", "Climate", + "Fan", "Response", "tuya" ] diff --git a/haco/fan.py b/haco/fan.py new file mode 100644 index 0000000..11ecc22 --- /dev/null +++ b/haco/fan.py @@ -0,0 +1,56 @@ +from haco import constants +from haco.control import Control +from haco.schema import Schema, Capability, AnnounceTopic, Tasmota, ControlType, HomeAssistant +from haco.tools import get_range_pair, invert_bool + + +class Fan(Control): + NAME = 'fan' + + @classmethod + def get_schema(cls): + schema = Schema( + capabilities=[ + Capability( + ha=HomeAssistant(announce_data=AnnounceTopic(key='{io_ha}_topic')), + tasmota=Tasmota(announce_data=AnnounceTopic(key='{io_ha}_topic')) + ), + Capability( + name='preset_mode', + type=str + ), + Capability( + name='percentage', + type=int + ), + Capability( + name='oscillation', + type=ControlType + ) + + ] + ) + return schema + + def __init__(self, name=None, preset_modes=None, icon=None, speed_range=None): + self.temperature_unit = speed_range + self.speed_min, self.speed_max = get_range_pair(speed_range) + self.preset_modes = preset_modes + + super().__init__(name, icon=icon) + + def get_config_ha_ex(self): + data = { + 'speed_range_min': self.speed_min, + 'speed_range_max': self.speed_max, + 'preset_modes': self.preset_modes, + 'payload_oscillation_on': constants.ON, + 'payload_oscillation_off': constants.OFF, + + } + + return data + + @property + def control_type(self): + return invert_bool