From 4238166c47fbc5e78ce15b158cc7bbbe9b38a40a Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Wed, 28 Jun 2023 11:06:59 +0200 Subject: [PATCH] Some small fixes for the client (#339) --- matter_server/client/client.py | 11 +++++++---- matter_server/server/device_controller.py | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/matter_server/client/client.py b/matter_server/client/client.py index 5314ce07..bc0f7a0a 100644 --- a/matter_server/client/client.py +++ b/matter_server/client/client.py @@ -10,7 +10,7 @@ from aiohttp import ClientSession from chip.clusters import Objects as Clusters -from matter_server.common.errors import ERROR_MAP +from matter_server.common.errors import ERROR_MAP, NodeNotExists from ..common.helpers.util import dataclass_from_dict, dataclass_to_dict from ..common.models import ( @@ -54,7 +54,7 @@ def server_info(self) -> ServerInfoMessage | None: """Return info of the server we're currently connected to.""" return self.connection.server_info - def subscribe( + def subscribe_events( self, callback: Callable[[EventType, Any], None], event_filter: Optional[EventType] = None, @@ -103,8 +103,10 @@ def get_nodes(self) -> list[MatterNode]: return list(self._nodes.values()) def get_node(self, node_id: int) -> MatterNode: - """Return Matter node by id.""" - return self._nodes[node_id] + """Return Matter node by id or None if no node exists by that id.""" + if node := self._nodes.get(node_id): + return node + raise NodeNotExists(f"Node {node_id} does not exist or is not yet interviewed") async def commission_with_code(self, code: str) -> MatterNodeData: """ @@ -245,6 +247,7 @@ async def subscribe_attribute( """ await self.send_command( APICommand.SUBSCRIBE_ATTRIBUTE, + require_schema=4, node_id=node_id, attribute_path=attribute_path, ) diff --git a/matter_server/server/device_controller.py b/matter_server/server/device_controller.py index 0cb3ac4b..fb612462 100644 --- a/matter_server/server/device_controller.py +++ b/matter_server/server/device_controller.py @@ -144,9 +144,9 @@ def get_nodes(self, only_available: bool = False) -> list[MatterNodeData]: @api_command(APICommand.GET_NODE) def get_node(self, node_id: int) -> MatterNodeData: """Return info of a single Node.""" - node = self._nodes.get(node_id) - assert node is not None, "Node does not exist or is not yet interviewed" - return node + if node := self._nodes.get(node_id): + return node + raise NodeNotExists(f"Node {node_id} does not exist or is not yet interviewed") @api_command(APICommand.COMMISSION_WITH_CODE) async def commission_with_code(self, code: str) -> MatterNodeData: