From 463cdd480963b71fbc6db699df030699895fb2a4 Mon Sep 17 00:00:00 2001 From: Timofey Klimov Date: Tue, 30 Jul 2024 17:51:58 +0300 Subject: [PATCH] Move some constants to separate file --- codes/climate/1948.json | 1 - custom_components/smartir/__init__.py | 13 +++++++++++-- custom_components/smartir/climate.py | 8 +++++--- custom_components/smartir/controller_const.py | 3 +++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/codes/climate/1948.json b/codes/climate/1948.json index a8a15cfa..d50d6040 100644 --- a/codes/climate/1948.json +++ b/codes/climate/1948.json @@ -6,7 +6,6 @@ "RC-3" ], "supportedController": "UFOR11", - "disable_sending_commands_when_device_off": true, "commandsEncoding": "Raw", "temperatureUnit": "C", "minTemperature": 16.0, diff --git a/custom_components/smartir/__init__.py b/custom_components/smartir/__init__.py index 4626a93e..efa63308 100644 --- a/custom_components/smartir/__init__.py +++ b/custom_components/smartir/__init__.py @@ -5,7 +5,11 @@ import hashlib import json -from .controller_const import CONTROLLER_SUPPORT +from .controller_const import ( + CONTROLLER_SUPPORT, + CONF_CODE_ON_NAME, + CONF_CODE_REGULAR_NAME, +) _LOGGER = logging.getLogger(__name__) @@ -442,7 +446,12 @@ def check_file_climate_commands( return False elif level == "temperature": for temp in commands.keys(): - if not (isinstance(commands[temp], str) and commands[temp]): + if not ( + commands[temp] + and isinstance(commands[temp], dict) + and CONF_CODE_ON_NAME in commands[temp] + and CONF_CODE_REGULAR_NAME in commands[temp] + ) and not (commands[temp] and isinstance(commands[temp], str)): _LOGGER.error( "Invalid %s device JSON file '%s': invalid 'temperature' '%s' command value '%s'.", device_class, diff --git a/custom_components/smartir/climate.py b/custom_components/smartir/climate.py index d2397ec9..f5d7435b 100644 --- a/custom_components/smartir/climate.py +++ b/custom_components/smartir/climate.py @@ -1,6 +1,11 @@ import asyncio import logging +from .controller_const import ( + CONF_CODE_ON_NAME, + CONF_CODE_REGULAR_NAME, +) + import voluptuous as vol from numbers import Number @@ -51,9 +56,6 @@ PRECISION_DOUBLE = 2 -CONF_CODE_ON_NAME = "on" -CONF_CODE_REGULAR_NAME = "regular" - PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Optional(CONF_UNIQUE_ID): cv.string, diff --git a/custom_components/smartir/controller_const.py b/custom_components/smartir/controller_const.py index 14919ed2..94bf8a97 100644 --- a/custom_components/smartir/controller_const.py +++ b/custom_components/smartir/controller_const.py @@ -44,3 +44,6 @@ "ZHA_COMMAND": "zha_command", "ZHA_COMMAND_TYPE": "zha_command_type", } + +CONF_CODE_ON_NAME = "on" +CONF_CODE_REGULAR_NAME = "regular"