mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Jewish Calendar: Do not convert datetimes to UTC (#61222)
This commit is contained in:
parent
c8fbf4c339
commit
7b3a7ee2d1
@ -1,7 +1,7 @@
|
|||||||
"""Platform to retrieve Jewish calendar information for Home Assistant."""
|
"""Platform to retrieve Jewish calendar information for Home Assistant."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import date as Date, datetime
|
from datetime import date as Date
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ from homeassistant.const import DEVICE_CLASS_TIMESTAMP, SUN_EVENT_SUNSET
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.sun import get_astral_event_date
|
from homeassistant.helpers.sun import get_astral_event_date
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
from . import DOMAIN
|
from . import DOMAIN
|
||||||
@ -166,14 +166,8 @@ class JewishCalendarSensor(SensorEntity):
|
|||||||
self._candle_lighting_offset = data["candle_lighting_offset"]
|
self._candle_lighting_offset = data["candle_lighting_offset"]
|
||||||
self._havdalah_offset = data["havdalah_offset"]
|
self._havdalah_offset = data["havdalah_offset"]
|
||||||
self._diaspora = data["diaspora"]
|
self._diaspora = data["diaspora"]
|
||||||
self._state: datetime | None = None
|
|
||||||
self._holiday_attrs: dict[str, str] = {}
|
self._holiday_attrs: dict[str, str] = {}
|
||||||
|
|
||||||
@property
|
|
||||||
def native_value(self) -> datetime | StateType:
|
|
||||||
"""Return the state of the sensor."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Update the state of the sensor."""
|
"""Update the state of the sensor."""
|
||||||
now = dt_util.now()
|
now = dt_util.now()
|
||||||
@ -208,8 +202,12 @@ class JewishCalendarSensor(SensorEntity):
|
|||||||
if today_times.havdalah and now > today_times.havdalah:
|
if today_times.havdalah and now > today_times.havdalah:
|
||||||
after_tzais_date = daytime_date.next_day
|
after_tzais_date = daytime_date.next_day
|
||||||
|
|
||||||
self._state = self.get_state(daytime_date, after_shkia_date, after_tzais_date)
|
self._attr_native_value = self.get_state(
|
||||||
_LOGGER.debug("New value for %s: %s", self.entity_description.key, self._state)
|
daytime_date, after_shkia_date, after_tzais_date
|
||||||
|
)
|
||||||
|
_LOGGER.debug(
|
||||||
|
"New value for %s: %s", self.entity_description.key, self._attr_native_value
|
||||||
|
)
|
||||||
|
|
||||||
def make_zmanim(self, date: Date) -> Zmanim:
|
def make_zmanim(self, date: Date) -> Zmanim:
|
||||||
"""Create a Zmanim object."""
|
"""Create a Zmanim object."""
|
||||||
@ -259,13 +257,6 @@ class JewishCalendarTimeSensor(JewishCalendarSensor):
|
|||||||
|
|
||||||
_attr_device_class = DEVICE_CLASS_TIMESTAMP
|
_attr_device_class = DEVICE_CLASS_TIMESTAMP
|
||||||
|
|
||||||
@property
|
|
||||||
def native_value(self) -> datetime | None:
|
|
||||||
"""Return the state of the sensor."""
|
|
||||||
if self._state is None:
|
|
||||||
return None
|
|
||||||
return dt_util.as_utc(self._state)
|
|
||||||
|
|
||||||
def get_state(
|
def get_state(
|
||||||
self, daytime_date: HDate, after_shkia_date: HDate, after_tzais_date: HDate
|
self, daytime_date: HDate, after_shkia_date: HDate, after_tzais_date: HDate
|
||||||
) -> Any | None:
|
) -> Any | None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user