From f6f9a2b59f81573fa1b6df3d6f96b3232609daa1 Mon Sep 17 00:00:00 2001 From: Bluetooth Devices Bot Date: Wed, 20 May 2026 22:48:51 +0000 Subject: [PATCH] Enable ruff DTZ rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit datetime.now() without a tz argument returns a naive local-time value that silently drifts when serialized or compared against tz-aware datetimes. DTZ catches this class of bug at lint time. The single existing violation (aioesphomeapi/log_reader.py) switches to datetime.now().astimezone() so the timestamp is an aware local datetime — hour/minute/second values are unchanged, the user-visible log prefix stays identical. --- aioesphomeapi/log_reader.py | 2 +- pyproject.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/aioesphomeapi/log_reader.py b/aioesphomeapi/log_reader.py index c73857948..76f2ca790 100644 --- a/aioesphomeapi/log_reader.py +++ b/aioesphomeapi/log_reader.py @@ -61,7 +61,7 @@ async def main(argv: list[str]) -> None: ) def on_log(msg: SubscribeLogsResponse) -> None: - time_ = datetime.now() + time_ = datetime.now().astimezone() message: bytes = msg.message text = message.decode("utf8", "backslashreplace") nanoseconds = time_.microsecond // 1000 diff --git a/pyproject.toml b/pyproject.toml index 6d0b6e58b..5786c6317 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,7 @@ exclude = [ select = [ "ASYNC", # async rules "B", # flake8-bugbear + "DTZ", # flake8-datetimez "E", # pycodestyle "F", # pyflakes/autoflake "FLY", # flynt