Compare commits

...

1 Commits

Author SHA1 Message Date
G Johansson 9258487331 Use objectselector with date selectors to configure add/remove days in workday 2026-05-13 15:34:57 +00:00
3 changed files with 112 additions and 18 deletions
+61 -16
View File
@@ -14,16 +14,20 @@ from homeassistant.config_entries import (
)
from homeassistant.const import CONF_COUNTRY, CONF_LANGUAGE, CONF_NAME
from homeassistant.core import callback
from homeassistant.data_entry_flow import AbortFlow
from homeassistant.data_entry_flow import AbortFlow, SectionConfig, section
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.selector import (
CountrySelector,
CountrySelectorConfig,
DateSelector,
LanguageSelector,
LanguageSelectorConfig,
NumberSelector,
NumberSelectorConfig,
NumberSelectorMode,
ObjectSelector,
ObjectSelectorConfig,
ObjectSelectorField,
SelectOptionDict,
SelectSelector,
SelectSelectorConfig,
@@ -36,10 +40,13 @@ from .const import (
ALLOWED_DAYS,
CONF_ADD_HOLIDAYS,
CONF_CATEGORY,
CONF_END_DATE,
CONF_EXCLUDES,
CONF_OFFSET,
CONF_PROVINCE,
CONF_REMOVE_HOLIDAYS,
CONF_REMOVE_HOLIDAYS_NAMED,
CONF_START_DATE,
CONF_WORKDAYS,
DEFAULT_EXCLUDES,
DEFAULT_NAME,
@@ -49,6 +56,8 @@ from .const import (
LOGGER,
)
CONF_ADD_REMOVE_HOLIDAYS = "add_remove_holidays"
def add_province_and_language_to_schema(
schema: vol.Schema,
@@ -189,21 +198,57 @@ DATA_SCHEMA_OPT = vol.Schema(
vol.Optional(CONF_OFFSET, default=DEFAULT_OFFSET): NumberSelector(
NumberSelectorConfig(min=-10, max=10, step=1, mode=NumberSelectorMode.BOX)
),
vol.Optional(CONF_ADD_HOLIDAYS, default=[]): SelectSelector(
SelectSelectorConfig(
options=[],
multiple=True,
custom_value=True,
mode=SelectSelectorMode.DROPDOWN,
)
),
vol.Optional(CONF_REMOVE_HOLIDAYS, default=[]): SelectSelector(
SelectSelectorConfig(
options=[],
multiple=True,
custom_value=True,
mode=SelectSelectorMode.DROPDOWN,
)
vol.Required(CONF_ADD_REMOVE_HOLIDAYS): section(
vol.Schema(
{
vol.Optional(CONF_ADD_HOLIDAYS): ObjectSelector(
ObjectSelectorConfig(
label_field=CONF_START_DATE,
description_field=CONF_END_DATE,
multiple=True,
translation_key=CONF_ADD_HOLIDAYS,
fields={
CONF_START_DATE: ObjectSelectorField(
required=True,
selector=DateSelector(),
),
CONF_END_DATE: ObjectSelectorField(
required=False,
selector=DateSelector(),
),
},
)
),
vol.Optional(CONF_REMOVE_HOLIDAYS): ObjectSelector(
ObjectSelectorConfig(
label_field=CONF_START_DATE,
description_field=CONF_END_DATE,
multiple=True,
translation_key=CONF_REMOVE_HOLIDAYS,
fields={
CONF_START_DATE: ObjectSelectorField(
required=True,
selector=DateSelector(),
),
CONF_END_DATE: ObjectSelectorField(
required=False,
selector=DateSelector(),
),
},
)
),
vol.Optional(CONF_REMOVE_HOLIDAYS_NAMED): SelectSelector(
SelectSelectorConfig(
options=[],
multiple=True,
mode=SelectSelectorMode.DROPDOWN,
custom_value=True,
translation_key=CONF_REMOVE_HOLIDAYS_NAMED,
)
),
},
),
SectionConfig(collapsed=True),
),
}
)
@@ -17,7 +17,10 @@ CONF_EXCLUDES = "excludes"
CONF_OFFSET = "days_offset"
CONF_ADD_HOLIDAYS = "add_holidays"
CONF_REMOVE_HOLIDAYS = "remove_holidays"
CONF_REMOVE_HOLIDAYS_NAMED = "remove_holidays_named"
CONF_CATEGORY = "category"
CONF_START_DATE = "start_date"
CONF_END_DATE = "end_date"
# By default, Monday - Friday are workdays
DEFAULT_WORKDAYS = ["mon", "tue", "wed", "thu", "fri"]
+48 -2
View File
@@ -31,7 +31,24 @@
"remove_holidays": "Remove holidays as YYYY-MM-DD, as range using `,` as separator or by using partial of name",
"workdays": "Select which weekdays to include as possible workdays."
},
"description": "Set additional options for {name} configured for country {country}"
"description": "Set additional options for {name} configured for country {country}",
"sections": {
"add_remove_holidays": {
"data": {
"add_holidays": "Add holidays",
"remove_holidays": "Remove holidays",
"remove_holidays_named": "Remove named holidays"
},
"data_description": {
"add_holidays": "Holidays to add. For a single day, only enter a date in the start date field.",
"remove_holidays": "Holidays to remove. For a single day, only enter a date in the start date field.",
"remove_holidays_named": "Select named holidays from the list to remove them to be considered as holiday days."
},
"description": "Configure the holidays to add or remove.",
"name": "Add/Remove Holidays"
}
}
},
"user": {
"data": {
@@ -176,11 +193,34 @@
"remove_holidays": "[%key:component::workday::config::step::options::data_description::remove_holidays%]",
"workdays": "[%key:component::workday::config::step::options::data_description::workdays%]"
},
"description": "Change additional options for {name} configured for country {country}"
"description": "Change additional options for {name} configured for country {country}",
"sections": {
"add_remove_holidays": {
"data": {
"add_holidays": "Add holidays",
"remove_holidays": "Remove holidays",
"remove_holidays_named": "Named holidays to remove"
},
"data_description": {
"add_holidays": "Holidays to add. For a single day, only enter a date in the start date field.",
"remove_holidays": "Holidays to remove. For a single day, only enter a date in the start date field.",
"remove_holidays_named": "Select named holidays from the list to remove them to be considered as holiday days."
},
"description": "Configure the holidays to add or remove.",
"name": "Add/Remove Holidays"
}
}
}
}
},
"selector": {
"add_holidays": {
"fields": {
"end_date": "End date",
"start_date": "Start date"
}
},
"category": {
"options": {
"armed_forces": "Armed forces",
@@ -216,6 +256,12 @@
"options": {
"none": "No subdivision"
}
},
"remove_holidays": {
"fields": {
"end_date": "[%key:component::workday::selector::add_holidays::fields::end_date%]",
"start_date": "[%key:component::workday::selector::add_holidays::fields::start_date%]"
}
}
},
"services": {