1 """Config flow for file integration."""
3 from __future__
import annotations
5 from copy
import deepcopy
8 import voluptuous
as vol
20 CONF_UNIT_OF_MEASUREMENT,
27 BooleanSelectorConfig,
29 TemplateSelectorConfig,
35 from .const
import CONF_TIMESTAMP, DEFAULT_NAME, DOMAIN
41 FILE_OPTIONS_SCHEMAS = {
42 Platform.SENSOR.value: vol.Schema(
44 vol.Optional(CONF_VALUE_TEMPLATE): TEMPLATE_SELECTOR,
45 vol.Optional(CONF_UNIT_OF_MEASUREMENT): TEXT_SELECTOR,
48 Platform.NOTIFY.value: vol.Schema(
50 vol.Optional(CONF_TIMESTAMP, default=
False): BOOLEAN_SELECTOR,
56 Platform.SENSOR.value: vol.Schema(
58 vol.Required(CONF_FILE_PATH): TEXT_SELECTOR,
60 ).extend(FILE_OPTIONS_SCHEMAS[Platform.SENSOR.value].schema),
61 Platform.NOTIFY.value: vol.Schema(
63 vol.Required(CONF_FILE_PATH): TEXT_SELECTOR,
65 ).extend(FILE_OPTIONS_SCHEMAS[Platform.NOTIFY.value].schema),
70 """Handle a file config flow."""
77 config_entry: ConfigEntry,
78 ) -> FileOptionsFlowHandler:
79 """Get the options flow for this handler."""
83 """Ensure the file path is valid."""
84 return await self.hass.async_add_executor_job(
85 self.hass.config.is_allowed_path, file_path
89 self, user_input: dict[str, Any] |
None =
None
90 ) -> ConfigFlowResult:
91 """Handle a flow initiated by the user."""
94 menu_options=[
"notify",
"sensor"],
98 self, platform: str, user_input: dict[str, Any] |
None =
None
99 ) -> ConfigFlowResult:
100 """Handle file config flow step."""
101 errors: dict[str, str] = {}
103 user_input[CONF_PLATFORM] = platform
106 errors[CONF_FILE_PATH] =
"not_allowed"
108 title = f
"{DEFAULT_NAME} [{user_input[CONF_FILE_PATH]}]"
109 data = deepcopy(user_input)
111 for key, value
in user_input.items():
112 if key
not in (CONF_FILE_PATH, CONF_PLATFORM, CONF_NAME):
118 step_id=platform, data_schema=FILE_FLOW_SCHEMAS[platform], errors=errors
122 self, user_input: dict[str, Any] |
None =
None
123 ) -> ConfigFlowResult:
124 """Handle file notifier config flow."""
125 return await self.
_async_handle_step_async_handle_step(Platform.NOTIFY.value, user_input)
128 self, user_input: dict[str, Any] |
None =
None
129 ) -> ConfigFlowResult:
130 """Handle file sensor config flow."""
131 return await self.
_async_handle_step_async_handle_step(Platform.SENSOR.value, user_input)
135 """Handle File options."""
138 self, user_input: dict[str, Any] |
None =
None
139 ) -> ConfigFlowResult:
140 """Manage File options."""
ConfigFlowResult async_step_notify(self, dict[str, Any]|None user_input=None)
bool validate_file_path(self, str file_path)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_sensor(self, dict[str, Any]|None user_input=None)
FileOptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult _async_handle_step(self, str platform, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_init(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_create_entry(self, *str title, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None, Mapping[str, Any]|None options=None)
None _async_abort_entries_match(self, dict[str, Any]|None match_dict=None)
ConfigFlowResult async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
vol.Schema add_suggested_values_to_schema(self, vol.Schema data_schema, Mapping[str, Any]|None suggested_values)
_FlowResultT async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_show_menu(self, *str|None step_id=None, Container[str] menu_options, Mapping[str, str]|None description_placeholders=None)
_FlowResultT async_create_entry(self, *str|None title=None, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None)