waterleaksensor: use parent's Time for alert timestamp (#1614)
Some checks failed
Stale / stale (push) Has been cancelled
CI / Perform linting checks (3.13) (push) Has been cancelled
CodeQL checks / Analyze (python) (push) Has been cancelled
CI / Python 3.11 on macos-latest (push) Has been cancelled
CI / Python 3.12 on macos-latest (push) Has been cancelled
CI / Python 3.13 on macos-latest (push) Has been cancelled
CI / Python 3.11 on ubuntu-latest (push) Has been cancelled
CI / Python 3.12 on ubuntu-latest (push) Has been cancelled
CI / Python 3.13 on ubuntu-latest (push) Has been cancelled
CI / Python 3.11 on windows-latest (push) Has been cancelled
CI / Python 3.12 on windows-latest (push) Has been cancelled
CI / Python 3.13 on windows-latest (push) Has been cancelled

We do not, by design, add Time module for hub's children.
This has a side-effect that we need to fallback to the parent's time
module to allow presenting the correct timestamp for the last alert.
This commit is contained in:
Teemu R.
2025-11-30 20:07:54 +01:00
committed by GitHub
parent 347bf9a419
commit a87926f9d7
2 changed files with 28 additions and 3 deletions

View File

@@ -4,8 +4,10 @@ from __future__ import annotations
from datetime import datetime
from enum import Enum
from typing import TYPE_CHECKING
from ...feature import Feature
from ...interfaces.time import Time
from ..smartmodule import Module, SmartModule
@@ -76,6 +78,17 @@ class WaterleakSensor(SmartModule):
"""Return true if alarm is active."""
return self._device.sys_info["in_alarm"]
@property
def _time_module(self) -> Time:
"""Return time module from the parent for timestamp calculation."""
parent = self._device.parent
if TYPE_CHECKING:
from ..smartdevice import SmartDevice
assert isinstance(parent, SmartDevice)
return parent.modules[Module.Time]
@property
def alert_timestamp(self) -> datetime | None:
"""Return timestamp of the last leak trigger."""
@@ -84,5 +97,5 @@ class WaterleakSensor(SmartModule):
return None
ts = self._device.sys_info["trigger_timestamp"]
tz = self._device.modules[Module.Time].timezone
tz = self._time_module.timezone
return datetime.fromtimestamp(ts, tz=tz)