Jewish Calendar: Do not convert datetimes to UTC (#61222)

This commit is contained in:
Paulus Schoutsen 2021-12-07 23:38:52 -08:00 committed by GitHub
parent c8fbf4c339
commit 7b3a7ee2d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,7 @@
"""Platform to retrieve Jewish calendar information for Home Assistant."""
from __future__ import annotations
from datetime import date as Date, datetime
from datetime import date as Date
import logging
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.helpers.entity_platform import AddEntitiesCallback
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
from . import DOMAIN
@ -166,14 +166,8 @@ class JewishCalendarSensor(SensorEntity):
self._candle_lighting_offset = data["candle_lighting_offset"]
self._havdalah_offset = data["havdalah_offset"]
self._diaspora = data["diaspora"]
self._state: datetime | None = None
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:
"""Update the state of the sensor."""
now = dt_util.now()
@ -208,8 +202,12 @@ class JewishCalendarSensor(SensorEntity):
if today_times.havdalah and now > today_times.havdalah:
after_tzais_date = daytime_date.next_day
self._state = self.get_state(daytime_date, after_shkia_date, after_tzais_date)
_LOGGER.debug("New value for %s: %s", self.entity_description.key, self._state)
self._attr_native_value = self.get_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:
"""Create a Zmanim object."""
@ -259,13 +257,6 @@ class JewishCalendarTimeSensor(JewishCalendarSensor):
_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(
self, daytime_date: HDate, after_shkia_date: HDate, after_tzais_date: HDate
) -> Any | None: