diff --git a/haco/configs/demo.py b/haco/configs/demo.py index ebe6e4f..74b85a0 100644 --- a/haco/configs/demo.py +++ b/haco/configs/demo.py @@ -10,7 +10,7 @@ def ha(value) -> Tasmota[str, 'tasmota.cmd("restart 1")']: from haco import Sensor -memory = Sensor('Memory Free', icon='memory', uom=Sensor.UOM.DATA_KILOBYTES, device_class=Sensor.DEVICE_CLASS.DATA_SIZE) +memory = Sensor('Memory Free', icon='memory', uom=Sensor.UOM.DATA_KILOBYTES, uom_type=Sensor.UOM_TYPE.DATA_SIZE) @memory.callback(trigger='Tele#Heap') @@ -26,3 +26,20 @@ restart = Button('Restart Tasmota', icon='restart') @restart.callback() def ha(value) -> Tasmota[str, 'tasmota.cmd("restart 1")']: return value + + +from haco import Select, Tasmota + +LOG_LEVELS = ["None", "Error", "Info", "Debug", "Debug More"] + +weblog = Select('WebLog Level', icon='console', options=LOG_LEVELS) + + +@weblog.callback() +def ha(value) -> Tasmota[str, 'tasmota.cmd("WebLog "+value)']: + return LOG_LEVELS.index(value) + + +@weblog.callback(trigger='WebLog') +def tasmota(value: int): + return LOG_LEVELS[value] diff --git a/haco/configs/proscenic_t21.py b/haco/configs/proscenic_t21.py index 8ad974c..14bab99 100644 --- a/haco/configs/proscenic_t21.py +++ b/haco/configs/proscenic_t21.py @@ -21,8 +21,9 @@ def tasmota(value: int): time_remaining = Sensor( name='Time Remaining', uom=Sensor.UOM.TIME_MINUTES, + uom_type=Sensor.UOM_TYPE.DURATION, icon='timer', - device_class=Sensor.DEVICE_CLASS.DURATION + ) @@ -112,7 +113,7 @@ add_tuya_io(delay_time, int, 2, 6) status = Sensor( name='Status', icon='playlist-play', - device_class=Sensor.DEVICE_CLASS.ENUM + uom_type=Sensor.UOM_TYPE.ENUM ) diff --git a/haco/configs/test.py b/haco/configs/test.py index ea150a9..a1eccc7 100644 --- a/haco/configs/test.py +++ b/haco/configs/test.py @@ -20,6 +20,6 @@ def ha(value) -> Tasmota[str, set_greeting]: return value -@greeter.callback(trigger='Var16#state') -def tasmota(value: str): +@greeter.callback(trigger='WebLog') +def tasmota(value: int): return value diff --git a/haco/control.py b/haco/control.py index d0638bf..c971a82 100644 --- a/haco/control.py +++ b/haco/control.py @@ -54,7 +54,7 @@ class Control: callback_names = self.schema.get_callback_function_names() if function_name not in callback_names: - msg = f'Callback function "{function_name}" name is not valid. Must be one of: {sorted(callback_names)}' + msg = f'Callback function "{function_name}" name is not valid for control "{self.__class__.__name__}". Must be one of: {sorted(callback_names)}' raise ValueError(msg) capability_id, platform_id = function_name.rsplit('_', 1) diff --git a/haco/debugging.py b/haco/debugging.py index 9db48ea..1fc78f4 100644 --- a/haco/debugging.py +++ b/haco/debugging.py @@ -6,7 +6,7 @@ from haco.tasmota import Tasmota def get_memory_sensor(): - memory_sensor = Sensor('Memory Free', uom='kB', device_class='DATA_SIZE', data_type=int) + memory_sensor = Sensor('Memory Free', uom='kB', uom_type='DATA_SIZE', data_type=int) @memory_sensor.callback(trigger.Cron('*/30 * * * * *')) def tasmota(value: Tasmota[Any, 'tasmota.memory()']): diff --git a/haco/sensor.py b/haco/sensor.py index f145b7f..e27aa09 100644 --- a/haco/sensor.py +++ b/haco/sensor.py @@ -8,7 +8,7 @@ from haco.data.uom import Uom class Sensor(Control): NAME = 'sensor' - DEVICE_CLASS = DeviceClassSensor + UOM_TYPE = DeviceClassSensor UOM = Uom @classmethod @@ -23,9 +23,9 @@ class Sensor(Control): ] ) - def __init__(self, name, data_type=None, uom=None, icon=None, device_class=None): + def __init__(self, name, data_type=None, uom=None, icon=None, uom_type=None): self.data_type = data_type - self.device_class = device_class + self.device_class = uom_type self.uom = uom super().__init__(name, icon=icon)