Skip to content

Commit

Permalink
Fix Islamic prayer sensor timestamp format (home-assistant#35243)
Browse files Browse the repository at this point in the history
  • Loading branch information
engrbm87 authored May 6, 2020
1 parent 1b3f925 commit 35d8890
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/islamic_prayer_times/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ async def async_schedule_future_update(self):
"""
_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"
Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/islamic_prayer_times/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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

Expand Down Expand Up @@ -48,7 +49,11 @@ def icon(self):
@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):
Expand Down
2 changes: 1 addition & 1 deletion tests/components/islamic_prayer_times/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
"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()
3 changes: 2 additions & 1 deletion tests/components/islamic_prayer_times/test_sensor.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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()
)

0 comments on commit 35d8890

Please sign in to comment.