From 85638bc339a357e3b1b251c5df8b5d918dcb8ca3 Mon Sep 17 00:00:00 2001 From: Edward Brown Date: Wed, 6 Sep 2023 20:05:25 +0100 Subject: [PATCH] Rename default capability name from state to default --- haco/button.py | 4 ++-- haco/constants.py | 2 ++ haco/control.py | 6 +++--- haco/sensor.py | 4 ++-- haco/update.py | 3 ++- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/haco/button.py b/haco/button.py index 0c288a7..9572d78 100644 --- a/haco/button.py +++ b/haco/button.py @@ -1,4 +1,4 @@ -from haco import schema +from haco import schema, constants from haco.control import Control @@ -10,7 +10,7 @@ class Button(Control): return schema.Schema( capabilities=[ schema.Capability( - name='state', + name=constants.DEFAULT, ha=schema.HomeAssistant(announce_data=schema.AnnounceTopic(key='{io_ha}_topic')), tamota=None ) diff --git a/haco/constants.py b/haco/constants.py index 474625d..38cbfcc 100644 --- a/haco/constants.py +++ b/haco/constants.py @@ -6,6 +6,8 @@ CHARS_ALLOWED = string.ascii_lowercase + string.digits SEPS = '_- /' BRANCH = 'release' +DEFAULT = 'default' + CONFIGS_PATH = Path(os.environ['HACO_CONFIGS_PATH']) OPTIONS_PATH = Path(os.environ['HACO_OPTIONS_PATH']) MQTT_PASSWORD = os.environ['MQTT_PASSWORD'] diff --git a/haco/control.py b/haco/control.py index 4aa9551..a7f5a2f 100644 --- a/haco/control.py +++ b/haco/control.py @@ -1,7 +1,7 @@ import logging from functools import partial -from haco import schema, tools +from haco import schema, tools, constants from haco.callback import Callback from haco.schema import Schema, Platform, Tasmota, HomeAssistant, AnnounceTopic, Capability from haco.tools import log_publish @@ -17,7 +17,7 @@ class Control: schema = Schema( capabilities=[ Capability( - name='state', + name=constants.DEFAULT, ha=HomeAssistant(announce_data=AnnounceTopic(key='{io_ha}_topic')), tamota=Tasmota(announce_data=AnnounceTopic(key='{io_ha}_topic')) ) @@ -49,7 +49,7 @@ class Control: def add_callback(self, trigger, function): if (function_name := function.__name__) in {Tasmota.PLATFORM, HomeAssistant.PLATFORM}: - function_name = f'state_{function_name}' + function_name = f'{constants.DEFAULT}_{function_name}' callback_names = self.schema.get_callback_function_names() diff --git a/haco/sensor.py b/haco/sensor.py index e27aa09..4d7fbfa 100644 --- a/haco/sensor.py +++ b/haco/sensor.py @@ -1,4 +1,4 @@ -from haco import schema +from haco import schema, constants from haco.control import Control from haco.data.type_sensor import DeviceClassSensor @@ -16,7 +16,7 @@ class Sensor(Control): return schema.Schema( capabilities=[ schema.Capability( - name='state', + name=constants.DEFAULT, ha=None, tamota=schema.Tasmota(announce_data=schema.AnnounceTopic(key='{io_ha}_topic')) ) diff --git a/haco/update.py b/haco/update.py index 79800b5..7617a98 100644 --- a/haco/update.py +++ b/haco/update.py @@ -1,3 +1,4 @@ +from haco import constants from haco.control import Control from haco.schema import Schema, Capability, AnnounceTopic, Tasmota, HomeAssistant @@ -10,7 +11,7 @@ class Update(Control): schema = Schema( capabilities=[ Capability( - name='state', + name=constants.DEFAULT, ha=HomeAssistant(announce_data=AnnounceTopic(key='{io_ha}_topic')), tamota=Tasmota(announce_data=AnnounceTopic(key='{io_ha}_topic')) ),