mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-12-22 16:48:04 +01:00
Clear on_stop after calling instead of using a separate _on_stop_called
bool (#357)
This commit is contained in:
parent
284b767d8d
commit
025376852b
@ -95,8 +95,7 @@ class APIConnection:
|
||||
log_name: Optional[str] = None,
|
||||
) -> None:
|
||||
self._params = params
|
||||
self.on_stop = on_stop
|
||||
self._on_stop_called = False
|
||||
self.on_stop: Optional[Callable[[], Coroutine[Any, Any, None]]] = on_stop
|
||||
self._socket: Optional[socket.socket] = None
|
||||
self._frame_helper: Optional[APIFrameHelper] = None
|
||||
self._api_version: Optional[APIVersion] = None
|
||||
@ -151,10 +150,10 @@ class APIConnection:
|
||||
self._socket.close()
|
||||
self._socket = None
|
||||
|
||||
if not self._on_stop_called and self._connect_complete:
|
||||
# Ensure on_stop is called
|
||||
if self.on_stop and self._connect_complete:
|
||||
# Ensure on_stop is called only once
|
||||
asyncio.create_task(self.on_stop())
|
||||
self._on_stop_called = True
|
||||
self.on_stop = None
|
||||
|
||||
# Note: we don't explicitly cancel the ping/read task here
|
||||
# That's because if not written right the ping/read task could cancel
|
||||
|
Loading…
Reference in New Issue
Block a user