Propagate if disconnect was expected to disconnect callback (#448)

This commit is contained in:
J. Nick Koston 2023-06-25 21:45:36 -05:00 committed by GitHub
parent b490d3b7e0
commit 4fe46f5aa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -59,7 +59,9 @@ async def main(argv: List[str]) -> None:
except APIConnectionError:
await cli.disconnect()
async def on_disconnect() -> None:
async def on_disconnect( # pylint: disable=unused-argument
expected_disconnect: bool,
) -> None:
_LOGGER.warning("Disconnected from API")
logic = ReconnectLogic(

View File

@ -33,7 +33,7 @@ class ReconnectLogic(zeroconf.RecordUpdateListener):
*,
client: APIClient,
on_connect: Callable[[], Awaitable[None]],
on_disconnect: Callable[[], Awaitable[None]],
on_disconnect: Callable[[bool], Awaitable[None]],
zeroconf_instance: "zeroconf.Zeroconf",
name: Optional[str] = None,
on_connect_error: Optional[Callable[[Exception], Awaitable[None]]] = None,
@ -86,7 +86,7 @@ class ReconnectLogic(zeroconf.RecordUpdateListener):
)
# Run disconnect hook
await self._on_disconnect_cb()
await self._on_disconnect_cb(expected_disconnect)
async with self._connected_lock:
self._connected = False