forked from home-assistant/core
Ensure Forecast.Solar returns an iso formatted timestamp (#52669)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
"""Support for the Forecast.Solar sensor service."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_IDENTIFIERS, ATTR_MANUFACTURER, ATTR_NAME
|
||||
@@ -64,5 +66,7 @@ class ForecastSolarSensorEntity(CoordinatorEntity, SensorEntity):
|
||||
@property
|
||||
def state(self) -> StateType:
|
||||
"""Return the state of the sensor."""
|
||||
state: StateType = getattr(self.coordinator.data, self._sensor.key)
|
||||
state: StateType | datetime = getattr(self.coordinator.data, self._sensor.key)
|
||||
if isinstance(state, datetime):
|
||||
return state.isoformat()
|
||||
return state
|
||||
|
@@ -70,7 +70,7 @@ async def test_sensors(
|
||||
assert entry
|
||||
assert state
|
||||
assert entry.unique_id == f"{entry_id}_power_highest_peak_time_today"
|
||||
assert state.state == "2021-06-27 13:00:00+00:00"
|
||||
assert state.state == "2021-06-27T13:00:00+00:00"
|
||||
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Highest Power Peak Time - Today"
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TIMESTAMP
|
||||
@@ -82,7 +82,7 @@ async def test_sensors(
|
||||
assert entry
|
||||
assert state
|
||||
assert entry.unique_id == f"{entry_id}_power_highest_peak_time_tomorrow"
|
||||
assert state.state == "2021-06-27 14:00:00+00:00"
|
||||
assert state.state == "2021-06-27T14:00:00+00:00"
|
||||
assert (
|
||||
state.attributes.get(ATTR_FRIENDLY_NAME) == "Highest Power Peak Time - Tomorrow"
|
||||
)
|
||||
|
Reference in New Issue
Block a user