Fix config deprecation
Updated config flow to comply with new changes in HApull/45/head
parent
25bb26bb4d
commit
d9cb2179d5
|
|
@ -4,7 +4,7 @@ from typing import Any
|
|||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.config_entries import ConfigFlow, OptionsFlow
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
||||
|
|
@ -30,12 +30,25 @@ class InvalidAuth(HomeAssistantError):
|
|||
"""Invalid auth exception."""
|
||||
|
||||
|
||||
class ConfigOptionsFlowHandler(config_entries.OptionsFlow):
|
||||
class ConfigOptionsFlowHandler(OptionsFlow):
|
||||
"""Handle WeatherStation ConfigFlow."""
|
||||
|
||||
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
|
||||
def __init__(self) -> None:
|
||||
"""Initialize flow."""
|
||||
self.config_entry = config_entry
|
||||
super().__init__()
|
||||
|
||||
self.windy_data: dict[str, Any] = {}
|
||||
self.windy_data_schema = {}
|
||||
self.user_data: dict[str, str] = {}
|
||||
self.user_data_schema = {}
|
||||
self.sensors: dict[str, Any] = {}
|
||||
|
||||
@property
|
||||
def config_entry(self):
|
||||
return self.hass.config_entries.async_get_entry(self.handler)
|
||||
|
||||
def _get_entry_data(self):
|
||||
"""Get entry data."""
|
||||
|
||||
self.user_data: dict[str, str] = {
|
||||
API_ID: self.config_entry.options.get(API_ID),
|
||||
|
|
@ -44,6 +57,19 @@ class ConfigOptionsFlowHandler(config_entries.OptionsFlow):
|
|||
DEV_DBG: self.config_entry.options.get(DEV_DBG),
|
||||
}
|
||||
|
||||
self.user_data_schema = {
|
||||
vol.Required(API_ID, default=self.user_data[API_ID] or ""): str,
|
||||
vol.Required(API_KEY, default=self.user_data[API_KEY] or ""): str,
|
||||
vol.Optional(WSLINK, default=self.user_data[WSLINK]): bool,
|
||||
vol.Optional(DEV_DBG, default=self.user_data[DEV_DBG]): bool,
|
||||
}
|
||||
|
||||
self.sensors: dict[str, Any] = {
|
||||
SENSORS_TO_LOAD: self.config_entry.options.get(SENSORS_TO_LOAD)
|
||||
if isinstance(self.config_entry.options.get(SENSORS_TO_LOAD), list)
|
||||
else []
|
||||
}
|
||||
|
||||
self.windy_data: dict[str, Any] = {
|
||||
WINDY_API_KEY: self.config_entry.options.get(WINDY_API_KEY),
|
||||
WINDY_ENABLED: self.config_entry.options.get(WINDY_ENABLED)
|
||||
|
|
@ -54,19 +80,6 @@ class ConfigOptionsFlowHandler(config_entries.OptionsFlow):
|
|||
else False,
|
||||
}
|
||||
|
||||
self.sensors: dict[str, Any] = {
|
||||
SENSORS_TO_LOAD: self.config_entry.options.get(SENSORS_TO_LOAD)
|
||||
if isinstance(self.config_entry.options.get(SENSORS_TO_LOAD), list)
|
||||
else []
|
||||
}
|
||||
|
||||
self.user_data_schema = {
|
||||
vol.Required(API_ID, default=self.user_data[API_ID] or ""): str,
|
||||
vol.Required(API_KEY, default=self.user_data[API_KEY] or ""): str,
|
||||
vol.Optional(WSLINK, default=self.user_data[WSLINK]): bool,
|
||||
vol.Optional(DEV_DBG, default=self.user_data[DEV_DBG]): bool,
|
||||
}
|
||||
|
||||
self.windy_data_schema = {
|
||||
vol.Optional(
|
||||
WINDY_API_KEY, default=self.windy_data[WINDY_API_KEY] or ""
|
||||
|
|
@ -86,6 +99,8 @@ class ConfigOptionsFlowHandler(config_entries.OptionsFlow):
|
|||
"""Manage basic options - credentials."""
|
||||
errors = {}
|
||||
|
||||
self._get_entry_data()
|
||||
|
||||
if user_input is None:
|
||||
return self.async_show_form(
|
||||
step_id="basic",
|
||||
|
|
@ -121,6 +136,8 @@ class ConfigOptionsFlowHandler(config_entries.OptionsFlow):
|
|||
"""Manage windy options."""
|
||||
errors = {}
|
||||
|
||||
self._get_entry_data()
|
||||
|
||||
if user_input is None:
|
||||
return self.async_show_form(
|
||||
step_id="windy",
|
||||
|
|
@ -149,7 +166,7 @@ class ConfigOptionsFlowHandler(config_entries.OptionsFlow):
|
|||
return self.async_create_entry(title=DOMAIN, data=user_input)
|
||||
|
||||
|
||||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
class ConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow for Sencor SWS 12500 Weather Station."""
|
||||
|
||||
data_schema = {
|
||||
|
|
@ -191,10 +208,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
errors=errors,
|
||||
)
|
||||
|
||||
|
||||
@staticmethod
|
||||
@callback
|
||||
def async_get_options_flow(
|
||||
config_entry: config_entries.ConfigEntry,
|
||||
) -> ConfigOptionsFlowHandler:
|
||||
def async_get_options_flow(config_entry) -> ConfigOptionsFlowHandler:
|
||||
"""Get the options flow for this handler."""
|
||||
return ConfigOptionsFlowHandler(config_entry)
|
||||
return ConfigOptionsFlowHandler()
|
||||
|
|
|
|||
Loading…
Reference in New Issue