Skip to content

Commit

Permalink
Add missing value metadata properties (#837)
Browse files Browse the repository at this point in the history
* Add missing value metadata properties

* add missing property
  • Loading branch information
raman325 authored Dec 11, 2023
1 parent 911095e commit 35dfad6
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 1 deletion.
61 changes: 61 additions & 0 deletions test/model/test_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from zwave_js_server.model.node import Node
from zwave_js_server.model.value import (
ConfigurationValue,
ConfigurationValueFormat,
MetaDataType,
SetValueResult,
ValueDataType,
Expand Down Expand Up @@ -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
41 changes: 40 additions & 1 deletion zwave_js_server/model/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 35dfad6

Please sign in to comment.