mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 23:07:09 +00:00
Workday raise issues only to next year (#126997)
* Workday - raise issues only for current and next year * variable
This commit is contained in:
parent
a44bf164e5
commit
92a6f231a9
@ -90,7 +90,7 @@ def _get_obj_holidays(
|
|||||||
obj_holidays: HolidayBase = country_holidays(
|
obj_holidays: HolidayBase = country_holidays(
|
||||||
country,
|
country,
|
||||||
subdiv=province,
|
subdiv=province,
|
||||||
years=year,
|
years=[year, year + 1],
|
||||||
language=language,
|
language=language,
|
||||||
categories=set_categories,
|
categories=set_categories,
|
||||||
)
|
)
|
||||||
@ -129,6 +129,7 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
calc_add_holidays: list[str] = validate_dates(add_holidays)
|
calc_add_holidays: list[str] = validate_dates(add_holidays)
|
||||||
calc_remove_holidays: list[str] = validate_dates(remove_holidays)
|
calc_remove_holidays: list[str] = validate_dates(remove_holidays)
|
||||||
|
next_year = dt_util.now().year + 1
|
||||||
|
|
||||||
# Add custom holidays
|
# Add custom holidays
|
||||||
try:
|
try:
|
||||||
@ -152,7 +153,9 @@ async def async_setup_entry(
|
|||||||
LOGGER.debug("Removed %s by name '%s'", holiday, remove_holiday)
|
LOGGER.debug("Removed %s by name '%s'", holiday, remove_holiday)
|
||||||
except KeyError as unmatched:
|
except KeyError as unmatched:
|
||||||
LOGGER.warning("No holiday found matching %s", unmatched)
|
LOGGER.warning("No holiday found matching %s", unmatched)
|
||||||
if dt_util.parse_date(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(
|
async_create_issue(
|
||||||
hass,
|
hass,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
25
tests/components/workday/snapshots/test_binary_sensor.ambr
Normal file
25
tests/components/workday/snapshots/test_binary_sensor.ambr
Normal file
@ -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': <ANY>,
|
||||||
|
'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': <ANY>,
|
||||||
|
'dismissed_version': None,
|
||||||
|
'domain': 'workday',
|
||||||
|
'is_persistent': False,
|
||||||
|
'issue_id': 'bad_date_holiday-1-2025_08_15',
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
# ---
|
@ -5,10 +5,18 @@ from typing import Any
|
|||||||
|
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
import pytest
|
import pytest
|
||||||
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.components.workday.binary_sensor import SERVICE_CHECK_DATE
|
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.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import issue_registry as ir
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
from homeassistant.util.dt import UTC
|
from homeassistant.util.dt import UTC
|
||||||
@ -422,3 +430,34 @@ async def test_optional_category(
|
|||||||
state = hass.states.get("binary_sensor.workday_sensor")
|
state = hass.states.get("binary_sensor.workday_sensor")
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == end_state
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user