mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Use native datetime value in RDW sensors (#59914)
This commit is contained in:
parent
5593dd4006
commit
8a0c5aa50b
@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from datetime import date
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
from vehicle import Vehicle
|
from vehicle import Vehicle
|
||||||
@ -15,7 +16,6 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import (
|
||||||
CoordinatorEntity,
|
CoordinatorEntity,
|
||||||
DataUpdateCoordinator,
|
DataUpdateCoordinator,
|
||||||
@ -28,7 +28,7 @@ from .const import CONF_LICENSE_PLATE, DOMAIN, ENTRY_TYPE_SERVICE
|
|||||||
class RDWSensorEntityDescriptionMixin:
|
class RDWSensorEntityDescriptionMixin:
|
||||||
"""Mixin for required keys."""
|
"""Mixin for required keys."""
|
||||||
|
|
||||||
value_fn: Callable[[Vehicle], str | float | None]
|
value_fn: Callable[[Vehicle], date | str | float | None]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -43,13 +43,13 @@ SENSORS: tuple[RDWSensorEntityDescription, ...] = (
|
|||||||
key="apk_expiration",
|
key="apk_expiration",
|
||||||
name="APK Expiration",
|
name="APK Expiration",
|
||||||
device_class=DEVICE_CLASS_DATE,
|
device_class=DEVICE_CLASS_DATE,
|
||||||
value_fn=lambda vehicle: vehicle.apk_expiration.isoformat(),
|
value_fn=lambda vehicle: vehicle.apk_expiration,
|
||||||
),
|
),
|
||||||
RDWSensorEntityDescription(
|
RDWSensorEntityDescription(
|
||||||
key="ascription_date",
|
key="ascription_date",
|
||||||
name="Ascription Date",
|
name="Ascription Date",
|
||||||
device_class=DEVICE_CLASS_DATE,
|
device_class=DEVICE_CLASS_DATE,
|
||||||
value_fn=lambda vehicle: vehicle.ascription_date.isoformat(),
|
value_fn=lambda vehicle: vehicle.ascription_date,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -98,6 +98,6 @@ class RDWSensorEntity(CoordinatorEntity, SensorEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> StateType:
|
def native_value(self) -> date | str | float | None:
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self.entity_description.value_fn(self.coordinator.data)
|
return self.entity_description.value_fn(self.coordinator.data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user