Add assignment addon options, improve logging

This commit is contained in:
Edward Brown 2023-08-29 21:35:05 +01:00
parent 1c180f7fe6
commit 465c9ba079
3 changed files with 19 additions and 5 deletions

View file

@ -9,9 +9,15 @@ init: false
map:
- config:rw
name: haco
options: { }
options:
assignments:
- config: null
identifier: null
panel_icon: mdi:network-pos
schema: { }
schema:
assignments:
- config: str
identifier: str
services:
- mqtt:need
slug: haco

View file

@ -7,4 +7,6 @@ export MQTT_PASSWORD="$(bashio::services mqtt 'password')"
export MQTT_PORT="$(bashio::services mqtt 'port')"
export MQTT_USERNAME="$(bashio::services mqtt 'username')"
cp /data/options.json /config/haco/options.json
haco-daemon

View file

@ -1,8 +1,14 @@
import hashlib
import logging
from haco import constants, tuya
from haco.tasmota import Tasmota
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
def split_into_chunks(input_string, chunk_size):
return [input_string[i:i + chunk_size] for i in range(0, len(input_string), chunk_size)]
@ -30,20 +36,20 @@ def truncate_middle(input_string, max_length):
async def log_publish(client, topic, payload, retain=False):
log_retain = '|' if retain else ' '
message = f'mqtt->{log_retain} {topic} {truncate_middle(payload, 100)}'
print(message)
logger.debug(message)
await client.publish(topic=topic, payload=payload, retain=retain)
async def log_subscribe(client, topic):
message = f'mqtt+{topic}'
print(message)
logger.debug(message)
await client.subscribe(topic=topic)
async def log_received(message):
log_retain = '|' if message.retain else ' '
message = f'mqtt<-{log_retain} {message.topic} {truncate_middle(message.payload.decode("utf-8"), 100)}'
print(message)
logger.debug(message)
def callback_default(value, data=None):