Skip to content

Commit

Permalink
Merge pull request #6 from timniklas/timniklas-patch-1
Browse files Browse the repository at this point in the history
Added reconfigure option
  • Loading branch information
timniklas authored Oct 19, 2024
2 parents d4044b6 + 633322e commit 60375cb
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
42 changes: 38 additions & 4 deletions custom_components/blitzerde/config_flow.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,7 +20,7 @@

_LOGGER = logging.getLogger(__name__)

class SmartmeConfigFlow(ConfigFlow, domain=DOMAIN):
class BlitzerdeConfigFlow(ConfigFlow, domain=DOMAIN):
VERSION = 1

def __init__(self) -> None:
Expand All @@ -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))
11 changes: 11 additions & 0 deletions custom_components/blitzerde/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
}
}
}
}
11 changes: 11 additions & 0 deletions custom_components/blitzerde/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
}
}
}
}

0 comments on commit 60375cb

Please sign in to comment.