From 35dfad6729267be80fd3bbf1c8b08f3029eea485 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Mon, 11 Dec 2023 11:23:14 -0500 Subject: [PATCH] Add missing value metadata properties (#837) * Add missing value metadata properties * add missing property --- test/model/test_value.py | 61 ++++++++++++++++++++++++++++++++++ zwave_js_server/model/value.py | 41 ++++++++++++++++++++++- 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/test/model/test_value.py b/test/model/test_value.py index 2adaa32ad..08604424b 100644 --- a/test/model/test_value.py +++ b/test/model/test_value.py @@ -5,6 +5,7 @@ from zwave_js_server.model.node import Node from zwave_js_server.model.value import ( ConfigurationValue, + ConfigurationValueFormat, MetaDataType, SetValueResult, ValueDataType, @@ -222,3 +223,63 @@ def test_set_value_result_str(): result = SetValueResult({"status": 1, "remainingDuration": "unknown"}) assert result.status == SetValueStatus.WORKING assert str(result) == "Working (unknown duration)" + + +def test_configuration_value_metadata(inovelli_switch_state): + """Test configuration value specific metadata.""" + value = ConfigurationValue( + inovelli_switch_state, + ValueDataType( + commandClass=112, + property=8, + propertyName="8", + endpoint=0, + metadata=MetaDataType( + type="boolean", + max=2, + min=0, + allowManualEntry=True, + states={True: "On", False: "Off"}, + ), + ), + ) + metadata = value.metadata + assert metadata.default is None + assert metadata.is_advanced is None + assert metadata.is_from_config is None + assert metadata.requires_re_inclusion is None + assert metadata.no_bulk_support is None + assert metadata.value_size is None + assert metadata.format is None + + value = ConfigurationValue( + inovelli_switch_state, + ValueDataType( + commandClass=112, + property=8, + propertyName="8", + endpoint=0, + metadata=MetaDataType( + type="boolean", + max=2, + min=0, + allowManualEntry=True, + states={True: "On", False: "Off"}, + default=2, + isAdvanced=True, + isFromConfig=True, + requiresReInclusion=True, + noBulkSupport=True, + valueSize=1, + format=0, + ), + ), + ) + metadata = value.metadata + assert metadata.default == 2 + assert metadata.is_advanced + assert metadata.is_from_config + assert metadata.requires_re_inclusion + assert metadata.no_bulk_support + assert metadata.value_size == 1 + assert metadata.format == ConfigurationValueFormat.SIGNED_INTEGER diff --git a/zwave_js_server/model/value.py b/zwave_js_server/model/value.py index ae5fdc7ae..112d20eb2 100644 --- a/zwave_js_server/model/value.py +++ b/zwave_js_server/model/value.py @@ -45,9 +45,16 @@ class MetaDataType(TypedDict, total=False): ccSpecific: dict[str, Any] valueChangeOptions: list[str] allowManualEntry: bool - valueSize: int stateful: bool secret: bool + default: int + # Configuration Value specific attributes + valueSize: int + format: int + noBulkSupport: bool # deprecated + isAdvanced: bool + requiresReInclusion: bool + isFromConfig: bool class ValueDataType(TypedDict, total=False): @@ -184,6 +191,38 @@ def secret(self) -> bool | None: """Return secret.""" return self.data.get("secret") + @property + def default(self) -> int | None: + """Return default.""" + return self.data.get("default") + + @property + def format(self) -> ConfigurationValueFormat | None: + """Return format.""" + if (format_ := self.data.get("format")) is None: + return None + return ConfigurationValueFormat(format_) + + @property + def no_bulk_support(self) -> bool | None: + """Return noBulkSupport.""" + return self.data.get("noBulkSupport") + + @property + def is_advanced(self) -> bool | None: + """Return isAdvanced.""" + return self.data.get("isAdvanced") + + @property + def requires_re_inclusion(self) -> bool | None: + """Return requiresReInclusion.""" + return self.data.get("requiresReInclusion") + + @property + def is_from_config(self) -> bool | None: + """Return isFromConfig.""" + return self.data.get("isFromConfig") + def update(self, data: MetaDataType) -> None: """Update data.""" self.data.update(data)