Skip to content

Commit

Permalink
Ensure Forecast.Solar returns an iso formatted timestamp (#52669)
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck authored Jul 8, 2021
1 parent 5ff7c77 commit 62c7e54
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion homeassistant/components/forecast_solar/sensor.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -64,5 +66,7 @@ def __init__(
@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
4 changes: 2 additions & 2 deletions tests/components/forecast_solar/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
)
Expand Down

0 comments on commit 62c7e54

Please sign in to comment.