Add KNX source address to Sensor and BinarySensor (#48857)
* Add source address to Sensor and BinarySensor * Fix typing * Review: Always use UTC time in state attributes * Review: Add missing UTC conversion in sensor
This commit is contained in:
parent
676af205e4
commit
21744790d3
3 changed files with 28 additions and 5 deletions
|
@ -9,8 +9,9 @@ from homeassistant.components.binary_sensor import DEVICE_CLASSES, BinarySensorE
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util import dt
|
||||
|
||||
from .const import ATTR_COUNTER, DOMAIN
|
||||
from .const import ATTR_COUNTER, ATTR_LAST_KNX_UPDATE, ATTR_SOURCE, DOMAIN
|
||||
from .knx_entity import KnxEntity
|
||||
|
||||
|
||||
|
@ -51,9 +52,16 @@ class KNXBinarySensor(KnxEntity, BinarySensorEntity):
|
|||
@property
|
||||
def extra_state_attributes(self) -> dict[str, Any] | None:
|
||||
"""Return device specific state attributes."""
|
||||
attr: dict[str, Any] = {}
|
||||
|
||||
if self._device.counter is not None:
|
||||
return {ATTR_COUNTER: self._device.counter}
|
||||
return None
|
||||
attr[ATTR_COUNTER] = self._device.counter
|
||||
if self._device.last_telegram is not None:
|
||||
attr[ATTR_SOURCE] = str(self._device.last_telegram.source_address)
|
||||
attr[ATTR_LAST_KNX_UPDATE] = str(
|
||||
dt.as_utc(self._device.last_telegram.timestamp)
|
||||
)
|
||||
return attr
|
||||
|
||||
@property
|
||||
def force_update(self) -> bool:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue