Skip to content

Commit 3bc8387

Browse files
committed
use node lock for read and write attribute
1 parent 86edc3f commit 3bc8387

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

matter_server/server/device_controller.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,7 @@ async def send_device_command(
551551
cluster_cls: Cluster = ALL_CLUSTERS[cluster_id]
552552
command_cls = getattr(cluster_cls.Commands, command_name)
553553
command = dataclass_from_dict(command_cls, payload, allow_sdk_types=True)
554-
node_lock = self._get_node_lock(node_id)
555-
async with node_lock:
554+
async with self._get_node_lock(node_id):
556555
return await self.chip_controller.SendCommand(
557556
nodeid=node_id,
558557
endpoint=endpoint_id,
@@ -573,10 +572,9 @@ async def read_attribute(
573572
raise NodeNotReady(f"Node {node_id} is not (yet) available.")
574573
endpoint_id, cluster_id, attribute_id = parse_attribute_path(attribute_path)
575574
assert self.server.loop is not None
576-
future = self.server.loop.create_future()
577-
device = await self._resolve_node(node_id)
578-
node_lock = self._get_node_lock(node_id)
579-
async with node_lock:
575+
async with self._get_node_lock(node_id):
576+
future = self.server.loop.create_future()
577+
device = await self._resolve_node(node_id)
580578
Attribute.Read(
581579
future=future,
582580
eventLoop=self.server.loop,
@@ -621,10 +619,11 @@ async def write_attribute(
621619
value_type=attribute.attribute_type.Type,
622620
allow_sdk_types=True,
623621
)
624-
return await self.chip_controller.WriteAttribute(
625-
nodeid=node_id,
626-
attributes=[(endpoint_id, attribute)],
627-
)
622+
async with self._get_node_lock(node_id):
623+
return await self.chip_controller.WriteAttribute(
624+
nodeid=node_id,
625+
attributes=[(endpoint_id, attribute)],
626+
)
628627

629628
@api_command(APICommand.REMOVE_NODE)
630629
async def remove_node(self, node_id: int) -> None:
@@ -1084,8 +1083,7 @@ async def _resolve_node(
10841083
self, node_id: int, retries: int = 2, attempt: int = 1
10851084
) -> DeviceProxyWrapper:
10861085
"""Resolve a Node on the network."""
1087-
# log_level = logging.DEBUG if attempt == 1 else logging.INFO
1088-
log_level = logging.INFO # TEMP !
1086+
log_level = logging.DEBUG if attempt == 1 else logging.INFO
10891087
if self.chip_controller is None:
10901088
raise RuntimeError("Device Controller not initialized.")
10911089
try:

0 commit comments

Comments
 (0)