Skip to content

Commit

Permalink
Some small fixes for the client (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Jun 28, 2023
1 parent 7cdb9f3 commit 4238166
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions matter_server/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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,
)
Expand Down
6 changes: 3 additions & 3 deletions matter_server/server/device_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 4238166

Please sign in to comment.