diff --git a/homeassistant/components/jewish_calendar/sensor.py b/homeassistant/components/jewish_calendar/sensor.py index 0dfc61970ef..17a61c932a3 100644 --- a/homeassistant/components/jewish_calendar/sensor.py +++ b/homeassistant/components/jewish_calendar/sensor.py @@ -1,4 +1,5 @@ """Platform to retrieve Jewish calendar information for Home Assistant.""" +from datetime import datetime import logging import hdate @@ -51,6 +52,8 @@ class JewishCalendarSensor(SensorEntity): @property def state(self): """Return the state of the sensor.""" + if isinstance(self._state, datetime): + return self._state.isoformat() return self._state async def async_update(self): @@ -133,7 +136,9 @@ class JewishCalendarTimeSensor(JewishCalendarSensor): @property def state(self): """Return the state of the sensor.""" - return dt_util.as_utc(self._state) if self._state is not None else None + if self._state is None: + return None + return dt_util.as_utc(self._state).isoformat() @property def extra_state_attributes(self): diff --git a/tests/components/jewish_calendar/test_sensor.py b/tests/components/jewish_calendar/test_sensor.py index 970e31c7985..e9471d5d144 100644 --- a/tests/components/jewish_calendar/test_sensor.py +++ b/tests/components/jewish_calendar/test_sensor.py @@ -188,13 +188,13 @@ async def test_jewish_calendar_sensor( await hass.async_block_till_done() result = ( - dt_util.as_utc(result.replace(tzinfo=time_zone)) + dt_util.as_utc(result.replace(tzinfo=time_zone)).isoformat() if isinstance(result, dt) else result ) sensor_object = hass.states.get(f"sensor.test_{sensor}") - assert sensor_object.state == str(result) + assert sensor_object.state == result if sensor == "holiday": assert sensor_object.attributes.get("id") == "rosh_hashana_i" @@ -544,7 +544,7 @@ async def test_shabbat_times_sensor( sensor_type = sensor_type.replace(f"{language}_", "") result_value = ( - dt_util.as_utc(result_value) + dt_util.as_utc(result_value).isoformat() if isinstance(result_value, dt) else result_value )