This commit is contained in:
J. Nick Koston 2023-11-11 11:59:23 -06:00
parent 6a5cea171e
commit 9bdd802c7a
No known key found for this signature in database

View file

@ -4,10 +4,11 @@ from datetime import datetime
from typing import Optional
from aioesphomeapi import APIClient, ReconnectLogic, APIConnectionError, LogLevel
from aioesphomeapi.api_pb2 import SubscribeLogsResponse
import zeroconf
from esphome.const import CONF_KEY, CONF_PORT, CONF_PASSWORD, __version__
from esphome.util import safe_print
from esphome.core import CORE
from . import CONF_ENCRYPTION
_LOGGER = logging.getLogger(__name__)
@ -29,11 +30,16 @@ async def async_run_logs(config, address):
noise_psk=noise_psk,
)
first_connect = True
dashboard = CORE.dashboard
def on_log(msg):
time_ = datetime.now().time().strftime("[%H:%M:%S]")
text = msg.message.decode("utf8", "backslashreplace")
safe_print(time_ + text)
def on_log(msg: SubscribeLogsResponse) -> None:
"""Handle a new log message."""
time_ = datetime.now()
message: bytes = msg.message
text = message.decode("utf8", "backslashreplace")
if dashboard:
text = text.replace("\033", "\\033")
print(f"[{time_.hour:02}:{time_.minute:02}:{time_.second:02}]{text}")
async def on_connect():
nonlocal first_connect