mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 14:57:09 +00:00
Ensure Forecast.Solar returns an iso formatted timestamp (#52669)
This commit is contained in:
parent
5ff7c7708d
commit
62c7e5408b
@ -1,6 +1,8 @@
|
|||||||
"""Support for the Forecast.Solar sensor service."""
|
"""Support for the Forecast.Solar sensor service."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorEntity
|
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_IDENTIFIERS, ATTR_MANUFACTURER, ATTR_NAME
|
from homeassistant.const import ATTR_IDENTIFIERS, ATTR_MANUFACTURER, ATTR_NAME
|
||||||
@ -64,5 +66,7 @@ class ForecastSolarSensorEntity(CoordinatorEntity, SensorEntity):
|
|||||||
@property
|
@property
|
||||||
def state(self) -> StateType:
|
def state(self) -> StateType:
|
||||||
"""Return the state of the sensor."""
|
"""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
|
return state
|
||||||
|
@ -70,7 +70,7 @@ async def test_sensors(
|
|||||||
assert entry
|
assert entry
|
||||||
assert state
|
assert state
|
||||||
assert entry.unique_id == f"{entry_id}_power_highest_peak_time_today"
|
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_FRIENDLY_NAME) == "Highest Power Peak Time - Today"
|
||||||
assert state.attributes.get(ATTR_STATE_CLASS) is None
|
assert state.attributes.get(ATTR_STATE_CLASS) is None
|
||||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TIMESTAMP
|
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TIMESTAMP
|
||||||
@ -82,7 +82,7 @@ async def test_sensors(
|
|||||||
assert entry
|
assert entry
|
||||||
assert state
|
assert state
|
||||||
assert entry.unique_id == f"{entry_id}_power_highest_peak_time_tomorrow"
|
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 (
|
assert (
|
||||||
state.attributes.get(ATTR_FRIENDLY_NAME) == "Highest Power Peak Time - Tomorrow"
|
state.attributes.get(ATTR_FRIENDLY_NAME) == "Highest Power Peak Time - Tomorrow"
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user