mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Fix Islamic prayer sensor timestamp format (#35243)
This commit is contained in:
parent
1b3f9254bc
commit
35d8890f4e
@ -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"
|
||||||
|
@ -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):
|
||||||
|
@ -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()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""The tests for the Islamic prayer times sensor platform."""
|
"""The tests for the Islamic prayer times sensor platform."""
|
||||||
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
|
||||||
|
|
||||||
@ -25,5 +26,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()
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user