Change hebrew date at sunset (#17449)

* Change date at sunset

* Fix tests to actually run and add fix to component

* Make tests pass

* Use get_astral_event_next instead of get_astral_event_date

* Revert to using get_astral_event_date

* Make tox happy: reset state on tearDown
This commit is contained in:
Tsvi Mostovicz authored and Paulus Schoutsen committed 2018-10-30 15:21:58 +01:00
1 parent f0693f6f91
commit 87bd2a32e4
2 files changed
+94 -10

No files matched your search

@@ -13,6 +13,7 @@ from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.sun import get_astral_event_date
import homeassistant.util.dt as dt_util
REQUIREMENTS = ['hdate==0.6.5']
@@ -107,8 +108,18 @@ class JewishCalSensor(Entity):
"""Update the state of the sensor."""
import hdate
today = dt_util.now().date()
now = dt_util.as_local(dt_util.now())
_LOGGER.debug("Now: %s Timezone = %s", now, now.tzinfo)
today = now.date()
upcoming_saturday = today + timedelta((12 - today.weekday()) % 7)
sunset = dt_util.as_local(get_astral_event_date(
self.hass, 'sunset', today))
_LOGGER.debug("Now: %s Sunset: %s", now, sunset)
if now > sunset:
today += timedelta(1)
date = hdate.HDate(
today, diaspora=self.diaspora, hebrew=self._hebrew)