mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use native date value in Renault sensors (#59900)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
7cc7bbb76d
commit
28ff1b9d9e
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from datetime import datetime
|
||||||
from typing import TYPE_CHECKING, cast
|
from typing import TYPE_CHECKING, cast
|
||||||
|
|
||||||
from renault_api.kamereon.enums import ChargeState, PlugState
|
from renault_api.kamereon.enums import ChargeState, PlugState
|
||||||
@ -67,7 +68,7 @@ class RenaultSensorEntityDescription(
|
|||||||
icon_lambda: Callable[[RenaultSensor[T]], str] | None = None
|
icon_lambda: Callable[[RenaultSensor[T]], str] | None = None
|
||||||
condition_lambda: Callable[[RenaultVehicleProxy], bool] | None = None
|
condition_lambda: Callable[[RenaultVehicleProxy], bool] | None = None
|
||||||
requires_fuel: bool = False
|
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(
|
async def async_setup_entry(
|
||||||
@ -106,7 +107,7 @@ class RenaultSensor(RenaultDataEntity[T], SensorEntity):
|
|||||||
return self.entity_description.icon_lambda(self)
|
return self.entity_description.icon_lambda(self)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> StateType:
|
def native_value(self) -> StateType | datetime:
|
||||||
"""Return the state of this entity."""
|
"""Return the state of this entity."""
|
||||||
if self.data is None:
|
if self.data is None:
|
||||||
return None
|
return None
|
||||||
@ -153,12 +154,12 @@ def _get_rounded_value(entity: RenaultSensor[T]) -> float:
|
|||||||
return round(cast(float, entity.data))
|
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."""
|
"""Return the UTC value of this entity."""
|
||||||
original_dt = parse_datetime(cast(str, entity.data))
|
original_dt = parse_datetime(cast(str, entity.data))
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
assert original_dt is not None
|
assert original_dt is not None
|
||||||
return as_utc(original_dt).isoformat()
|
return as_utc(original_dt)
|
||||||
|
|
||||||
|
|
||||||
SENSOR_TYPES: tuple[RenaultSensorEntityDescription, ...] = (
|
SENSOR_TYPES: tuple[RenaultSensorEntityDescription, ...] = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user