1 """Adds config flow for Time & Date integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
6 from datetime
import timedelta
10 import voluptuous
as vol
17 SchemaCommonFlowHandler,
18 SchemaConfigFlowHandler,
29 from .const
import CONF_DISPLAY_OPTIONS, DOMAIN, OPTION_TYPES
30 from .sensor
import TimeDateSensor
32 _LOGGER = logging.getLogger(__name__)
34 USER_SCHEMA = vol.Schema(
39 mode=SelectSelectorMode.DROPDOWN,
40 translation_key=
"display_options",
48 handler: SchemaCommonFlowHandler, user_input: dict[str, Any]
50 """Validate rest setup."""
51 hass = handler.parent_handler.hass
52 if hass.config.time_zone
is None:
61 validate_user_input=validate_input,
67 """Handle a config flow for Time & Date."""
69 config_flow = CONFIG_FLOW
72 """Return config entry title."""
73 return f
"Time & Date {options[CONF_DISPLAY_OPTIONS]}"
76 """Abort if instance already exist."""
81 """Set up preview WS API."""
82 websocket_api.async_register_command(hass, ws_start_preview)
85 @websocket_api.websocket_command(
{
vol.Required("type"):
"time_date/start_preview",
86 vol.Required(
"flow_id"): str,
87 vol.Required(
"flow_type"): vol.Any(
"config_flow"),
88 vol.Required(
"user_input"): dict,
91 @websocket_api.async_response
97 """Generate a preview."""
105 domain=SENSOR_DOMAIN,
106 platform_name=DOMAIN,
109 entity_namespace=
None,
111 await entity_platform.async_load_translations()
114 def async_preview_updated(state: str, attributes: Mapping[str, Any]) ->
None:
115 """Forward config entry state events to websocket."""
116 connection.send_message(
117 websocket_api.event_message(
118 msg[
"id"], {
"attributes": attributes,
"state": state}
123 preview_entity.hass = hass
124 preview_entity.platform = entity_platform
126 connection.send_result(msg[
"id"])
127 connection.subscriptions[msg[
"id"]] = preview_entity.async_start_preview(
128 async_preview_updated
130
None async_setup_preview(HomeAssistant hass)
str async_config_entry_title(self, Mapping[str, Any] options)
None async_config_flow_finished(self, Mapping[str, Any] options)
None _async_abort_entries_match(self, dict[str, Any]|None match_dict=None)
None ws_start_preview(HomeAssistant hass, websocket_api.ActiveConnection connection, dict[str, Any] msg)
dict[str, Any] validate_input(SchemaCommonFlowHandler handler, dict[str, Any] user_input)
ModuleType|None async_prepare_setup_platform(core.HomeAssistant hass, ConfigType hass_config, str domain, str platform_name)