From b2bf36029705bbcbb1670e4a6d6ccfc2b5714f01 Mon Sep 17 00:00:00 2001 From: Arkadii Yakovets Date: Sat, 8 Jul 2023 11:27:25 -0700 Subject: [PATCH] Update holidays to 0.28 (#95091) Bump Python Holidays version to 0.28 Set `language` from country's default language for holidays objects. --- homeassistant/components/workday/binary_sensor.py | 15 ++++++++------- homeassistant/components/workday/config_flow.py | 11 +++++++---- homeassistant/components/workday/manifest.json | 9 ++------- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/workday/binary_sensor.py b/homeassistant/components/workday/binary_sensor.py index 51560161faa..0814958ad27 100644 --- a/homeassistant/components/workday/binary_sensor.py +++ b/homeassistant/components/workday/binary_sensor.py @@ -120,15 +120,16 @@ async def async_setup_entry( sensor_name: str = entry.options[CONF_NAME] workdays: list[str] = entry.options[CONF_WORKDAYS] + cls: HolidayBase = getattr(holidays, country) year: int = (dt_util.now() + timedelta(days=days_offset)).year - obj_holidays: HolidayBase = getattr(holidays, country)(years=year) - if province: - try: - obj_holidays = getattr(holidays, country)(subdiv=province, years=year) - except NotImplementedError: - LOGGER.error("There is no subdivision %s in country %s", province, country) - return + if province and province not in cls.subdivisions: + LOGGER.error("There is no subdivision %s in country %s", province, country) + return + + obj_holidays = cls( + subdiv=province, years=year, language=cls.default_language + ) # type: ignore[operator] # Add custom holidays try: diff --git a/homeassistant/components/workday/config_flow.py b/homeassistant/components/workday/config_flow.py index 7153dac1bcb..15e04ffca93 100644 --- a/homeassistant/components/workday/config_flow.py +++ b/homeassistant/components/workday/config_flow.py @@ -3,7 +3,8 @@ from __future__ import annotations from typing import Any -from holidays import country_holidays, list_supported_countries +import holidays +from holidays import HolidayBase, list_supported_countries import voluptuous as vol from homeassistant.config_entries import ( @@ -76,10 +77,12 @@ def validate_custom_dates(user_input: dict[str, Any]) -> None: if dt_util.parse_date(add_date) is None: raise AddDatesError("Incorrect date") + cls: HolidayBase = getattr(holidays, user_input[CONF_COUNTRY]) year: int = dt_util.now().year - obj_holidays = country_holidays( - user_input[CONF_COUNTRY], user_input.get(CONF_PROVINCE), year - ) + + obj_holidays = cls( + subdiv=user_input.get(CONF_PROVINCE), years=year, language=cls.default_language + ) # type: ignore[operator] for remove_date in user_input[CONF_REMOVE_HOLIDAYS]: if dt_util.parse_date(remove_date) is None: diff --git a/homeassistant/components/workday/manifest.json b/homeassistant/components/workday/manifest.json index e018eaa588e..698ef17902f 100644 --- a/homeassistant/components/workday/manifest.json +++ b/homeassistant/components/workday/manifest.json @@ -5,12 +5,7 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/workday", "iot_class": "local_polling", - "loggers": [ - "convertdate", - "hijri_converter", - "holidays", - "korean_lunar_calendar" - ], + "loggers": ["holidays"], "quality_scale": "internal", - "requirements": ["holidays==0.21.13"] + "requirements": ["holidays==0.28"] } diff --git a/requirements_all.txt b/requirements_all.txt index e990e899435..70285de2588 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -977,7 +977,7 @@ hlk-sw16==0.0.9 hole==0.8.0 # homeassistant.components.workday -holidays==0.21.13 +holidays==0.28 # homeassistant.components.frontend home-assistant-frontend==20230705.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 819899f96cf..f712da5d6ed 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -760,7 +760,7 @@ hlk-sw16==0.0.9 hole==0.8.0 # homeassistant.components.workday -holidays==0.21.13 +holidays==0.28 # homeassistant.components.frontend home-assistant-frontend==20230705.1