Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Islamic prayer sensor timestamp format #35243

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b41c566
Add Islamic Prayer Times config_flow
engrbm87 Nov 13, 2019
211b60a
Add Islamic Prayer Times config_flow
engrbm87 Nov 13, 2019
a98ee58
Merge branch 'islamic-prayer-config-flow' of https://github.com/engrb…
engrbm87 Feb 5, 2020
4fd2cea
handle options update and fix tests
engrbm87 Feb 7, 2020
87460d0
fix sensor update handling
engrbm87 Feb 7, 2020
8336df4
Merge branch 'dev' of https://github.com/home-assistant/home-assistan…
engrbm87 Feb 11, 2020
0e544e5
fix pylint
engrbm87 Feb 13, 2020
d412176
fix scheduled update and add test
engrbm87 Feb 15, 2020
8f9d01b
Merge branch 'dev' of https://github.com/home-assistant/home-assistan…
engrbm87 Mar 16, 2020
2a61a7d
update test_init
engrbm87 Mar 18, 2020
d5e6dfb
update flow options to show drop list
engrbm87 Mar 19, 2020
da7f34c
Merge branch 'dev' of https://github.com/home-assistant/home-assistan…
engrbm87 Apr 1, 2020
33e757e
Merge branch 'dev' into islamic-prayer-config-flow
engrbm87 Apr 10, 2020
25547a3
Merge branch 'dev' of https://github.com/home-assistant/home-assistan…
engrbm87 Apr 10, 2020
ee453f6
clean up code
engrbm87 Apr 13, 2020
3c75168
Merge branch 'islamic-prayer-config-flow' of https://github.com/engrb…
engrbm87 Apr 13, 2020
92ca24c
async scheduling and revert state to timestamp
engrbm87 Apr 13, 2020
d2b9782
fix update retry method
engrbm87 Apr 15, 2020
a1c57a9
Merge branch 'dev' of https://github.com/home-assistant/home-assistan…
engrbm87 Apr 20, 2020
d8d3df0
update strings
engrbm87 Apr 20, 2020
f3dc053
keep title as root key
engrbm87 Apr 20, 2020
60e56ca
Merge branch 'dev' of https://github.com/home-assistant/home-assistan…
engrbm87 Apr 27, 2020
300220d
fix sensor naming and calculation_method key
engrbm87 Apr 27, 2020
41dc6f0
fix strings
engrbm87 Apr 27, 2020
3e2bfbb
Merge branch 'dev' of https://github.com/home-assistant/home-assistan…
engrbm87 Apr 29, 2020
3d6c174
Merge branch 'dev' of https://github.com/home-assistant/home-assistan…
engrbm87 May 5, 2020
aa4fd4d
add timezone to sensor timestamp
engrbm87 May 5, 2020
6608b81
fix timezone
engrbm87 May 6, 2020
7cd9a52
Merge branch 'dev' of https://github.com/home-assistant/home-assistan…
engrbm87 May 6, 2020
29310c7
revert changes to en.json
engrbm87 May 6, 2020
43a8a74
change sensor time to utc time
engrbm87 May 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/components/islamic_prayer_times/__init__.py
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
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
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
@@ -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()
)