Ensure Jewish Calendar returns an iso formatted timestamp (#52722)
parent
2b3148296c
commit
d4d791e0a1
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue