fix(connection): let the library own keep_reconnecting's task — no double scheduling on protocol start/stop
This commit is contained in:
1 parent
9a1e1300dd
commit
a4e7a285d4
1 file changed
+4
-8
@@ -166,7 +166,6 @@ class ShieldConnectionManager:
|
|||||||
self._protocol = protocol
|
self._protocol = protocol
|
||||||
self._protocol_settings = protocol_settings
|
self._protocol_settings = protocol_settings
|
||||||
self._invalid_auth_callback = invalid_auth_callback
|
self._invalid_auth_callback = invalid_auth_callback
|
||||||
self._protocol_task: asyncio.Task | None = None
|
|
||||||
self._protocol_loop: asyncio.AbstractEventLoop | None = None
|
self._protocol_loop: asyncio.AbstractEventLoop | None = None
|
||||||
self._listeners: list[Callable[[], None]] = []
|
self._listeners: list[Callable[[], None]] = []
|
||||||
self._tasks: list[asyncio.Task] = []
|
self._tasks: list[asyncio.Task] = []
|
||||||
@@ -251,10 +250,10 @@ class ShieldConnectionManager:
|
|||||||
client.add_is_available_updated_callback(self._on_is_available)
|
client.add_is_available_updated_callback(self._on_is_available)
|
||||||
client.add_current_app_updated_callback(self._on_current_app)
|
client.add_current_app_updated_callback(self._on_current_app)
|
||||||
client.add_volume_info_updated_callback(self._on_volume_info)
|
client.add_volume_info_updated_callback(self._on_volume_info)
|
||||||
self._protocol_task = self._create_task(
|
# One owner per transport: the library's keep_reconnecting() creates
|
||||||
client.keep_reconnecting(self._on_invalid_auth),
|
# and owns its reconnect task internally — we never wrap or duplicate
|
||||||
"shield_protocol_keep_reconnecting",
|
# it (the stop path closes the client, which tears the task down).
|
||||||
)
|
client.keep_reconnecting(self._on_invalid_auth)
|
||||||
|
|
||||||
def _on_is_on(self, on) -> None:
|
def _on_is_on(self, on) -> None:
|
||||||
self._protocol_push(FIELD_IS_ON, bool(on))
|
self._protocol_push(FIELD_IS_ON, bool(on))
|
||||||
@@ -420,9 +419,6 @@ class ShieldConnectionManager:
|
|||||||
tasks, self._tasks = self._tasks, []
|
tasks, self._tasks = self._tasks, []
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
task.cancel()
|
task.cancel()
|
||||||
if self._protocol_task is not None:
|
|
||||||
self._protocol_task.cancel()
|
|
||||||
self._protocol_task = None
|
|
||||||
self._listeners.clear()
|
self._listeners.clear()
|
||||||
if self._poller is not None:
|
if self._poller is not None:
|
||||||
with contextlib.suppress(Exception):
|
with contextlib.suppress(Exception):
|
||||||
|
|||||||
Reference in new issue
Block a user