Skip to content

Commit

Permalink
Add to_dict to CommandClassInfo (#1059)
Browse files Browse the repository at this point in the history
* Add to_dict to CommandClassInfo

* Implement suggestion

* Clean whitespace

* Update test

* Test to_dict

---------

Co-authored-by: Martin Hjelmare <[email protected]>
  • Loading branch information
edenhaus and MartinHjelmare authored Sep 10, 2024
1 parent da19e22 commit 1f83f11
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 11 additions & 7 deletions test/model/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
UnwriteableValue,
)
from zwave_js_server.model import endpoint as endpoint_pkg, node as node_pkg
from zwave_js_server.model.node import Node
from zwave_js_server.model.node.firmware import (
NodeFirmwareUpdateInfo,
NodeFirmwareUpdateStatus,
Expand Down Expand Up @@ -207,14 +208,17 @@ async def test_highest_security_value(lock_schlage_be469, ring_keypad):
assert ring_keypad.highest_security_class is None


async def test_command_classes(endpoints_with_command_classes):
async def test_command_classes(endpoints_with_command_classes: Node) -> None:
"""Test command_classes property on endpoint."""
assert len(endpoints_with_command_classes.endpoints[0].command_classes) == 17
assert endpoints_with_command_classes.endpoints[0].command_classes[0].id == 38
assert (
endpoints_with_command_classes.endpoints[0].command_classes[0].command_class
== CommandClass.SWITCH_MULTILEVEL
)
node = endpoints_with_command_classes
assert len(node.endpoints[0].command_classes) == 17
command_class_info = node.endpoints[0].command_classes[0]
assert command_class_info.id == 38
assert command_class_info.command_class == CommandClass.SWITCH_MULTILEVEL
assert command_class_info.name == "Multilevel Switch"
assert command_class_info.version == 2
assert command_class_info.is_secure is False
assert command_class_info.to_dict() == command_class_info.data


async def test_device_config(
Expand Down
4 changes: 4 additions & 0 deletions zwave_js_server/model/command_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ def version(self) -> int:
def is_secure(self) -> bool:
"""Return if the CommandClass is used securely on this node/endpoint."""
return self.data["isSecure"]

def to_dict(self) -> CommandClassInfoDataType:
"""Create a dictionary from itself."""
return self.data.copy()

0 comments on commit 1f83f11

Please sign in to comment.