Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added reconfigure option #6

Merged
merged 3 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)"
}
}
}
}
}
Loading