mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add subdiv aliases to workday (#133608)
* Add subdiv aliases to workday * Fix * Add lib test
This commit is contained in:
parent
cd2313d2ca
commit
f2e4bcea19
@ -26,6 +26,7 @@ from homeassistant.helpers.selector import (
|
|||||||
NumberSelector,
|
NumberSelector,
|
||||||
NumberSelectorConfig,
|
NumberSelectorConfig,
|
||||||
NumberSelectorMode,
|
NumberSelectorMode,
|
||||||
|
SelectOptionDict,
|
||||||
SelectSelector,
|
SelectSelector,
|
||||||
SelectSelectorConfig,
|
SelectSelectorConfig,
|
||||||
SelectSelectorMode,
|
SelectSelectorMode,
|
||||||
@ -79,10 +80,19 @@ def add_province_and_language_to_schema(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if provinces := all_countries.get(country):
|
if provinces := all_countries.get(country):
|
||||||
|
if _country.subdivisions_aliases and (
|
||||||
|
subdiv_aliases := _country.get_subdivision_aliases()
|
||||||
|
):
|
||||||
|
province_options: list[Any] = [
|
||||||
|
SelectOptionDict(value=k, label=", ".join(v))
|
||||||
|
for k, v in subdiv_aliases.items()
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
province_options = provinces
|
||||||
province_schema = {
|
province_schema = {
|
||||||
vol.Optional(CONF_PROVINCE): SelectSelector(
|
vol.Optional(CONF_PROVINCE): SelectSelector(
|
||||||
SelectSelectorConfig(
|
SelectSelectorConfig(
|
||||||
options=provinces,
|
options=province_options,
|
||||||
mode=SelectSelectorMode.DROPDOWN,
|
mode=SelectSelectorMode.DROPDOWN,
|
||||||
translation_key=CONF_PROVINCE,
|
translation_key=CONF_PROVINCE,
|
||||||
)
|
)
|
||||||
|
@ -55,7 +55,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||||||
CONF_WORKDAYS: DEFAULT_WORKDAYS,
|
CONF_WORKDAYS: DEFAULT_WORKDAYS,
|
||||||
CONF_ADD_HOLIDAYS: [],
|
CONF_ADD_HOLIDAYS: [],
|
||||||
CONF_REMOVE_HOLIDAYS: [],
|
CONF_REMOVE_HOLIDAYS: [],
|
||||||
CONF_LANGUAGE: "de",
|
CONF_LANGUAGE: "en_US",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -70,7 +70,48 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||||||
"workdays": ["mon", "tue", "wed", "thu", "fri"],
|
"workdays": ["mon", "tue", "wed", "thu", "fri"],
|
||||||
"add_holidays": [],
|
"add_holidays": [],
|
||||||
"remove_holidays": [],
|
"remove_holidays": [],
|
||||||
"language": "de",
|
"language": "en_US",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_form_province_no_alias(hass: HomeAssistant) -> None:
|
||||||
|
"""Test we get the forms."""
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
)
|
||||||
|
assert result["type"] is FlowResultType.FORM
|
||||||
|
|
||||||
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
{
|
||||||
|
CONF_NAME: "Workday Sensor",
|
||||||
|
CONF_COUNTRY: "US",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
result3 = await hass.config_entries.flow.async_configure(
|
||||||
|
result2["flow_id"],
|
||||||
|
{
|
||||||
|
CONF_EXCLUDES: DEFAULT_EXCLUDES,
|
||||||
|
CONF_OFFSET: DEFAULT_OFFSET,
|
||||||
|
CONF_WORKDAYS: DEFAULT_WORKDAYS,
|
||||||
|
CONF_ADD_HOLIDAYS: [],
|
||||||
|
CONF_REMOVE_HOLIDAYS: [],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert result3["type"] is FlowResultType.CREATE_ENTRY
|
||||||
|
assert result3["title"] == "Workday Sensor"
|
||||||
|
assert result3["options"] == {
|
||||||
|
"name": "Workday Sensor",
|
||||||
|
"country": "US",
|
||||||
|
"excludes": ["sat", "sun", "holiday"],
|
||||||
|
"days_offset": 0,
|
||||||
|
"workdays": ["mon", "tue", "wed", "thu", "fri"],
|
||||||
|
"add_holidays": [],
|
||||||
|
"remove_holidays": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ from __future__ import annotations
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
|
from holidays.utils import country_holidays
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -50,3 +51,18 @@ async def test_update_options(
|
|||||||
assert entry_check.state is ConfigEntryState.LOADED
|
assert entry_check.state is ConfigEntryState.LOADED
|
||||||
state = hass.states.get("binary_sensor.workday_sensor")
|
state = hass.states.get("binary_sensor.workday_sensor")
|
||||||
assert state.state == "off"
|
assert state.state == "off"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_workday_subdiv_aliases() -> None:
|
||||||
|
"""Test subdiv aliases in holidays library."""
|
||||||
|
|
||||||
|
country = country_holidays(
|
||||||
|
country="FR",
|
||||||
|
years=2025,
|
||||||
|
)
|
||||||
|
subdiv_aliases = country.get_subdivision_aliases()
|
||||||
|
assert subdiv_aliases["GES"] == [ # codespell:ignore
|
||||||
|
"Alsace",
|
||||||
|
"Champagne-Ardenne",
|
||||||
|
"Lorraine",
|
||||||
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user