Add on 0.6.9
This commit is contained in:
87
custom_components/bahmcloud_store/config_flow.py
Normal file
87
custom_components/bahmcloud_store/config_flow.py
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant import config_entries
|
||||||
|
|
||||||
|
DOMAIN = "bahmcloud_store"
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
CONF_GITHUB_TOKEN = "github_token"
|
||||||
|
|
||||||
|
|
||||||
|
class BCSConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
"""Config flow for Bahmcloud Store.
|
||||||
|
|
||||||
|
Design goals:
|
||||||
|
- GUI setup only (no YAML config)
|
||||||
|
- store index URL is fixed (not configurable)
|
||||||
|
- optional GitHub token to raise API rate limits
|
||||||
|
"""
|
||||||
|
|
||||||
|
VERSION = 1
|
||||||
|
|
||||||
|
async def async_step_user(self, user_input: dict[str, Any] | None = None):
|
||||||
|
"""Handle the initial step."""
|
||||||
|
# Single instance only
|
||||||
|
if self._async_current_entries():
|
||||||
|
return self.async_abort(reason="single_instance_allowed")
|
||||||
|
|
||||||
|
if user_input is not None:
|
||||||
|
token = (user_input.get(CONF_GITHUB_TOKEN) or "").strip() or None
|
||||||
|
data: dict[str, Any] = {}
|
||||||
|
options: dict[str, Any] = {}
|
||||||
|
if token:
|
||||||
|
options[CONF_GITHUB_TOKEN] = token
|
||||||
|
|
||||||
|
return self.async_create_entry(title="Bahmcloud Store", data=data, options=options)
|
||||||
|
|
||||||
|
schema = vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Optional(CONF_GITHUB_TOKEN, default=""): str,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return self.async_show_form(
|
||||||
|
step_id="user",
|
||||||
|
data_schema=schema,
|
||||||
|
description_placeholders={
|
||||||
|
"rate_limit": "GitHub API is rate-limited without a token (recommended for large indexes / HACS).",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def async_get_options_flow(config_entry: config_entries.ConfigEntry):
|
||||||
|
return BCSOptionsFlowHandler(config_entry)
|
||||||
|
|
||||||
|
|
||||||
|
class BCSOptionsFlowHandler(config_entries.OptionsFlow):
|
||||||
|
"""Handle options for Bahmcloud Store."""
|
||||||
|
|
||||||
|
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
|
||||||
|
self.config_entry = config_entry
|
||||||
|
|
||||||
|
async def async_step_init(self, user_input: dict[str, Any] | None = None):
|
||||||
|
if user_input is not None:
|
||||||
|
token = (user_input.get(CONF_GITHUB_TOKEN) or "").strip() or None
|
||||||
|
opts: dict[str, Any] = dict(self.config_entry.options)
|
||||||
|
if token:
|
||||||
|
opts[CONF_GITHUB_TOKEN] = token
|
||||||
|
else:
|
||||||
|
opts.pop(CONF_GITHUB_TOKEN, None)
|
||||||
|
return self.async_create_entry(title="", data=opts)
|
||||||
|
|
||||||
|
cur = (self.config_entry.options.get(CONF_GITHUB_TOKEN) or "").strip()
|
||||||
|
schema = vol.Schema({vol.Optional(CONF_GITHUB_TOKEN, default=cur): str})
|
||||||
|
|
||||||
|
return self.async_show_form(
|
||||||
|
step_id="init",
|
||||||
|
data_schema=schema,
|
||||||
|
description_placeholders={
|
||||||
|
"rate_limit": "Optional. Adds GitHub authorization to avoid rate limits.",
|
||||||
|
},
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user