From 4c894270db27449db27165f94db9e4588e63d24e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 15 Nov 2023 00:53:59 -0600 Subject: [PATCH] Pass the name to the log runner when available When connecting by IP, by passing the name, we can reconnect quicker if the device goes offline while running logs since we can use the zeroconf logic to watch for the device to come back online --- esphome/components/api/client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/esphome/components/api/client.py b/esphome/components/api/client.py index 2c43eca70c..2ec6b89eb7 100644 --- a/esphome/components/api/client.py +++ b/esphome/components/api/client.py @@ -18,9 +18,10 @@ from . import CONF_ENCRYPTION _LOGGER = logging.getLogger(__name__) -async def async_run_logs(config, address): +async def async_run_logs(config: dict[str, Any], address: str) -> None: """Run the logs command in the event loop.""" conf = config["api"] + name = config["esphome"].get("name") port: int = int(conf[CONF_PORT]) password: str = conf[CONF_PASSWORD] noise_psk: str | None = None @@ -28,7 +29,6 @@ async def async_run_logs(config, address): noise_psk = conf[CONF_ENCRYPTION][CONF_KEY] _LOGGER.info("Starting log output from %s using esphome API", address) aiozc = AsyncZeroconf() - cli = APIClient( address, port, @@ -48,7 +48,7 @@ async def async_run_logs(config, address): text = text.replace("\033", "\\033") print(f"[{time_.hour:02}:{time_.minute:02}:{time_.second:02}]{text}") - stop = await async_run(cli, on_log, aio_zeroconf_instance=aiozc) + stop = await async_run(cli, on_log, aio_zeroconf_instance=aiozc, name=name) try: while True: await asyncio.sleep(60)