Skip to content
Snippets Groups Projects
Unverified Commit a5c45085 authored by Ville Skyttä's avatar Ville Skyttä Committed by GitHub
Browse files

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
parent f56797e4
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
"step": { "step": {
"init": { "init": {
"data": { "data": {
"name": "Notification service name",
"recipient": "SMS notification recipients", "recipient": "SMS notification recipients",
"track_new_devices": "Track new devices" "track_new_devices": "Track new devices"
} }
......
...@@ -28,6 +28,7 @@ from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN ...@@ -28,6 +28,7 @@ from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
CONF_NAME,
CONF_PASSWORD, CONF_PASSWORD,
CONF_RECIPIENT, CONF_RECIPIENT,
CONF_URL, CONF_URL,
...@@ -54,6 +55,7 @@ from .const import ( ...@@ -54,6 +55,7 @@ from .const import (
ALL_KEYS, ALL_KEYS,
CONNECTION_TIMEOUT, CONNECTION_TIMEOUT,
DEFAULT_DEVICE_NAME, DEFAULT_DEVICE_NAME,
DEFAULT_NOTIFY_SERVICE_NAME,
DOMAIN, DOMAIN,
KEY_DEVICE_BASIC_INFORMATION, KEY_DEVICE_BASIC_INFORMATION,
KEY_DEVICE_INFORMATION, KEY_DEVICE_INFORMATION,
...@@ -82,9 +84,10 @@ NOTIFY_SCHEMA = vol.Any( ...@@ -82,9 +84,10 @@ NOTIFY_SCHEMA = vol.Any(
None, None,
vol.Schema( vol.Schema(
{ {
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_RECIPIENT): vol.Any( vol.Optional(CONF_RECIPIENT): vol.Any(
None, vol.All(cv.ensure_list, [cv.string]) None, vol.All(cv.ensure_list, [cv.string])
) ),
} }
), ),
) )
...@@ -262,6 +265,13 @@ async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry) ...@@ -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[f"{CONF_RECIPIENT}_from_yaml"] = yaml_recipient
new_options[CONF_RECIPIENT] = 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 # Update entry if overrides were found
if new_data or new_options: if new_data or new_options:
hass.config_entries.async_update_entry( hass.config_entries.async_update_entry(
...@@ -353,7 +363,11 @@ async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry) ...@@ -353,7 +363,11 @@ async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry)
hass, hass,
NOTIFY_DOMAIN, NOTIFY_DOMAIN,
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, hass.data[DOMAIN].hass_config,
) )
......
...@@ -21,11 +21,17 @@ import voluptuous as vol ...@@ -21,11 +21,17 @@ import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components import ssdp 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 from homeassistant.core import callback
# see https://github.com/PyCQA/pylint/issues/3202 about the DOMAIN's pylint issue # 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 from .const import DOMAIN # pylint: disable=unused-import
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
...@@ -246,10 +252,16 @@ class OptionsFlowHandler(config_entries.OptionsFlow): ...@@ -246,10 +252,16 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
data_schema = vol.Schema( data_schema = vol.Schema(
{ {
vol.Optional(
CONF_NAME,
default=self.config_entry.options.get(
CONF_NAME, DEFAULT_NOTIFY_SERVICE_NAME
),
): str,
vol.Optional( vol.Optional(
CONF_RECIPIENT, CONF_RECIPIENT,
default=self.config_entry.options.get(CONF_RECIPIENT, ""), default=self.config_entry.options.get(CONF_RECIPIENT, ""),
): str ): str,
} }
) )
return self.async_show_form(step_id="init", data_schema=data_schema) return self.async_show_form(step_id="init", data_schema=data_schema)
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
DOMAIN = "huawei_lte" DOMAIN = "huawei_lte"
DEFAULT_DEVICE_NAME = "LTE" DEFAULT_DEVICE_NAME = "LTE"
DEFAULT_NOTIFY_SERVICE_NAME = DOMAIN
UPDATE_SIGNAL = f"{DOMAIN}_update" UPDATE_SIGNAL = f"{DOMAIN}_update"
UPDATE_OPTIONS_SIGNAL = f"{DOMAIN}_options_update" UPDATE_OPTIONS_SIGNAL = f"{DOMAIN}_options_update"
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
"step": { "step": {
"init": { "init": {
"data": { "data": {
"name": "Notification service name",
"recipient": "SMS notification recipients", "recipient": "SMS notification recipients",
"track_new_devices": "Track new devices" "track_new_devices": "Track new devices"
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment