Skip to content

Commit 59b9531

Browse files
committed
reststructure offline node code
1 parent d731dea commit 59b9531

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

matter_server/server/device_controller.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -958,10 +958,9 @@ def resubscription_attempted(
958958
# we debounce it a bit so we only mark the node unavailable
959959
# at the second resubscription attempt
960960
if node.available and self._last_subscription_attempt[node_id] >= 1:
961-
node.available = False
962961
# NOTE: if the node is (re)discovered by mdns, that callback will
963962
# take care of resubscribing to the node
964-
self.server.signal_event(EventType.NODE_UPDATED, node)
963+
asyncio.create_task(self._node_offline(node_id))
965964
self._last_subscription_attempt[node_id] += 1
966965

967966
def resubscription_succeeded(
@@ -1219,15 +1218,7 @@ async def _on_mdns_operational_node_state(
12191218
if not node.available:
12201219
return # node is already offline, nothing to do
12211220
LOGGER.info("Node %s vanished according to MDNS", node_id)
1222-
# Remove and cancel any existing interview/subscription reschedule timer
1223-
if existing := self._sub_retry_timer.pop(node_id, None):
1224-
existing.cancel()
1225-
# shutdown existing subscriptions
1226-
if sub := self._subscriptions.pop(node_id, None):
1227-
await self._call_sdk(sub.Shutdown)
1228-
# mark node as unavailable
1229-
node.available = False
1230-
self.server.signal_event(EventType.NODE_UPDATED, node_id)
1221+
await self._node_offline(node_id)
12311222
finally:
12321223
self._mdns_inprogress.remove(node_id)
12331224

@@ -1256,3 +1247,18 @@ def _write_node_state(self, node_id: int, force: bool = False) -> None:
12561247
subkey=str(node_id),
12571248
force=force,
12581249
)
1250+
1251+
async def _node_offline(self, node_id: int) -> None:
1252+
"""Mark node as offline."""
1253+
# Remove and cancel any existing interview/subscription reschedule timer
1254+
if existing := self._sub_retry_timer.pop(node_id, None):
1255+
existing.cancel()
1256+
# shutdown existing subscriptions
1257+
if sub := self._subscriptions.pop(node_id, None):
1258+
await self._call_sdk(sub.Shutdown)
1259+
# mark node as unavailable
1260+
node = self._nodes[node_id]
1261+
if not node.available:
1262+
return
1263+
node.available = False
1264+
self.server.signal_event(EventType.NODE_UPDATED, node)

0 commit comments

Comments
 (0)