Add options flow for Recollect Waste (#44234)
* Add options flow for Recollect Waste * Add test * Typing * Typing * Typing AGAIN * Add missing type hints * Code review * Code review * Don't need to block until done
This commit is contained in:
parent
fbc695e5cf
commit
60ecc8282c
6 changed files with 121 additions and 11 deletions
|
@ -1,9 +1,13 @@
|
|||
"""Config flow for ReCollect Waste integration."""
|
||||
from typing import Optional
|
||||
|
||||
from aiorecollect.client import Client
|
||||
from aiorecollect.errors import RecollectError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_FRIENDLY_NAME
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
|
||||
from .const import ( # pylint:disable=unused-import
|
||||
|
@ -24,6 +28,14 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
VERSION = 1
|
||||
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL
|
||||
|
||||
@staticmethod
|
||||
@callback
|
||||
def async_get_options_flow(
|
||||
config_entry: config_entries.ConfigEntry,
|
||||
) -> config_entries.OptionsFlow:
|
||||
"""Define the config flow to handle options."""
|
||||
return RecollectWasteOptionsFlowHandler(config_entry)
|
||||
|
||||
async def async_step_import(self, import_config: dict = None) -> dict:
|
||||
"""Handle configuration via YAML import."""
|
||||
return await self.async_step_user(import_config)
|
||||
|
@ -62,3 +74,28 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
CONF_SERVICE_ID: user_input[CONF_SERVICE_ID],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class RecollectWasteOptionsFlowHandler(config_entries.OptionsFlow):
|
||||
"""Handle a Recollect Waste options flow."""
|
||||
|
||||
def __init__(self, entry: config_entries.ConfigEntry):
|
||||
"""Initialize."""
|
||||
self._entry = entry
|
||||
|
||||
async def async_step_init(self, user_input: Optional[dict] = None):
|
||||
"""Manage the options."""
|
||||
if user_input is not None:
|
||||
return self.async_create_entry(title="", data=user_input)
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="init",
|
||||
data_schema=vol.Schema(
|
||||
{
|
||||
vol.Optional(
|
||||
CONF_FRIENDLY_NAME,
|
||||
default=self._entry.options.get(CONF_FRIENDLY_NAME),
|
||||
): bool
|
||||
}
|
||||
),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue