diff --git a/homeassistant/components/jewish_calendar/__init__.py b/homeassistant/components/jewish_calendar/__init__.py index 2e4644d7ef5..45f979874f7 100644 --- a/homeassistant/components/jewish_calendar/__init__.py +++ b/homeassistant/components/jewish_calendar/__init__.py @@ -21,6 +21,7 @@ SENSOR_TYPES = { "weekly_portion": ["Parshat Hashavua", "mdi:book-open-variant"], "holiday": ["Holiday", "mdi:calendar-star"], "omer_count": ["Day of the Omer", "mdi:counter"], + "daf_yomi": ["Daf Yomi", "mdi:book-open-variant"], }, "time": { "first_light": ["Alot Hashachar", "mdi:weather-sunset-up"], diff --git a/homeassistant/components/jewish_calendar/manifest.json b/homeassistant/components/jewish_calendar/manifest.json index 8e1781f310b..c4ebb382a44 100644 --- a/homeassistant/components/jewish_calendar/manifest.json +++ b/homeassistant/components/jewish_calendar/manifest.json @@ -2,7 +2,7 @@ "domain": "jewish_calendar", "name": "Jewish Calendar", "documentation": "https://www.home-assistant.io/integrations/jewish_calendar", - "requirements": ["hdate==0.9.3"], + "requirements": ["hdate==0.9.5"], "dependencies": [], "codeowners": ["@tsvi"] } diff --git a/homeassistant/components/jewish_calendar/sensor.py b/homeassistant/components/jewish_calendar/sensor.py index d0376694a44..7da9d7e31d0 100644 --- a/homeassistant/components/jewish_calendar/sensor.py +++ b/homeassistant/components/jewish_calendar/sensor.py @@ -73,7 +73,7 @@ class JewishCalendarSensor(Entity): _LOGGER.debug("Now: %s Sunset: %s", now, sunset) - date = hdate.HDate(today, diaspora=self._diaspora, hebrew=self._hebrew) + daytime_date = hdate.HDate(today, diaspora=self._diaspora, hebrew=self._hebrew) # The Jewish day starts after darkness (called "tzais") and finishes at # sunset ("shkia"). The time in between is a gray area (aka "Bein @@ -82,16 +82,16 @@ class JewishCalendarSensor(Entity): # For some sensors, it is more interesting to consider the date to be # tomorrow based on sunset ("shkia"), for others based on "tzais". # Hence the following variables. - after_tzais_date = after_shkia_date = date + after_tzais_date = after_shkia_date = daytime_date today_times = self.make_zmanim(today) if now > sunset: - after_shkia_date = date.next_day + after_shkia_date = daytime_date.next_day if today_times.havdalah and now > today_times.havdalah: - after_tzais_date = date.next_day + after_tzais_date = daytime_date.next_day - self._state = self.get_state(after_shkia_date, after_tzais_date) + self._state = self.get_state(daytime_date, after_shkia_date, after_tzais_date) _LOGGER.debug("New value for %s: %s", self._type, self._state) def make_zmanim(self, date): @@ -112,7 +112,7 @@ class JewishCalendarSensor(Entity): return {} - def get_state(self, after_shkia_date, after_tzais_date): + def get_state(self, daytime_date, after_shkia_date, after_tzais_date): """For a given type of sensor, return the state.""" # Terminology note: by convention in py-libhdate library, "upcoming" # refers to "current" or "upcoming" dates. @@ -128,6 +128,8 @@ class JewishCalendarSensor(Entity): return after_shkia_date.holiday_description if self._type == "omer_count": return after_shkia_date.omer_day + if self._type == "daf_yomi": + return daytime_date.daf_yomi return None @@ -157,7 +159,7 @@ class JewishCalendarTimeSensor(JewishCalendarSensor): return attrs - def get_state(self, after_shkia_date, after_tzais_date): + def get_state(self, daytime_date, after_shkia_date, after_tzais_date): """For a given type of sensor, return the state.""" if self._type == "upcoming_shabbat_candle_lighting": times = self.make_zmanim( diff --git a/requirements_all.txt b/requirements_all.txt index c28c0df1965..548ad2bd7ea 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -659,7 +659,7 @@ hass-nabucasa==0.31 hbmqtt==0.9.5 # homeassistant.components.jewish_calendar -hdate==0.9.3 +hdate==0.9.5 # homeassistant.components.heatmiser heatmiserV3==1.1.18 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index cca31185b6f..3e8eca8d3ac 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -242,7 +242,7 @@ hass-nabucasa==0.31 hbmqtt==0.9.5 # homeassistant.components.jewish_calendar -hdate==0.9.3 +hdate==0.9.5 # homeassistant.components.here_travel_time herepy==2.0.0 diff --git a/tests/components/jewish_calendar/test_sensor.py b/tests/components/jewish_calendar/test_sensor.py index e630702c6b2..59b6dc01313 100644 --- a/tests/components/jewish_calendar/test_sensor.py +++ b/tests/components/jewish_calendar/test_sensor.py @@ -568,3 +568,37 @@ async def test_omer_sensor(hass, test_time, result): await hass.async_block_till_done() assert hass.states.get("sensor.test_day_of_the_omer").state == result + + +DAFYOMI_PARAMS = [ + (dt(2014, 4, 28, 0), "Beitzah 29"), + (dt(2020, 1, 4, 0), "Niddah 73"), + (dt(2020, 1, 5, 0), "Berachos 2"), + (dt(2020, 3, 7, 0), "Berachos 64"), + (dt(2020, 3, 8, 0), "Shabbos 2"), +] +DAFYOMI_TEST_IDS = [ + "randomly_picked_date", + "end_of_cycle13", + "start_of_cycle14", + "cycle14_end_of_berachos", + "cycle14_start_of_shabbos", +] + + +@pytest.mark.parametrize(["test_time", "result"], DAFYOMI_PARAMS, ids=DAFYOMI_TEST_IDS) +async def test_dafyomi_sensor(hass, test_time, result): + """Test Daf Yomi sensor output.""" + test_time = hass.config.time_zone.localize(test_time) + + with alter_time(test_time): + assert await async_setup_component( + hass, jewish_calendar.DOMAIN, {"jewish_calendar": {"name": "test"}} + ) + await hass.async_block_till_done() + + future = dt_util.utcnow() + timedelta(seconds=30) + async_fire_time_changed(hass, future) + await hass.async_block_till_done() + + assert hass.states.get("sensor.test_daf_yomi").state == result