mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2025-02-20 02:22:13 +01:00
Propagate if disconnect was expected to disconnect callback (#448)
This commit is contained in:
parent
b490d3b7e0
commit
4fe46f5aa0
@ -59,7 +59,9 @@ async def main(argv: List[str]) -> None:
|
|||||||
except APIConnectionError:
|
except APIConnectionError:
|
||||||
await cli.disconnect()
|
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")
|
_LOGGER.warning("Disconnected from API")
|
||||||
|
|
||||||
logic = ReconnectLogic(
|
logic = ReconnectLogic(
|
||||||
|
@ -33,7 +33,7 @@ class ReconnectLogic(zeroconf.RecordUpdateListener):
|
|||||||
*,
|
*,
|
||||||
client: APIClient,
|
client: APIClient,
|
||||||
on_connect: Callable[[], Awaitable[None]],
|
on_connect: Callable[[], Awaitable[None]],
|
||||||
on_disconnect: Callable[[], Awaitable[None]],
|
on_disconnect: Callable[[bool], Awaitable[None]],
|
||||||
zeroconf_instance: "zeroconf.Zeroconf",
|
zeroconf_instance: "zeroconf.Zeroconf",
|
||||||
name: Optional[str] = None,
|
name: Optional[str] = None,
|
||||||
on_connect_error: Optional[Callable[[Exception], Awaitable[None]]] = None,
|
on_connect_error: Optional[Callable[[Exception], Awaitable[None]]] = None,
|
||||||
@ -86,7 +86,7 @@ class ReconnectLogic(zeroconf.RecordUpdateListener):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Run disconnect hook
|
# Run disconnect hook
|
||||||
await self._on_disconnect_cb()
|
await self._on_disconnect_cb(expected_disconnect)
|
||||||
|
|
||||||
async with self._connected_lock:
|
async with self._connected_lock:
|
||||||
self._connected = False
|
self._connected = False
|
||||||
|
Loading…
Reference in New Issue
Block a user