Use native date value in Renault sensors (#59900)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-11-18 16:15:54 +01:00 committed by GitHub
parent 7cc7bbb76d
commit 28ff1b9d9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,6 +3,7 @@ from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass
from datetime import datetime
from typing import TYPE_CHECKING, cast
from renault_api.kamereon.enums import ChargeState, PlugState
@ -67,7 +68,7 @@ class RenaultSensorEntityDescription(
icon_lambda: Callable[[RenaultSensor[T]], str] | None = None
condition_lambda: Callable[[RenaultVehicleProxy], bool] | None = None
requires_fuel: bool = False
value_lambda: Callable[[RenaultSensor[T]], StateType] | None = None
value_lambda: Callable[[RenaultSensor[T]], StateType | datetime] | None = None
async def async_setup_entry(
@ -106,7 +107,7 @@ class RenaultSensor(RenaultDataEntity[T], SensorEntity):
return self.entity_description.icon_lambda(self)
@property
def native_value(self) -> StateType:
def native_value(self) -> StateType | datetime:
"""Return the state of this entity."""
if self.data is None:
return None
@ -153,12 +154,12 @@ def _get_rounded_value(entity: RenaultSensor[T]) -> float:
return round(cast(float, entity.data))
def _get_utc_value(entity: RenaultSensor[T]) -> str:
def _get_utc_value(entity: RenaultSensor[T]) -> datetime:
"""Return the UTC value of this entity."""
original_dt = parse_datetime(cast(str, entity.data))
if TYPE_CHECKING:
assert original_dt is not None
return as_utc(original_dt).isoformat()
return as_utc(original_dt)
SENSOR_TYPES: tuple[RenaultSensorEntityDescription, ...] = (