mirror of
https://github.com/fmtr/haco.git
synced 2026-10-26 19:01:51 -04:00
Add Tasmota updater prefab, send callback IDs to Tasmota
This commit is contained in:
parent
08097f816c
commit
988a3f9f4f
7 changed files with 78 additions and 11 deletions
|
|
@ -304,6 +304,7 @@ class Daemon
|
|||
var callback_type=CALLBACK_MAP[data.find('type', classname(tools.callbacks.Rule))]
|
||||
var topic=data['topic']
|
||||
var trigger=data['trigger']
|
||||
var id=data['id']
|
||||
|
||||
var function
|
||||
|
||||
|
|
@ -315,7 +316,11 @@ class Daemon
|
|||
function=/value,data->{'value':value,'data':data}
|
||||
end
|
||||
|
||||
return callback_type(trigger,/value,data->tasmota.set_timer(0,/->self.publish_output(function,value,data,topic)))
|
||||
return callback_type(
|
||||
trigger,
|
||||
/value,data->tasmota.set_timer(0,/->self.publish_output(function,value,data,topic)),
|
||||
id
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
from haco import tuya
|
||||
from .button import Button
|
||||
from .callback import Response
|
||||
from .climate import Climate
|
||||
from .number import Number
|
||||
from .pulldown import Select
|
||||
from .sensor import Sensor
|
||||
from .switch import Switch
|
||||
from .tasmota import Tasmota
|
||||
from .text import Text, Password
|
||||
from .update import Update
|
||||
|
||||
__all__ = [
|
||||
|
|
@ -15,7 +17,10 @@ __all__ = [
|
|||
"Tasmota",
|
||||
"Number",
|
||||
"Switch",
|
||||
"Text",
|
||||
"Password",
|
||||
"Update",
|
||||
"Climate",
|
||||
"Response",
|
||||
"tuya"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
from haco.climate import Climate
|
||||
from haco.number import Number
|
||||
from haco.pulldown import Select
|
||||
from haco.sensor import Sensor
|
||||
from haco.tasmota import Tasmota
|
||||
from haco.text import Text, Password
|
||||
from haco import Number, Tasmota, Select, Sensor, Text, Password, Climate
|
||||
|
||||
|
||||
number = Number(
|
||||
'Dev Number Test Control',
|
||||
|
|
@ -169,3 +165,8 @@ def ha(value: str) -> Tasmota[str, 'tasmota.cmd("var14 "+str(value))']:
|
|||
@password.callback('var14#state')
|
||||
def tasmota(value: str):
|
||||
return value
|
||||
|
||||
|
||||
from haco.debugging import get_tasmota_updater
|
||||
|
||||
update = get_tasmota_updater()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import math
|
||||
|
||||
from haco import Tasmota, Number, Sensor, Select, Switch, tuya
|
||||
from haco.debugging import get_tasmota_updater
|
||||
from haco.tools import add_tuya_io
|
||||
|
||||
OPTIONS = ['Default', 'Fries', 'Shrimp', 'Pizza', 'Chicken', 'Fish', 'Steak', 'Cake', 'Bacon', 'Preheat', 'Custom']
|
||||
|
|
@ -130,4 +131,6 @@ keep_warm_time = Number(
|
|||
|
||||
add_tuya_io(keep_warm_time, int, 2, 105)
|
||||
|
||||
update = get_tasmota_updater()
|
||||
|
||||
DEVICE_CONFIG = {'run_config_post': f'def () return tasmota.cmd("TuyaSend0") end'}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import random
|
||||
from typing import Any
|
||||
|
||||
from haco import trigger
|
||||
from haco import trigger, Update, Response
|
||||
from haco.sensor import Sensor
|
||||
from haco.tasmota import Tasmota
|
||||
from haco.tools import get_latest
|
||||
|
||||
|
||||
def get_memory_sensor():
|
||||
|
|
@ -13,3 +15,42 @@ def get_memory_sensor():
|
|||
return value.get('heap_free', 'unknown')
|
||||
|
||||
return memory_sensor
|
||||
|
||||
|
||||
def get_tasmota_updater():
|
||||
DEFAULT_OTA_URL = 'https://ota.tasmota.com/tasmota32/release/tasmota32.bin'
|
||||
|
||||
once_daily = trigger.Cron(f"0 {random.randint(0, 59)} {random.randint(0, 23)} * * *")
|
||||
|
||||
update = Update('Update Tasmota')
|
||||
|
||||
@update.callback()
|
||||
def ha(value) -> Tasmota[str, 'tasmota.cmd("upgrade 1")']:
|
||||
return value
|
||||
|
||||
@update.callback(trigger=once_daily)
|
||||
def latest_version_tasmota(value):
|
||||
tag = get_latest('arendst', 'Tasmota')
|
||||
|
||||
if not tag:
|
||||
return Response(send=False)
|
||||
|
||||
tag = tag.lstrip('v')
|
||||
|
||||
return tag
|
||||
|
||||
@update.callback(trigger=once_daily)
|
||||
def tasmota(value: Tasmota[Any, 'tasmota.cmd("status 2")'], otaurl: Tasmota[Any, 'tasmota.cmd("OtaUrl")']):
|
||||
|
||||
if otaurl['OtaUrl'] != DEFAULT_OTA_URL:
|
||||
return Response(send=False)
|
||||
|
||||
version = value.get('StatusFWR', {}).get('Version') or ''
|
||||
version = version.removesuffix('(tasmota32)')
|
||||
|
||||
if not version:
|
||||
return Response(send=False)
|
||||
|
||||
return version
|
||||
|
||||
return update
|
||||
|
|
|
|||
|
|
@ -79,6 +79,15 @@ class Platform:
|
|||
|
||||
self.callback = None
|
||||
|
||||
@property
|
||||
def callback_id(self):
|
||||
return (
|
||||
Path() /
|
||||
self.capability.schema.control.NAME /
|
||||
self.capability.schema.control.name_sanitized /
|
||||
self.capability.name
|
||||
)
|
||||
|
||||
@property
|
||||
def callback_function_name(self):
|
||||
return f'{self.capability.alias}_{self.PLATFORM}'
|
||||
|
|
@ -220,7 +229,8 @@ class HomeAssistant(Platform):
|
|||
'topic': None,
|
||||
'trigger': str(trigger),
|
||||
'function': self.callback.function_tasmota,
|
||||
'type': 'MqttSubscription'
|
||||
'type': 'MqttSubscription',
|
||||
'id': str(self.callback_id)
|
||||
}
|
||||
|
||||
return config
|
||||
|
|
@ -290,7 +300,8 @@ class Tasmota(Platform):
|
|||
'topic': str(self.get_topic_subscription()),
|
||||
'trigger': self.callback.trigger,
|
||||
'function': self.callback.function_tasmota,
|
||||
'type': self.callback.type_id
|
||||
'type': self.callback.type_id,
|
||||
'id': str(self.callback_id)
|
||||
}
|
||||
|
||||
return config
|
||||
|
|
|
|||
3
setup.py
3
setup.py
|
|
@ -24,7 +24,8 @@ setup(
|
|||
},
|
||||
install_requires=[
|
||||
'aiomqtt',
|
||||
'pyyaml'
|
||||
'pyyaml',
|
||||
'requests'
|
||||
],
|
||||
extras_require={
|
||||
'tasmota': [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue