1 """Config flow for World clock."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
6 from typing
import Any, cast
9 import voluptuous
as vol
13 SchemaCommonFlowHandler,
14 SchemaConfigFlowHandler,
25 from .const
import CONF_TIME_FORMAT, DEFAULT_NAME, DEFAULT_TIME_STR_FORMAT, DOMAIN
29 value=DEFAULT_TIME_STR_FORMAT, label=f
"14:05 ({DEFAULT_TIME_STR_FORMAT})"
32 SelectOptionDict(value=
"%Y-%m-%d %H:%M", label=
"2024-01-01 14:05 (%Y-%m-%d %H:%M)"),
34 value=
"%a, %b %d, %Y %I:%M %p",
35 label=
"Mon, Jan 01, 2024 11:05 AM (%a, %b %d, %Y %I:%M %p)",
41 handler: SchemaCommonFlowHandler, user_input: dict[str, Any]
43 """Validate already existing entry."""
44 handler.parent_handler._async_abort_entries_match({**handler.options, **user_input})
49 async
def get_schema(handler: SchemaCommonFlowHandler) -> vol.Schema:
50 """Get available timezones."""
51 get_timezones: list[str] =
list(
52 await handler.parent_handler.hass.async_add_executor_job(
53 zoneinfo.available_timezones
58 vol.Required(CONF_NAME, default=DEFAULT_NAME):
TextSelector(),
61 options=get_timezones, mode=SelectSelectorMode.DROPDOWN, sort=
True
65 ).extend(DATA_SCHEMA_OPTIONS.schema)
68 DATA_SCHEMA_OPTIONS = vol.Schema(
70 vol.Optional(CONF_TIME_FORMAT, default=DEFAULT_TIME_STR_FORMAT):
SelectSelector(
72 options=TIME_STR_OPTIONS,
74 mode=SelectSelectorMode.DROPDOWN,
84 validate_user_input=validate_duplicate,
88 validate_user_input=validate_duplicate,
94 validate_user_input=validate_duplicate,
100 """Handle a config flow for Worldclock."""
102 config_flow = CONFIG_FLOW
103 options_flow = OPTIONS_FLOW
106 """Return config entry title."""
107 return cast(str, options[CONF_NAME])
str async_config_entry_title(self, Mapping[str, Any] options)
dict[str, Any] validate_duplicate(SchemaCommonFlowHandler handler, dict[str, Any] user_input)
vol.Schema get_schema(SchemaCommonFlowHandler handler)