From 465c9ba079cb9bdb970bdd57d30838ad0f13e100 Mon Sep 17 00:00:00 2001 From: Edward Brown Date: Tue, 29 Aug 2023 21:35:05 +0100 Subject: [PATCH] Add assignment addon options, improve logging --- ha/addon/config.yaml | 10 ++++++++-- ha/addon/run.sh | 2 ++ haco/tools.py | 12 +++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/ha/addon/config.yaml b/ha/addon/config.yaml index 34df686..22bd0ba 100644 --- a/ha/addon/config.yaml +++ b/ha/addon/config.yaml @@ -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 diff --git a/ha/addon/run.sh b/ha/addon/run.sh index 5a084cf..7789376 100644 --- a/ha/addon/run.sh +++ b/ha/addon/run.sh @@ -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 \ No newline at end of file diff --git a/haco/tools.py b/haco/tools.py index 2e18a75..720e3fe 100644 --- a/haco/tools.py +++ b/haco/tools.py @@ -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):