diff --git a/homeassistant/components/workday/binary_sensor.py b/homeassistant/components/workday/binary_sensor.py index 33c2e249024a62..f4a2541a1d7e50 100644 --- a/homeassistant/components/workday/binary_sensor.py +++ b/homeassistant/components/workday/binary_sensor.py @@ -90,7 +90,7 @@ def _get_obj_holidays( obj_holidays: HolidayBase = country_holidays( country, subdiv=province, - years=year, + years=[year, year + 1], language=language, categories=set_categories, ) @@ -129,6 +129,7 @@ async def async_setup_entry( ) calc_add_holidays: list[str] = validate_dates(add_holidays) calc_remove_holidays: list[str] = validate_dates(remove_holidays) + next_year = dt_util.now().year + 1 # Add custom holidays try: @@ -152,26 +153,28 @@ async def async_setup_entry( LOGGER.debug("Removed %s by name '%s'", holiday, remove_holiday) except KeyError as unmatched: LOGGER.warning("No holiday found matching %s", unmatched) - if dt_util.parse_date(remove_holiday): - async_create_issue( - hass, - DOMAIN, - f"bad_date_holiday-{entry.entry_id}-{slugify(remove_holiday)}", - is_fixable=True, - is_persistent=False, - severity=IssueSeverity.WARNING, - translation_key="bad_date_holiday", - translation_placeholders={ - CONF_COUNTRY: country if country else "-", - "title": entry.title, - CONF_REMOVE_HOLIDAYS: remove_holiday, - }, - data={ - "entry_id": entry.entry_id, - "country": country, - "named_holiday": remove_holiday, - }, - ) + if _date := dt_util.parse_date(remove_holiday): + if _date.year <= next_year: + # Only check and raise issues for current and next year + async_create_issue( + hass, + DOMAIN, + f"bad_date_holiday-{entry.entry_id}-{slugify(remove_holiday)}", + is_fixable=True, + is_persistent=False, + severity=IssueSeverity.WARNING, + translation_key="bad_date_holiday", + translation_placeholders={ + CONF_COUNTRY: country if country else "-", + "title": entry.title, + CONF_REMOVE_HOLIDAYS: remove_holiday, + }, + data={ + "entry_id": entry.entry_id, + "country": country, + "named_holiday": remove_holiday, + }, + ) else: async_create_issue( hass, diff --git a/tests/components/workday/snapshots/test_binary_sensor.ambr b/tests/components/workday/snapshots/test_binary_sensor.ambr new file mode 100644 index 00000000000000..8ad2f37f360384 --- /dev/null +++ b/tests/components/workday/snapshots/test_binary_sensor.ambr @@ -0,0 +1,25 @@ +# serializer version: 1 +# name: test_only_repairs_for_current_next_year + dict({ + tuple( + 'workday', + 'bad_date_holiday-1-2024_08_15', + ): IssueRegistryItemSnapshot({ + 'created': , + 'dismissed_version': None, + 'domain': 'workday', + 'is_persistent': False, + 'issue_id': 'bad_date_holiday-1-2024_08_15', + }), + tuple( + 'workday', + 'bad_date_holiday-1-2025_08_15', + ): IssueRegistryItemSnapshot({ + 'created': , + 'dismissed_version': None, + 'domain': 'workday', + 'is_persistent': False, + 'issue_id': 'bad_date_holiday-1-2025_08_15', + }), + }) +# --- diff --git a/tests/components/workday/test_binary_sensor.py b/tests/components/workday/test_binary_sensor.py index a2718c00824d38..212c3e9d305d98 100644 --- a/tests/components/workday/test_binary_sensor.py +++ b/tests/components/workday/test_binary_sensor.py @@ -5,10 +5,18 @@ from freezegun.api import FrozenDateTimeFactory import pytest +from syrupy.assertion import SnapshotAssertion from homeassistant.components.workday.binary_sensor import SERVICE_CHECK_DATE -from homeassistant.components.workday.const import DOMAIN +from homeassistant.components.workday.const import ( + DEFAULT_EXCLUDES, + DEFAULT_NAME, + DEFAULT_OFFSET, + DEFAULT_WORKDAYS, + DOMAIN, +) from homeassistant.core import HomeAssistant +from homeassistant.helpers import issue_registry as ir from homeassistant.setup import async_setup_component from homeassistant.util import dt as dt_util from homeassistant.util.dt import UTC @@ -422,3 +430,34 @@ async def test_optional_category( state = hass.states.get("binary_sensor.workday_sensor") assert state is not None assert state.state == end_state + + +async def test_only_repairs_for_current_next_year( + hass: HomeAssistant, + freezer: FrozenDateTimeFactory, + issue_registry: ir.IssueRegistry, + snapshot: SnapshotAssertion, +) -> None: + """Test only repairs are raised for current and next year.""" + freezer.move_to(datetime(2024, 8, 15, 12, tzinfo=UTC)) + remove_dates = [ + # None of these dates are holidays + "2024-08-15", # Creates issue + "2025-08-15", # Creates issue + "2026-08-15", # No issue + ] + config = { + "name": DEFAULT_NAME, + "country": "DE", + "province": "BW", + "excludes": DEFAULT_EXCLUDES, + "days_offset": DEFAULT_OFFSET, + "workdays": DEFAULT_WORKDAYS, + "add_holidays": [], + "remove_holidays": remove_dates, + "language": "de", + } + await init_integration(hass, config) + + assert len(issue_registry.issues) == 2 + assert issue_registry.issues == snapshot