diff --git a/custom_components/blitzerde/config_flow.py b/custom_components/blitzerde/config_flow.py index fc85da1..aaf16ac 100644 --- a/custom_components/blitzerde/config_flow.py +++ b/custom_components/blitzerde/config_flow.py @@ -1,10 +1,13 @@ import voluptuous as vol import logging -from homeassistant.config_entries import ConfigFlow +from homeassistant.config_entries import ( + ConfigFlow, + OptionsFlowWithConfigEntry, +) from homeassistant.helpers.aiohttp_client import async_get_clientsession from aiohttp import ClientError, ClientResponseError, ClientSession - +from homeassistant.core import callback from homeassistant.helpers.selector import selector from .const import DOMAIN @@ -17,7 +20,7 @@ _LOGGER = logging.getLogger(__name__) -class SmartmeConfigFlow(ConfigFlow, domain=DOMAIN): +class BlitzerdeConfigFlow(ConfigFlow, domain=DOMAIN): VERSION = 1 def __init__(self) -> None: @@ -39,5 +42,36 @@ async def async_step_user(self, user_input=None): "radius": True } }) - return self.async_show_form(step_id="user", data_schema=vol.Schema(data_schema)) + + @staticmethod + @callback + def async_get_options_flow(config_entry): + """Get the options flow for Met.""" + return BlitzerdeOptionsFlow(config_entry) + + +class BlitzerdeOptionsFlow(OptionsFlowWithConfigEntry): + + def __init__(self, config_entry) -> None: + """Initialize options flow.""" + self._config_entry = config_entry + + async def async_step_init(self, user_input=None): + """Configure options for Met.""" + + if user_input is not None: + # Update config entry with data from user input + user_input[CONF_NAME] = self.config_entry.data.get(CONF_NAME) + user_input[CONF_LOCATION] = self.config_entry.data.get(CONF_LOCATION) + self.hass.config_entries.async_update_entry( + self._config_entry, data=user_input + ) + return self.async_create_entry( + title=self._config_entry.title, data=user_input + ) + + data_schema = { + vol.Required(CONF_SELECTOR, default=self.config_entry.data.get(CONF_SELECTOR)): str + } + return self.async_show_form(step_id="init", data_schema=vol.Schema(data_schema)) diff --git a/custom_components/blitzerde/translations/de.json b/custom_components/blitzerde/translations/de.json index 84ae680..b47ad5b 100644 --- a/custom_components/blitzerde/translations/de.json +++ b/custom_components/blitzerde/translations/de.json @@ -16,5 +16,16 @@ "connenction": "Fehler bei dem Verbindungsaufbau.", "unknown": "Unbekannter Fehler." } + }, + "options": { + "step": { + "init": { + "title": "Blitzer.de Setup", + "description": "Passe folgende Einstellunge an.", + "data": { + "selector": "Regex Filter der Städtenamen (Whitelist)" + } + } + } } } diff --git a/custom_components/blitzerde/translations/en.json b/custom_components/blitzerde/translations/en.json index 50b6147..61d896d 100644 --- a/custom_components/blitzerde/translations/en.json +++ b/custom_components/blitzerde/translations/en.json @@ -16,5 +16,16 @@ "connenction": "Error while connecting to api.", "unknown": "Unknown error." } + }, + "options": { + "step": { + "init": { + "title": "Blitzer.de Setup", + "description": "Change the following settings.", + "data": { + "selector": "Regex Filter of city names (whitelist)" + } + } + } } }