From f99701f41a59a1316877c9c9a90b53c40ddf971e Mon Sep 17 00:00:00 2001 From: Tsvi Mostovicz Date: Wed, 7 Nov 2018 14:30:41 +0200 Subject: [PATCH] Upgrade hdate to 0.7.5 (#18296) In 0.7.x the API to HDate was cleaned up so as to move logic from homeassistant to the HDate external library. This commit removes all the superfluous code, updates the required tests and changes the requirement from version 0.6.5 to 0.7.5 --- .../components/sensor/jewish_calendar.py | 26 ++++--------------- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- .../components/sensor/test_jewish_calendar.py | 10 +++---- 4 files changed, 12 insertions(+), 28 deletions(-) diff --git a/homeassistant/components/sensor/jewish_calendar.py b/homeassistant/components/sensor/jewish_calendar.py index 2c917ba0f3b..8058a411266 100644 --- a/homeassistant/components/sensor/jewish_calendar.py +++ b/homeassistant/components/sensor/jewish_calendar.py @@ -17,7 +17,7 @@ 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'] +REQUIREMENTS = ['hdate==0.7.5'] _LOGGER = logging.getLogger(__name__) @@ -113,7 +113,6 @@ class JewishCalSensor(Entity): _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, SUN_EVENT_SUNSET, today)) @@ -124,30 +123,15 @@ class JewishCalSensor(Entity): date = hdate.HDate( today, diaspora=self.diaspora, hebrew=self._hebrew) - upcoming_shabbat = hdate.HDate( - upcoming_saturday, diaspora=self.diaspora, hebrew=self._hebrew) if self.type == 'date': - self._state = hdate.date.get_hebrew_date( - date.h_day, date.h_month, date.h_year, hebrew=self._hebrew) + self._state = date.hebrew_date elif self.type == 'weekly_portion': - self._state = hdate.date.get_parashe( - upcoming_shabbat.get_reading(self.diaspora), - hebrew=self._hebrew) + self._state = date.parasha elif self.type == 'holiday_name': - try: - description = next( - x.description[self._hebrew] - for x in hdate.htables.HOLIDAYS - if x.index == date.get_holyday()) - if not self._hebrew: - self._state = description - else: - self._state = description.long - except StopIteration: - self._state = None + self._state = date.holiday_description elif self.type == 'holyness': - self._state = hdate.date.get_holyday_type(date.get_holyday()) + self._state = date.holiday_type else: times = hdate.Zmanim( date=today, latitude=self.latitude, longitude=self.longitude, diff --git a/requirements_all.txt b/requirements_all.txt index d391346710e..9af4c020892 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -461,7 +461,7 @@ hangups==0.4.6 hbmqtt==0.9.4 # homeassistant.components.sensor.jewish_calendar -hdate==0.6.5 +hdate==0.7.5 # homeassistant.components.climate.heatmiser heatmiserV3==0.9.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 90d13a8c3ec..e2a64592498 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -91,7 +91,7 @@ hangups==0.4.6 hbmqtt==0.9.4 # homeassistant.components.sensor.jewish_calendar -hdate==0.6.5 +hdate==0.7.5 # homeassistant.components.binary_sensor.workday holidays==0.9.8 diff --git a/tests/components/sensor/test_jewish_calendar.py b/tests/components/sensor/test_jewish_calendar.py index 47874d1da42..320bc903661 100644 --- a/tests/components/sensor/test_jewish_calendar.py +++ b/tests/components/sensor/test_jewish_calendar.py @@ -64,7 +64,7 @@ class TestJewishCalenderSensor(): (dt(2018, 9, 3), 'UTC', 31.778, 35.235, "english", "date", False, "23 Elul 5778"), (dt(2018, 9, 3), 'UTC', 31.778, 35.235, "hebrew", "date", - False, "כ\"ג באלול ה\' תשע\"ח"), + False, "כ\"ג אלול ה\' תשע\"ח"), (dt(2018, 9, 10), 'UTC', 31.778, 35.235, "hebrew", "holiday_name", False, "א\' ראש השנה"), (dt(2018, 9, 10), 'UTC', 31.778, 35.235, "english", "holiday_name", @@ -72,17 +72,17 @@ class TestJewishCalenderSensor(): (dt(2018, 9, 10), 'UTC', 31.778, 35.235, "english", "holyness", False, 1), (dt(2018, 9, 8), 'UTC', 31.778, 35.235, "hebrew", "weekly_portion", - False, "פרשת נצבים"), + False, "נצבים"), (dt(2018, 9, 8), 'America/New_York', 40.7128, -74.0060, "hebrew", "first_stars", True, time(19, 48)), (dt(2018, 9, 8), "Asia/Jerusalem", 31.778, 35.235, "hebrew", "first_stars", False, time(19, 21)), (dt(2018, 10, 14), "Asia/Jerusalem", 31.778, 35.235, "hebrew", - "weekly_portion", False, "פרשת לך לך"), + "weekly_portion", False, "לך לך"), (dt(2018, 10, 14, 17, 0, 0), "Asia/Jerusalem", 31.778, 35.235, - "hebrew", "date", False, "ה\' בחשון ה\' תשע\"ט"), + "hebrew", "date", False, "ה\' מרחשוון ה\' תשע\"ט"), (dt(2018, 10, 14, 19, 0, 0), "Asia/Jerusalem", 31.778, 35.235, - "hebrew", "date", False, "ו\' בחשון ה\' תשע\"ט") + "hebrew", "date", False, "ו\' מרחשוון ה\' תשע\"ט") ] test_ids = [