1 """Adds config flow for Brottsplatskartan integration."""
3 from __future__
import annotations
8 from brottsplatskartan
import AREAS
9 import voluptuous
as vol
15 from .const
import CONF_APP_ID, CONF_AREA, DEFAULT_NAME, DOMAIN
17 DATA_SCHEMA = vol.Schema(
19 vol.Optional(CONF_LOCATION): selector.LocationSelector(
20 selector.LocationSelectorConfig(radius=
False, icon=
"")
22 vol.Optional(CONF_AREA): selector.SelectSelector(
23 selector.SelectSelectorConfig(
25 mode=selector.SelectSelectorMode.DROPDOWN,
33 """Handle a config flow for Brottsplatskartan integration."""
38 self, user_input: dict[str, Any] |
None =
None
39 ) -> ConfigFlowResult:
40 """Handle the user step."""
41 errors: dict[str, str] = {}
43 if user_input
is not None:
44 latitude: float |
None =
None
45 longitude: float |
None =
None
46 area: str |
None = user_input.get(CONF_AREA)
49 name = f
"{DEFAULT_NAME} {area}"
50 elif location := user_input.get(CONF_LOCATION):
51 lat: float = location[CONF_LATITUDE]
52 long: float = location[CONF_LONGITUDE]
55 name = f
"{DEFAULT_NAME} {round(latitude, 2)}, {round(longitude, 2)}"
57 latitude = self.hass.config.latitude
58 longitude = self.hass.config.longitude
59 name = f
"{DEFAULT_NAME} HOME"
61 app = f
"ha-{uuid.getnode()}"
64 {CONF_AREA: area, CONF_LATITUDE: latitude, CONF_LONGITUDE: longitude}
69 CONF_LATITUDE: latitude,
70 CONF_LONGITUDE: longitude,
78 data_schema=DATA_SCHEMA,
ConfigFlowResult async_step_user(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)
_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)