Skip to content

Commit f29cc35

Browse files
authored
Cleanup: Remove fallback node scanner (#882)
1 parent 7b09393 commit f29cc35

File tree

1 file changed

+1
-47
lines changed

1 file changed

+1
-47
lines changed

matter_server/server/device_controller.py

+1-47
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
NODE_PING_TIMEOUT = 10
8888
NODE_PING_TIMEOUT_BATTERY_POWERED = 60
8989
NODE_MDNS_SUBSCRIPTION_RETRY_TIMEOUT = 30 * 60
90-
FALLBACK_NODE_SCANNER_INTERVAL = 30 * 60
9190
CUSTOM_ATTRIBUTES_POLLER_INTERVAL = 30
9291

9392
MDNS_TYPE_OPERATIONAL_NODE = "_matter._tcp.local."
@@ -156,8 +155,6 @@ def __init__(
156155
self._known_commissioning_params_timers: dict[int, asyncio.TimerHandle] = {}
157156
self._aiobrowser: AsyncServiceBrowser | None = None
158157
self._aiozc: AsyncZeroconf | None = None
159-
self._fallback_node_scanner_timer: asyncio.TimerHandle | None = None
160-
self._fallback_node_scanner_task: asyncio.Task | None = None
161158
self._thread_node_setup_throttle = asyncio.Semaphore(5)
162159
self._mdns_event_timer: dict[str, asyncio.TimerHandle] = {}
163160
self._polled_attributes: dict[int, set[str]] = {}
@@ -218,18 +215,12 @@ async def start(self) -> None:
218215
services,
219216
handlers=[self._on_mdns_service_state_change],
220217
)
221-
# set-up fallback node scanner
222-
self._schedule_fallback_scanner()
223218

224219
async def stop(self) -> None:
225220
"""Handle logic on server stop."""
226-
# shutdown (and cleanup) mdns browser and fallback node scanner
221+
# shutdown (and cleanup) mdns browser
227222
if self._aiobrowser:
228223
await self._aiobrowser.async_cancel()
229-
if self._fallback_node_scanner_timer:
230-
self._fallback_node_scanner_timer.cancel()
231-
if (scan_task := self._fallback_node_scanner_task) and not scan_task.done():
232-
scan_task.cancel()
233224
if self._aiozc:
234225
await self._aiozc.async_close()
235226
# Ensure any in-progress setup tasks are cancelled
@@ -1581,43 +1572,6 @@ async def _node_offline(self, node_id: int) -> None:
15811572
# mark node as unavailable (if it wasn't already)
15821573
self._node_unavailable(node_id)
15831574

1584-
async def _fallback_node_scanner(self) -> None:
1585-
"""Scan for operational nodes in the background that are missed by mdns."""
1586-
# This code could/should be removed in the future and is added to have a fallback
1587-
# to discover operational nodes that got somehow missed by zeroconf.
1588-
# the issue in zeroconf is being investigated and in the meanwhile we have this fallback.
1589-
for node_id, node in self._nodes.items():
1590-
if node.available:
1591-
continue
1592-
now = time.time()
1593-
last_seen = self._node_last_seen_on_mdns.get(node_id, 0)
1594-
if now - last_seen < FALLBACK_NODE_SCANNER_INTERVAL:
1595-
continue
1596-
if await self.ping_node(node_id, attempts=3):
1597-
LOGGER.info("Node %s discovered using fallback ping", node_id)
1598-
if task := self._setup_node_create_task(node_id):
1599-
await task
1600-
1601-
# reschedule self to run at next interval
1602-
self._schedule_fallback_scanner()
1603-
1604-
def _schedule_fallback_scanner(self) -> None:
1605-
"""Schedule running the fallback node scanner at X interval."""
1606-
if existing := self._fallback_node_scanner_timer:
1607-
existing.cancel()
1608-
1609-
def run_fallback_node_scanner() -> None:
1610-
self._fallback_node_scanner_timer = None
1611-
if (existing := self._fallback_node_scanner_task) and not existing.done():
1612-
existing.cancel()
1613-
self._fallback_node_scanner_task = asyncio.create_task(
1614-
self._fallback_node_scanner()
1615-
)
1616-
1617-
self._fallback_node_scanner_timer = self._loop.call_later(
1618-
FALLBACK_NODE_SCANNER_INTERVAL, run_fallback_node_scanner
1619-
)
1620-
16211575
async def _custom_attributes_poller(self) -> None:
16221576
"""Poll custom clusters/attributes for changes."""
16231577
for node_id in tuple(self._polled_attributes):

0 commit comments

Comments
 (0)