Fix Islamic prayer sensor timestamp format (#35243)

This commit is contained in:
Rami Mosleh 2020-05-06 16:17:40 +03:00 committed by Paulus Schoutsen
parent 00282dab72
commit 97d66c4eb2
4 changed files with 11 additions and 5 deletions

View File

@ -125,11 +125,11 @@ class IslamicPrayerClient:
""" """
_LOGGER.debug("Scheduling next update for Islamic prayer times") _LOGGER.debug("Scheduling next update for Islamic prayer times")
now = dt_util.as_local(dt_util.now()) now = dt_util.utcnow()
midnight_dt = self.prayer_times_info["Midnight"] midnight_dt = self.prayer_times_info["Midnight"]
if now > dt_util.as_local(midnight_dt): if now > dt_util.as_utc(midnight_dt):
next_update_at = midnight_dt + timedelta(days=1, minutes=1) next_update_at = midnight_dt + timedelta(days=1, minutes=1)
_LOGGER.debug( _LOGGER.debug(
"Midnight is after day the changes so schedule update for after Midnight the next day" "Midnight is after day the changes so schedule update for after Midnight the next day"

View File

@ -4,6 +4,7 @@ import logging
from homeassistant.const import DEVICE_CLASS_TIMESTAMP from homeassistant.const import DEVICE_CLASS_TIMESTAMP
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
import homeassistant.util.dt as dt_util
from .const import DATA_UPDATED, DOMAIN, PRAYER_TIMES_ICON, SENSOR_TYPES from .const import DATA_UPDATED, DOMAIN, PRAYER_TIMES_ICON, SENSOR_TYPES
@ -48,7 +49,11 @@ class IslamicPrayerTimeSensor(Entity):
@property @property
def state(self): def state(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.client.prayer_times_info.get(self.sensor_type).isoformat() return (
self.client.prayer_times_info.get(self.sensor_type)
.astimezone(dt_util.UTC)
.isoformat()
)
@property @property
def should_poll(self): def should_poll(self):

View File

@ -42,4 +42,4 @@ NEW_PRAYER_TIMES_TIMESTAMPS = {
"Midnight": datetime(2020, 1, 1, 00, 43, 0), "Midnight": datetime(2020, 1, 1, 00, 43, 0),
} }
NOW = datetime(2020, 1, 1, 00, 00, 0) NOW = datetime(2020, 1, 1, 00, 00, 0).astimezone()

View File

@ -2,6 +2,7 @@
from unittest.mock import patch from unittest.mock import patch
from homeassistant.components import islamic_prayer_times from homeassistant.components import islamic_prayer_times
import homeassistant.util.dt as dt_util
from . import NOW, PRAYER_TIMES, PRAYER_TIMES_TIMESTAMPS from . import NOW, PRAYER_TIMES, PRAYER_TIMES_TIMESTAMPS
@ -26,5 +27,5 @@ async def test_islamic_prayer_times_sensors(hass):
hass.states.get( hass.states.get(
f"sensor.{prayer}_{islamic_prayer_times.const.SENSOR_TYPES[prayer]}" f"sensor.{prayer}_{islamic_prayer_times.const.SENSOR_TYPES[prayer]}"
).state ).state
== PRAYER_TIMES_TIMESTAMPS[prayer].isoformat() == PRAYER_TIMES_TIMESTAMPS[prayer].astimezone(dt_util.UTC).isoformat()
) )