mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +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 dataclasses import dataclass
|
||||
from datetime import date
|
||||
from typing import Callable
|
||||
|
||||
from vehicle import Vehicle
|
||||
@ -15,7 +16,6 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
@ -28,7 +28,7 @@ from .const import CONF_LICENSE_PLATE, DOMAIN, ENTRY_TYPE_SERVICE
|
||||
class RDWSensorEntityDescriptionMixin:
|
||||
"""Mixin for required keys."""
|
||||
|
||||
value_fn: Callable[[Vehicle], str | float | None]
|
||||
value_fn: Callable[[Vehicle], date | str | float | None]
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -43,13 +43,13 @@ SENSORS: tuple[RDWSensorEntityDescription, ...] = (
|
||||
key="apk_expiration",
|
||||
name="APK Expiration",
|
||||
device_class=DEVICE_CLASS_DATE,
|
||||
value_fn=lambda vehicle: vehicle.apk_expiration.isoformat(),
|
||||
value_fn=lambda vehicle: vehicle.apk_expiration,
|
||||
),
|
||||
RDWSensorEntityDescription(
|
||||
key="ascription_date",
|
||||
name="Ascription 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
|
||||
def native_value(self) -> StateType:
|
||||
def native_value(self) -> date | str | float | None:
|
||||
"""Return the state of the sensor."""
|
||||
return self.entity_description.value_fn(self.coordinator.data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user