mirror of
https://github.com/fmtr/haco.git
synced 2026-10-25 18:40:15 -04:00
Refine some error messages and argument names
This commit is contained in:
parent
bd9304b4ba
commit
74b7d0c841
6 changed files with 28 additions and 10 deletions
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()']):
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue