Make Huawei LTE notify service name configurable (#30208)

* Default Huawei LTE notify service name to notify.huawei_lte, make configurable

Closes https://github.com/home-assistant/home-assistant/issues/29409

* Set default notify service name for uninvoked options flow
This commit is contained in:
Ville Skyttä 2019-12-25 13:42:28 +02:00 committed by GitHub
parent f56797e413
commit a5c4508571
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 5 deletions

View File

@ -33,6 +33,7 @@
"step": {
"init": {
"data": {
"name": "Notification service name",
"recipient": "SMS notification recipients",
"track_new_devices": "Track new devices"
}

View File

@ -28,6 +28,7 @@ from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import (
CONF_NAME,
CONF_PASSWORD,
CONF_RECIPIENT,
CONF_URL,
@ -54,6 +55,7 @@ from .const import (
ALL_KEYS,
CONNECTION_TIMEOUT,
DEFAULT_DEVICE_NAME,
DEFAULT_NOTIFY_SERVICE_NAME,
DOMAIN,
KEY_DEVICE_BASIC_INFORMATION,
KEY_DEVICE_INFORMATION,
@ -82,9 +84,10 @@ NOTIFY_SCHEMA = vol.Any(
None,
vol.Schema(
{
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_RECIPIENT): vol.Any(
None, vol.All(cv.ensure_list, [cv.string])
)
),
}
),
)
@ -262,6 +265,13 @@ async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry)
):
new_options[f"{CONF_RECIPIENT}_from_yaml"] = yaml_recipient
new_options[CONF_RECIPIENT] = yaml_recipient
yaml_notify_name = yaml_config.get(NOTIFY_DOMAIN, {}).get(CONF_NAME)
if (
yaml_notify_name is not None
and yaml_notify_name != config_entry.options.get(f"{CONF_NAME}_from_yaml")
):
new_options[f"{CONF_NAME}_from_yaml"] = yaml_notify_name
new_options[CONF_NAME] = yaml_notify_name
# Update entry if overrides were found
if new_data or new_options:
hass.config_entries.async_update_entry(
@ -353,7 +363,11 @@ async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry)
hass,
NOTIFY_DOMAIN,
DOMAIN,
{CONF_URL: url, CONF_RECIPIENT: config_entry.options.get(CONF_RECIPIENT)},
{
CONF_URL: url,
CONF_NAME: config_entry.options.get(CONF_NAME, DEFAULT_NOTIFY_SERVICE_NAME),
CONF_RECIPIENT: config_entry.options.get(CONF_RECIPIENT),
},
hass.data[DOMAIN].hass_config,
)

View File

@ -21,11 +21,17 @@ import voluptuous as vol
from homeassistant import config_entries
from homeassistant.components import ssdp
from homeassistant.const import CONF_PASSWORD, CONF_RECIPIENT, CONF_URL, CONF_USERNAME
from homeassistant.const import (
CONF_NAME,
CONF_PASSWORD,
CONF_RECIPIENT,
CONF_URL,
CONF_USERNAME,
)
from homeassistant.core import callback
# see https://github.com/PyCQA/pylint/issues/3202 about the DOMAIN's pylint issue
from .const import CONNECTION_TIMEOUT, DEFAULT_DEVICE_NAME
from .const import CONNECTION_TIMEOUT, DEFAULT_DEVICE_NAME, DEFAULT_NOTIFY_SERVICE_NAME
from .const import DOMAIN # pylint: disable=unused-import
_LOGGER = logging.getLogger(__name__)
@ -246,10 +252,16 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
data_schema = vol.Schema(
{
vol.Optional(
CONF_NAME,
default=self.config_entry.options.get(
CONF_NAME, DEFAULT_NOTIFY_SERVICE_NAME
),
): str,
vol.Optional(
CONF_RECIPIENT,
default=self.config_entry.options.get(CONF_RECIPIENT, ""),
): str
): str,
}
)
return self.async_show_form(step_id="init", data_schema=data_schema)

View File

@ -3,6 +3,7 @@
DOMAIN = "huawei_lte"
DEFAULT_DEVICE_NAME = "LTE"
DEFAULT_NOTIFY_SERVICE_NAME = DOMAIN
UPDATE_SIGNAL = f"{DOMAIN}_update"
UPDATE_OPTIONS_SIGNAL = f"{DOMAIN}_options_update"

View File

@ -33,6 +33,7 @@
"step": {
"init": {
"data": {
"name": "Notification service name",
"recipient": "SMS notification recipients",
"track_new_devices": "Track new devices"
}