From c4f49afbe89e417f18583db5ffc5b5f87529fbc6 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Wed, 9 Aug 2023 02:15:56 -0400 Subject: [PATCH 1/3] Improve logic for determining config value boolean type --- zwave_js_server/model/value.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/zwave_js_server/model/value.py b/zwave_js_server/model/value.py index 3a189dc0..6d98eb1b 100644 --- a/zwave_js_server/model/value.py +++ b/zwave_js_server/model/value.py @@ -2,6 +2,7 @@ from __future__ import annotations from dataclasses import dataclass, field +from enum import StrEnum from typing import TYPE_CHECKING, Any, TypedDict from ..const import VALUE_UNKNOWN, CommandClass, ConfigurationValueType, SetValueStatus @@ -13,6 +14,15 @@ from .node import Node +class ValueType(StrEnum): + """Enum with all value types.""" + + ANY = "any" + BOOLEAN = "boolean" + NUMBER = "number" + STRING = "string" + + class MetaDataType(TypedDict, total=False): """Represent a metadata data dict type.""" @@ -301,8 +311,11 @@ def configuration_value_type(self) -> ConfigurationValueType: max_ = self.metadata.max states = self.metadata.states allow_manual_entry = self.metadata.allow_manual_entry + type_ = self.metadata.type - if max_ == 1 and min_ == 0 and not states: + if ( + (max_ == 1 and min_ == 0) or type_ == ValueType.BOOLEAN + ) and not states: return ConfigurationValueType.BOOLEAN if ( From 12387474dd71ea6b9a4dc56d3dde7b2a3be9abbe Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Wed, 9 Aug 2023 02:17:17 -0400 Subject: [PATCH 2/3] fix --- zwave_js_server/model/value.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/zwave_js_server/model/value.py b/zwave_js_server/model/value.py index 6d98eb1b..b1bd9e18 100644 --- a/zwave_js_server/model/value.py +++ b/zwave_js_server/model/value.py @@ -313,9 +313,7 @@ def configuration_value_type(self) -> ConfigurationValueType: allow_manual_entry = self.metadata.allow_manual_entry type_ = self.metadata.type - if ( - (max_ == 1 and min_ == 0) or type_ == ValueType.BOOLEAN - ) and not states: + if ((max_ == 1 and min_ == 0) or type_ == ValueType.BOOLEAN) and not states: return ConfigurationValueType.BOOLEAN if ( From 9e277f92329a3afbddd321ba41ab898571195c4e Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Wed, 9 Aug 2023 22:22:41 -0400 Subject: [PATCH 3/3] Update zwave_js_server/model/value.py Co-authored-by: Martin Hjelmare --- zwave_js_server/model/value.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zwave_js_server/model/value.py b/zwave_js_server/model/value.py index b1bd9e18..2841d502 100644 --- a/zwave_js_server/model/value.py +++ b/zwave_js_server/model/value.py @@ -313,7 +313,7 @@ def configuration_value_type(self) -> ConfigurationValueType: allow_manual_entry = self.metadata.allow_manual_entry type_ = self.metadata.type - if ((max_ == 1 and min_ == 0) or type_ == ValueType.BOOLEAN) and not states: + if (max_ == 1 and min_ == 0 or type_ == ValueType.BOOLEAN) and not states: return ConfigurationValueType.BOOLEAN if (