1
0
mirror of https://github.com/esphome/esphome.git synced 2025-02-15 09:28:16 +00:00

actually only use one zc instance

This commit is contained in:
J. Nick Koston 2023-11-11 16:25:51 -06:00
parent 19b6ec9d5a
commit b2e566041e
No known key found for this signature in database

View File

@ -8,6 +8,7 @@ from typing import Any
from aioesphomeapi import APIClient from aioesphomeapi import APIClient
from aioesphomeapi.api_pb2 import SubscribeLogsResponse from aioesphomeapi.api_pb2 import SubscribeLogsResponse
from aioesphomeapi.log_runner import async_run from aioesphomeapi.log_runner import async_run
from zeroconf.asyncio import AsyncZeroconf
from esphome.const import CONF_KEY, CONF_PASSWORD, CONF_PORT, __version__ from esphome.const import CONF_KEY, CONF_PASSWORD, CONF_PORT, __version__
from esphome.core import CORE from esphome.core import CORE
@ -26,12 +27,15 @@ async def async_run_logs(config, address):
if CONF_ENCRYPTION in conf: if CONF_ENCRYPTION in conf:
noise_psk = conf[CONF_ENCRYPTION][CONF_KEY] noise_psk = conf[CONF_ENCRYPTION][CONF_KEY]
_LOGGER.info("Starting log output from %s using esphome API", address) _LOGGER.info("Starting log output from %s using esphome API", address)
aiozc = AsyncZeroconf()
cli = APIClient( cli = APIClient(
address, address,
port, port,
password, password,
client_info=f"ESPHome Logs {__version__}", client_info=f"ESPHome Logs {__version__}",
noise_psk=noise_psk, noise_psk=noise_psk,
zeroconf_instance=aiozc,
) )
dashboard = CORE.dashboard dashboard = CORE.dashboard
@ -44,11 +48,12 @@ async def async_run_logs(config, address):
text = text.replace("\033", "\\033") text = text.replace("\033", "\\033")
print(f"[{time_.hour:02}:{time_.minute:02}:{time_.second:02}]{text}") print(f"[{time_.hour:02}:{time_.minute:02}:{time_.second:02}]{text}")
stop = await async_run(cli, on_log) stop = await async_run(cli, on_log, aio_zeroconf_instance=aiozc)
try: try:
while True: while True:
await asyncio.sleep(60) await asyncio.sleep(60)
finally: finally:
await aiozc.async_close()
await stop() await stop()