Merge pull request #1 from schizza/Developer-debug
Initial config and ConfigFlow update.pull/3/head
commit
400b449e44
|
|
@ -1,4 +1,6 @@
|
|||
"""Config flow for Sencor SWS 12500 Weather Station integration."""
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
|
|
@ -8,6 +10,7 @@ from homeassistant.exceptions import HomeAssistantError
|
|||
from .const import (
|
||||
API_ID,
|
||||
API_KEY,
|
||||
DEV_DBG,
|
||||
DOMAIN,
|
||||
INVALID_CREDENTIALS,
|
||||
WINDY_API_KEY,
|
||||
|
|
@ -15,13 +18,6 @@ from .const import (
|
|||
WINDY_LOGGER_ENABLED,
|
||||
)
|
||||
|
||||
STEP_USER_DATA_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(API_ID, default="API ID"): str,
|
||||
vol.Required(API_KEY, default="API KEY"): str,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class CannotConnect(HomeAssistantError):
|
||||
"""We can not connect. - not used in push mechanism."""
|
||||
|
|
@ -32,12 +28,41 @@ class InvalidAuth(HomeAssistantError):
|
|||
|
||||
|
||||
class ConfigOptionsFlowHandler(config_entries.OptionsFlow):
|
||||
"""Handle WeatherStation options."""
|
||||
"""Handle WeatherStation ConfigFlow."""
|
||||
|
||||
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
|
||||
"""Initialize options flow."""
|
||||
"""Initialize flow."""
|
||||
self.config_entry = config_entry
|
||||
|
||||
self.user_data: dict[str, str] = {
|
||||
API_ID: self.config_entry.options.get(API_ID),
|
||||
API_KEY: self.config_entry.options.get(API_KEY),
|
||||
DEV_DBG: self.config_entry.options.get(DEV_DBG),
|
||||
}
|
||||
|
||||
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) if isinstance(self.config_entry.options.get(WINDY_ENABLED), bool) else False,
|
||||
WINDY_LOGGER_ENABLED: self.config_entry.options.get(WINDY_LOGGER_ENABLED) if isinstance(self.config_entry.options.get(WINDY_LOGGER_ENABLED), bool) else False,
|
||||
}
|
||||
|
||||
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(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 ""
|
||||
): str,
|
||||
vol.Optional(WINDY_ENABLED, default=self.windy_data[WINDY_ENABLED]): bool,
|
||||
vol.Optional(
|
||||
WINDY_LOGGER_ENABLED,
|
||||
default=self.windy_data[WINDY_LOGGER_ENABLED],
|
||||
): bool,
|
||||
}
|
||||
|
||||
async def async_step_init(self, user_input=None):
|
||||
"""Manage the options - show menu first."""
|
||||
return self.async_show_menu(step_id="init", menu_options=["basic", "windy"])
|
||||
|
|
@ -46,25 +71,17 @@ class ConfigOptionsFlowHandler(config_entries.OptionsFlow):
|
|||
"""Manage basic options - credentials."""
|
||||
errors = {}
|
||||
|
||||
api_id = self.config_entry.options.get(API_ID)
|
||||
api_key = self.config_entry.options.get(API_KEY)
|
||||
|
||||
OPTIONAL_USER_DATA_SCHEMA = vol.Schema( # pylint: disable=invalid-name
|
||||
{
|
||||
vol.Required(API_ID, default=api_id): str,
|
||||
vol.Required(API_KEY, default=api_key): str,
|
||||
}
|
||||
)
|
||||
|
||||
if user_input is None:
|
||||
return self.async_show_form(
|
||||
step_id="basic", data_schema=OPTIONAL_USER_DATA_SCHEMA, errors=errors
|
||||
step_id="basic",
|
||||
data_schema=vol.Schema(self.user_data_schema),
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
if user_input[API_ID] in INVALID_CREDENTIALS:
|
||||
errors["base"] = "valid_credentials_api"
|
||||
errors[API_ID] = "valid_credentials_api"
|
||||
elif user_input[API_KEY] in INVALID_CREDENTIALS:
|
||||
errors["base"] = "valid_credentials_key"
|
||||
errors[API_KEY] = "valid_credentials_key"
|
||||
elif user_input[API_KEY] == user_input[API_ID]:
|
||||
errors["base"] = "valid_credentials_match"
|
||||
else:
|
||||
|
|
@ -76,55 +93,58 @@ class ConfigOptionsFlowHandler(config_entries.OptionsFlow):
|
|||
WINDY_LOGGER_ENABLED
|
||||
)
|
||||
|
||||
data.update(user_input)
|
||||
# retain windy data
|
||||
user_input.update(self.windy_data)
|
||||
|
||||
return self.async_create_entry(title=DOMAIN, data=data)
|
||||
return self.async_create_entry(title=DOMAIN, data=user_input)
|
||||
|
||||
self.user_data = user_input
|
||||
|
||||
# we are ending with error msg, reshow form
|
||||
return self.async_show_form(
|
||||
step_id="basic", data_schema=OPTIONAL_USER_DATA_SCHEMA, errors=errors
|
||||
step_id="basic",
|
||||
data_schema=vol.Schema(self.user_data_schema),
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_windy(self, user_input=None):
|
||||
"""Manage windy options."""
|
||||
errors = {}
|
||||
|
||||
windy_key = self.config_entry.options.get(WINDY_API_KEY)
|
||||
windy_enabled = self.config_entry.options.get(WINDY_ENABLED)
|
||||
windy_logger_enabled = self.config_entry.options.get(WINDY_LOGGER_ENABLED)
|
||||
|
||||
OPTIONAL_USER_DATA_SCHEMA = vol.Schema( # pylint: disable=invalid-name
|
||||
{
|
||||
vol.Optional(WINDY_API_KEY, default=windy_key): str,
|
||||
vol.Optional(WINDY_ENABLED, default=windy_enabled): bool,
|
||||
vol.Optional(WINDY_LOGGER_ENABLED, default=windy_logger_enabled): bool,
|
||||
}
|
||||
)
|
||||
|
||||
if user_input is None:
|
||||
return self.async_show_form(
|
||||
step_id="windy", data_schema=OPTIONAL_USER_DATA_SCHEMA, errors=errors
|
||||
step_id="windy",
|
||||
data_schema=vol.Schema(self.windy_data_schema),
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
if (user_input[WINDY_ENABLED] is True) and (user_input[WINDY_API_KEY] == ""):
|
||||
errors["base"] = "windy_key_required"
|
||||
errors[WINDY_API_KEY] = "windy_key_required"
|
||||
return self.async_show_form(
|
||||
step_id="windy", data_schema=OPTIONAL_USER_DATA_SCHEMA, errors=errors
|
||||
step_id="windy",
|
||||
data_schema=self.windy_data_schema,
|
||||
description_placeholders={
|
||||
WINDY_ENABLED: True,
|
||||
WINDY_LOGGER_ENABLED: user_input[WINDY_LOGGER_ENABLED],
|
||||
},
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
# retain API_ID and API_KEY from config
|
||||
data: dict = {}
|
||||
data[API_ID] = self.config_entry.options.get(API_ID)
|
||||
data[API_KEY] = self.config_entry.options.get(API_KEY)
|
||||
# retain user_data
|
||||
user_input.update(self.user_data)
|
||||
|
||||
data.update(user_input)
|
||||
|
||||
return self.async_create_entry(title=DOMAIN, data=data)
|
||||
return self.async_create_entry(title=DOMAIN, data=user_input)
|
||||
|
||||
|
||||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow for Sencor SWS 12500 Weather Station."""
|
||||
|
||||
data_schema = {
|
||||
vol.Required(API_ID): str,
|
||||
vol.Required(API_KEY): str,
|
||||
vol.Optional(DEV_DBG): bool,
|
||||
}
|
||||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
|
|
@ -134,24 +154,25 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
self._abort_if_unique_id_configured()
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=STEP_USER_DATA_SCHEMA
|
||||
step_id="user",
|
||||
data_schema=vol.Schema(self.data_schema),
|
||||
)
|
||||
|
||||
errors = {}
|
||||
|
||||
if user_input[API_ID] in INVALID_CREDENTIALS:
|
||||
errors["base"] = "valid_credentials_api"
|
||||
errors[API_ID] = "valid_credentials_api"
|
||||
elif user_input[API_KEY] in INVALID_CREDENTIALS:
|
||||
errors["base"] = "valid_credentials_key"
|
||||
errors[API_KEY] = "valid_credentials_key"
|
||||
elif user_input[API_KEY] == user_input[API_ID]:
|
||||
errors["base"] = "valid_credentials_match"
|
||||
else:
|
||||
return self.async_create_entry(
|
||||
title=DOMAIN, data=user_input, options=user_input
|
||||
)
|
||||
return self.async_create_entry(title=DOMAIN, data=user_input, options=user_input)
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
|
||||
step_id="user",
|
||||
data_schema=vol.Schema(self.data_schema),
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
|||
|
|
@ -10,10 +10,12 @@ ICON = "mdi:weather"
|
|||
|
||||
API_KEY = "API_KEY"
|
||||
API_ID = "API_ID"
|
||||
|
||||
DEV_DBG: Final = "dev_debug_checkbox"
|
||||
|
||||
WINDY_API_KEY = "WINDY_API_KEY"
|
||||
WINDY_ENABLED: Final = "windy_enabled_checkbox"
|
||||
WINDY_LOGGER_ENABLED: Final = "windy_logger_checkbox"
|
||||
|
||||
WINDY_NOT_INSERTED: Final = "Data was succefuly sent to Windy, but not inserted by Windy API. Does anyone else sent data to Windy?"
|
||||
WINDY_INVALID_KEY: Final = "Windy API KEY is invalid. Send data to Windy is now disabled. Check your API KEY and try again."
|
||||
WINDY_SUCCESS: Final = (
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@
|
|||
"iot_class": "local_push",
|
||||
"requirements": [],
|
||||
"ssdp": [],
|
||||
"version": "0.0.2",
|
||||
"version": "0.1.1",
|
||||
"zeroconf": []
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@ from typing import Any
|
|||
|
||||
from homeassistant.components.sensor import (
|
||||
SensorDeviceClass,
|
||||
SensorEntityDescription,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
UnitOfIrradiance,
|
||||
|
|
@ -17,7 +16,6 @@ from homeassistant.const import (
|
|||
UnitOfSpeed,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
|
|
|||
|
|
@ -1,54 +1,62 @@
|
|||
{
|
||||
"config": {
|
||||
"step": {
|
||||
"user": {
|
||||
"title": "Configure access for Weather Station",
|
||||
"description": "Provide API ID and API KEY so the Weather Station can access HomeAssistant",
|
||||
"data": {
|
||||
"api_id": "API ID / Station ID",
|
||||
"api_key": "API KEY / Password"
|
||||
}
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"valid_credentials_api": "Provide valid API ID.",
|
||||
"valid_credentials_key": "Provide valid API KEY.",
|
||||
"valid_credentials_match": "API ID and API KEY should not be the same."
|
||||
},
|
||||
"step": {
|
||||
"user": {
|
||||
"data": {
|
||||
"API_ID": "API ID / Station ID",
|
||||
"API_KEY": "API KEY / Password",
|
||||
"dev_debug_checkbox": "Developer log"
|
||||
},
|
||||
"description": "Provide API ID and API KEY so the Weather Station can access HomeAssistant",
|
||||
"title": "Configure access for Weather Station",
|
||||
"data_description": {
|
||||
"dev_debug_checkbox": " Enable only if you want to send debuging data to the developer."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"step": {
|
||||
"init": {
|
||||
"title": "Configure SWS12500 Integration",
|
||||
"description": "Choose what do you want to configure. If basic access or resending data for Windy site",
|
||||
"menu_options": {
|
||||
"basic": "Basic - configure credentials for Weather Station",
|
||||
"windy": "Windy configuration"
|
||||
}
|
||||
},
|
||||
"basic": {
|
||||
"title": "Configure credentials",
|
||||
"description": "Provide API ID and API KEY so the Weather Station can access HomeAssistant",
|
||||
"data": {
|
||||
"API_ID": "API ID / Station ID",
|
||||
"API_KEY": "API KEY / Password"
|
||||
}
|
||||
},
|
||||
"windy": {
|
||||
"title": "Configure Windy",
|
||||
"description": "Resend weather data to your Windy stations.",
|
||||
"data": {
|
||||
"WINDY_API_KEY": "API KEY provided by Windy",
|
||||
"windy_enabled_checkbox": "Enable resending data to Windy",
|
||||
"windy_logger_checkbox": "Log Windy data and responses"
|
||||
}
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"valid_credentials_api": "Provide valid API ID.",
|
||||
"valid_credentials_key": "Provide valid API KEY.",
|
||||
"valid_credentials_match": "API ID and API KEY should not be the same.",
|
||||
"windy_key_required": "Windy API key is required if you want to enable this function."
|
||||
},
|
||||
"step": {
|
||||
"basic": {
|
||||
"data": {
|
||||
"API_ID": "API ID / Station ID",
|
||||
"API_KEY": "API KEY / Password",
|
||||
"dev_debug_checkbox": "Developer log"
|
||||
},
|
||||
"description": "Provide API ID and API KEY so the Weather Station can access HomeAssistant",
|
||||
"title": "Configure credentials",
|
||||
"data_description": {
|
||||
"dev_debug_checkbox": " Enable only if you want to send debuging data to the developer."
|
||||
}
|
||||
},
|
||||
"init": {
|
||||
"description": "Choose what do you want to configure. If basic access or resending data for Windy site",
|
||||
"menu_options": {
|
||||
"basic": "Basic - configure credentials for Weather Station",
|
||||
"windy": "Windy configuration"
|
||||
},
|
||||
"title": "Configure SWS12500 Integration"
|
||||
},
|
||||
"windy": {
|
||||
"data": {
|
||||
"WINDY_API_KEY": "API KEY provided by Windy",
|
||||
"windy_enabled_checkbox": "Enable resending data to Windy",
|
||||
"windy_logger_checkbox": "Log Windy data and responses"
|
||||
},
|
||||
"description": "Resend weather data to your Windy stations.",
|
||||
"title": "Configure Windy"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,15 @@
|
|||
"step": {
|
||||
"user": {
|
||||
"data": {
|
||||
"api_id": "API ID / Station ID",
|
||||
"api_key": "API KEY / Password"
|
||||
"API_ID": "API ID / Station ID",
|
||||
"API_KEY": "API KEY / Password",
|
||||
"dev_debug_checkbox": "Developer"
|
||||
},
|
||||
"description": "Provide API ID and API KEY so the Weather Station can access HomeAssistant",
|
||||
"title": "Configure access for Weather Station"
|
||||
"title": "Configure access for Weather Station",
|
||||
"data_description": {
|
||||
"dev_debug_checkbox": " Enable only if you want to send debuging data to the developer."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -27,10 +31,15 @@
|
|||
"basic": {
|
||||
"data": {
|
||||
"API_ID": "API ID / Station ID",
|
||||
"API_KEY": "API KEY / Password"
|
||||
"API_KEY": "API KEY / Password",
|
||||
"dev_debug_checkbox": "Developer"
|
||||
},
|
||||
"description": "Provide API ID and API KEY so the Weather Station can access HomeAssistant",
|
||||
"title": "Configure credentials"
|
||||
"title": "Configure credentials",
|
||||
"data_description": {
|
||||
"api_id": "data desc.",
|
||||
"dev_debug_checkbox": " Enable only if you want to send debuging data to the developer."
|
||||
}
|
||||
},
|
||||
"init": {
|
||||
"description": "Choose what do you want to configure. If basic access or resending data for Windy site",
|
||||
|
|
|
|||
Loading…
Reference in New Issue