Fix Islamic prayer sensor timestamp format (#35243)

This commit is contained in:
Rami Mosleh 2020-05-06 16:17:40 +03:00 committed by GitHub
parent 1b3f9254bc
commit 35d8890f4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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")
now = dt_util.as_local(dt_util.now())
now = dt_util.utcnow()
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)
_LOGGER.debug(
"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.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity
import homeassistant.util.dt as dt_util
from .const import DATA_UPDATED, DOMAIN, PRAYER_TIMES_ICON, SENSOR_TYPES
@ -48,7 +49,11 @@ class IslamicPrayerTimeSensor(Entity):
@property
def state(self):
"""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
def should_poll(self):

View file

@ -42,4 +42,4 @@ NEW_PRAYER_TIMES_TIMESTAMPS = {
"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

@ -1,5 +1,6 @@
"""The tests for the Islamic prayer times sensor platform."""
from homeassistant.components import islamic_prayer_times
import homeassistant.util.dt as dt_util
from . import NOW, PRAYER_TIMES, PRAYER_TIMES_TIMESTAMPS
@ -25,5 +26,5 @@ async def test_islamic_prayer_times_sensors(hass):
hass.states.get(
f"sensor.{prayer}_{islamic_prayer_times.const.SENSOR_TYPES[prayer]}"
).state
== PRAYER_TIMES_TIMESTAMPS[prayer].isoformat()
== PRAYER_TIMES_TIMESTAMPS[prayer].astimezone(dt_util.UTC).isoformat()
)