Implement Fan object

This commit is contained in:
Edward Brown 2023-09-08 13:22:09 +01:00
parent 257b68d8d5
commit 613006bf91
2 changed files with 58 additions and 0 deletions

View file

@ -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"
]

56
haco/fan.py Normal file
View file

@ -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