diff --git a/src/ramscreen/__main__.py b/src/ramscreen/__main__.py index 67fd5c2..5234718 100644 --- a/src/ramscreen/__main__.py +++ b/src/ramscreen/__main__.py @@ -55,6 +55,12 @@ def _warn_if_write_timeout(exc: OSError) -> None: "Abhilfe: Display kurz ab- und wieder anstecken") +def _boottime() -> float: + # Wie time.monotonic() (CLOCK_MONOTONIC), läuft aber im Standby weiter: sonst zählten Ausfalldauer und + # Erinnerung bei einem über Nacht abgezogenen Display nur die Wachzeit + return time.clock_gettime(time.CLOCK_BOOTTIME) + + def run( cfg: Config, lcd, @@ -63,7 +69,7 @@ def run( read_memory=meminfo.read_memory, top_apps=meminfo.top_apps, now=datetime.now, - monotonic=time.monotonic, + monotonic=_boottime, reconnect_delay: float = RECONNECT_DELAY, full_refresh_interval: float = FULL_REFRESH_INTERVAL, ) -> None: diff --git a/tests/test_main.py b/tests/test_main.py index be70565..c412d34 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,5 +1,6 @@ import errno import functools +import inspect import logging import os import signal @@ -285,6 +286,15 @@ def test_dauer_lesbar(seconds, text): assert main_module._duration(seconds) == text +def test_standarduhr_zaehlt_standby_mit(monkeypatch): + # CLOCK_MONOTONIC steht im Standby still: ein über Nacht abgezogenes Display meldete sonst am Morgen nur + # die Wachzeit als Ausfalldauer. CLOCK_BOOTTIME ist ebenso monoton und nicht verstellbar. + clocks = [] + monkeypatch.setattr(time, "clock_gettime", lambda clock: clocks.append(clock) or 42.0) + assert inspect.signature(run).parameters["monotonic"].default() == 42.0 + assert clocks == [time.CLOCK_BOOTTIME] + + def log_lines(caplog): return [(r.levelname, r.getMessage()) for r in caplog.records if r.name == "ramscreen"]