Skip to content

Commit

Permalink
Handle unknown and default Durations (#754)
Browse files Browse the repository at this point in the history
* Handle unknown and default Durations

* Remove unused constants

* black

* fix types

* fix types
  • Loading branch information
raman325 authored Sep 12, 2023
1 parent 15e82ae commit 3bd48af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions test/model/test_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,7 @@ def test_set_value_result_str():
result = SetValueResult({"status": 3, "message": "test"})
assert result.status == SetValueStatus.ENDPOINT_NOT_FOUND
assert str(result) == "Endpoint Not Found: test"

result = SetValueResult({"status": 1, "remainingDuration": "unknown"})
assert result.status == SetValueStatus.WORKING
assert str(result) == "Working (unknown duration)"
8 changes: 6 additions & 2 deletions zwave_js_server/model/duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ class DurationDataType(TypedDict, total=False):
"""Represent a Duration data dict type."""

# https://github.com/zwave-js/node-zwave-js/blob/v11-dev/packages/core/src/values/Duration.ts#L11
unit: Literal["seconds", "minutes", "unknown", "default"] # required
unit: Literal["seconds", "minutes"] # required
value: int | float


@dataclass
class Duration:
"""Duration class."""

data: DurationDataType
data: DurationDataType | Literal["unknown", "default"]
unit: Literal["seconds", "minutes", "unknown", "default"] = field(init=False)
value: int | float | None = field(init=False)

def __post_init__(self) -> None:
"""Post init."""
if isinstance(self.data, str):
self.unit = self.data
self.value = None
return
self.unit = self.data["unit"]
self.value = self.data.get("value")

Expand Down

0 comments on commit 3bd48af

Please sign in to comment.