1 """The filesize config flow."""
3 from __future__
import annotations
9 import voluptuous
as vol
15 from .const
import DOMAIN
17 DATA_SCHEMA = vol.Schema({vol.Required(CONF_FILE_PATH): str})
19 _LOGGER = logging.getLogger(__name__)
22 def validate_path(hass: HomeAssistant, path: str) -> tuple[str |
None, dict[str, str]]:
24 get_path = pathlib.Path(path)
25 if not get_path.exists()
or not get_path.is_file():
26 _LOGGER.error(
"Can not access file %s", path)
27 return (
None, {
"base":
"not_valid"})
29 if not hass.config.is_allowed_path(path):
30 _LOGGER.error(
"Filepath %s is not allowed", path)
31 return (
None, {
"base":
"not_allowed"})
33 full_path = get_path.absolute()
35 return (
str(full_path), {})
39 """Config flow for Filesize."""
44 self, user_input: dict[str, Any] |
None =
None
45 ) -> ConfigFlowResult:
46 """Handle a flow initialized by the user."""
47 errors: dict[str, str] = {}
49 if user_input
is not None:
50 full_path, errors = await self.hass.async_add_executor_job(
51 validate_path, self.hass, user_input[CONF_FILE_PATH]
57 name =
str(user_input[CONF_FILE_PATH]).rsplit(
"/", maxsplit=1)[-1]
60 data={CONF_FILE_PATH: user_input[CONF_FILE_PATH]},
64 step_id=
"user", data_schema=DATA_SCHEMA, errors=errors
68 self, user_input: dict[str, Any] |
None =
None
69 ) -> ConfigFlowResult:
70 """Handle a reconfigure flow initialized by the user."""
71 errors: dict[str, str] = {}
73 if user_input
is not None:
75 full_path, errors = await self.hass.async_add_executor_job(
76 validate_path, self.hass, user_input[CONF_FILE_PATH]
82 name =
str(user_input[CONF_FILE_PATH]).rsplit(
"/", maxsplit=1)[-1]
87 data_updates={CONF_FILE_PATH: user_input[CONF_FILE_PATH]},
91 step_id=
"reconfigure", data_schema=DATA_SCHEMA, errors=errors
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reconfigure(self, dict[str, Any]|None user_input=None)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
ConfigEntry|None async_set_unique_id(self, str|None unique_id=None, *bool raise_on_progress=True)
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)
ConfigFlowResult async_update_reload_and_abort(self, ConfigEntry entry, *str|None|UndefinedType unique_id=UNDEFINED, str|UndefinedType title=UNDEFINED, Mapping[str, Any]|UndefinedType data=UNDEFINED, Mapping[str, Any]|UndefinedType data_updates=UNDEFINED, Mapping[str, Any]|UndefinedType options=UNDEFINED, str|UndefinedType reason=UNDEFINED, bool reload_even_if_entry_is_unchanged=True)
ConfigEntry _get_reconfigure_entry(self)
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)
_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_create_entry(self, *str|None title=None, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None)
tuple[str|None, dict[str, str]] validate_path(HomeAssistant hass, str path)