mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Opower: Fix unavailable "start date" and "end date" sensors (#138694)
avoid passing string into date device class
This commit is contained in:
parent
e5c0183e0f
commit
14375e76a3
@ -4,6 +4,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 date
|
||||||
|
|
||||||
from opower import Forecast, MeterType, UnitOfMeasure
|
from opower import Forecast, MeterType, UnitOfMeasure
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ from .coordinator import OpowerConfigEntry, OpowerCoordinator
|
|||||||
class OpowerEntityDescription(SensorEntityDescription):
|
class OpowerEntityDescription(SensorEntityDescription):
|
||||||
"""Class describing Opower sensors entities."""
|
"""Class describing Opower sensors entities."""
|
||||||
|
|
||||||
value_fn: Callable[[Forecast], str | float]
|
value_fn: Callable[[Forecast], str | float | date]
|
||||||
|
|
||||||
|
|
||||||
# suggested_display_precision=0 for all sensors since
|
# suggested_display_precision=0 for all sensors since
|
||||||
@ -96,7 +97,7 @@ ELEC_SENSORS: tuple[OpowerEntityDescription, ...] = (
|
|||||||
device_class=SensorDeviceClass.DATE,
|
device_class=SensorDeviceClass.DATE,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
value_fn=lambda data: str(data.start_date),
|
value_fn=lambda data: data.start_date,
|
||||||
),
|
),
|
||||||
OpowerEntityDescription(
|
OpowerEntityDescription(
|
||||||
key="elec_end_date",
|
key="elec_end_date",
|
||||||
@ -104,7 +105,7 @@ ELEC_SENSORS: tuple[OpowerEntityDescription, ...] = (
|
|||||||
device_class=SensorDeviceClass.DATE,
|
device_class=SensorDeviceClass.DATE,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
value_fn=lambda data: str(data.end_date),
|
value_fn=lambda data: data.end_date,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
GAS_SENSORS: tuple[OpowerEntityDescription, ...] = (
|
GAS_SENSORS: tuple[OpowerEntityDescription, ...] = (
|
||||||
@ -168,7 +169,7 @@ GAS_SENSORS: tuple[OpowerEntityDescription, ...] = (
|
|||||||
device_class=SensorDeviceClass.DATE,
|
device_class=SensorDeviceClass.DATE,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
value_fn=lambda data: str(data.start_date),
|
value_fn=lambda data: data.start_date,
|
||||||
),
|
),
|
||||||
OpowerEntityDescription(
|
OpowerEntityDescription(
|
||||||
key="gas_end_date",
|
key="gas_end_date",
|
||||||
@ -176,7 +177,7 @@ GAS_SENSORS: tuple[OpowerEntityDescription, ...] = (
|
|||||||
device_class=SensorDeviceClass.DATE,
|
device_class=SensorDeviceClass.DATE,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
value_fn=lambda data: str(data.end_date),
|
value_fn=lambda data: data.end_date,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -246,7 +247,7 @@ class OpowerSensor(CoordinatorEntity[OpowerCoordinator], SensorEntity):
|
|||||||
self.utility_account_id = utility_account_id
|
self.utility_account_id = utility_account_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> StateType:
|
def native_value(self) -> StateType | date:
|
||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
if self.coordinator.data is not None:
|
if self.coordinator.data is not None:
|
||||||
return self.entity_description.value_fn(
|
return self.entity_description.value_fn(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user