mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Remove Netgear LTE yaml import (#119180)
Remove Netgear LTE yaml config
This commit is contained in:
parent
b577ce61b8
commit
a38d88730d
@ -5,25 +5,21 @@ from datetime import timedelta
|
||||
from aiohttp.cookiejar import CookieJar
|
||||
import attr
|
||||
import eternalegypt
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry, ConfigEntryState
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_RECIPIENT,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, Event, HomeAssistant
|
||||
from homeassistant.core import Event, HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import config_validation as cv, discovery
|
||||
from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import (
|
||||
@ -31,9 +27,6 @@ from .const import (
|
||||
ATTR_HOST,
|
||||
ATTR_MESSAGE,
|
||||
ATTR_SMS_ID,
|
||||
CONF_BINARY_SENSOR,
|
||||
CONF_NOTIFY,
|
||||
CONF_SENSOR,
|
||||
DATA_HASS_CONFIG,
|
||||
DISPATCHER_NETGEAR_LTE,
|
||||
DOMAIN,
|
||||
@ -67,60 +60,14 @@ ALL_BINARY_SENSORS = [
|
||||
"mobile_connected",
|
||||
]
|
||||
|
||||
|
||||
NOTIFY_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_NAME, default=DOMAIN): cv.string,
|
||||
vol.Optional(CONF_RECIPIENT, default=[]): vol.All(cv.ensure_list, [cv.string]),
|
||||
}
|
||||
)
|
||||
|
||||
SENSOR_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_MONITORED_CONDITIONS, default=["usage"]): vol.All(
|
||||
cv.ensure_list, [vol.In(ALL_SENSORS)]
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
BINARY_SENSOR_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_MONITORED_CONDITIONS, default=["mobile_connected"]): vol.All(
|
||||
cv.ensure_list, [vol.In(ALL_BINARY_SENSORS)]
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
DOMAIN: vol.All(
|
||||
cv.ensure_list,
|
||||
[
|
||||
vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(CONF_NOTIFY, default={}): vol.All(
|
||||
cv.ensure_list, [NOTIFY_SCHEMA]
|
||||
),
|
||||
vol.Optional(CONF_SENSOR, default={}): SENSOR_SCHEMA,
|
||||
vol.Optional(
|
||||
CONF_BINARY_SENSOR, default={}
|
||||
): BINARY_SENSOR_SCHEMA,
|
||||
}
|
||||
)
|
||||
],
|
||||
)
|
||||
},
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
PLATFORMS = [
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.NOTIFY,
|
||||
Platform.SENSOR,
|
||||
]
|
||||
|
||||
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
|
||||
|
||||
|
||||
@attr.s
|
||||
class ModemData:
|
||||
@ -170,44 +117,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up Netgear LTE component."""
|
||||
hass.data[DATA_HASS_CONFIG] = config
|
||||
|
||||
if lte_config := config.get(DOMAIN):
|
||||
hass.async_create_task(import_yaml(hass, lte_config))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def import_yaml(hass: HomeAssistant, lte_config: ConfigType) -> None:
|
||||
"""Import yaml if we can connect. Create appropriate issue registry entries."""
|
||||
for entry in lte_config:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=entry
|
||||
)
|
||||
if result.get("reason") == "cannot_connect":
|
||||
async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
"import_failure",
|
||||
is_fixable=False,
|
||||
severity=IssueSeverity.ERROR,
|
||||
translation_key="import_failure",
|
||||
)
|
||||
else:
|
||||
async_create_issue(
|
||||
hass,
|
||||
HOMEASSISTANT_DOMAIN,
|
||||
f"deprecated_yaml_{DOMAIN}",
|
||||
breaks_in_ha_version="2024.7.0",
|
||||
is_fixable=False,
|
||||
issue_domain=DOMAIN,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_yaml",
|
||||
translation_placeholders={
|
||||
"domain": DOMAIN,
|
||||
"integration_title": "Netgear LTE",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Netgear LTE from a config entry."""
|
||||
host = entry.data[CONF_HOST]
|
||||
@ -241,7 +153,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
await async_setup_services(hass)
|
||||
|
||||
_legacy_task(hass, entry)
|
||||
await discovery.async_load_platform(
|
||||
hass,
|
||||
Platform.NOTIFY,
|
||||
DOMAIN,
|
||||
{CONF_HOST: entry.data[CONF_HOST], CONF_NAME: entry.title},
|
||||
hass.data[DATA_HASS_CONFIG],
|
||||
)
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(
|
||||
entry, [platform for platform in PLATFORMS if platform != Platform.NOTIFY]
|
||||
@ -285,64 +203,3 @@ async def _login(hass: HomeAssistant, modem_data: ModemData, password: str) -> N
|
||||
|
||||
await modem_data.async_update()
|
||||
hass.data[DOMAIN].modem_data[modem_data.host] = modem_data
|
||||
|
||||
|
||||
def _legacy_task(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
"""Create notify service and add a repair issue when appropriate."""
|
||||
# Discovery can happen up to 2 times for notify depending on existing yaml config
|
||||
# One for the name of the config entry, allows the user to customize the name
|
||||
# One for each notify described in the yaml config which goes away with config flow
|
||||
# One for the default if the user never specified one
|
||||
hass.async_create_task(
|
||||
discovery.async_load_platform(
|
||||
hass,
|
||||
Platform.NOTIFY,
|
||||
DOMAIN,
|
||||
{CONF_HOST: entry.data[CONF_HOST], CONF_NAME: entry.title},
|
||||
hass.data[DATA_HASS_CONFIG],
|
||||
)
|
||||
)
|
||||
if not (lte_configs := hass.data[DATA_HASS_CONFIG].get(DOMAIN, [])):
|
||||
return
|
||||
async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
"deprecated_notify",
|
||||
breaks_in_ha_version="2024.7.0",
|
||||
is_fixable=False,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_notify",
|
||||
translation_placeholders={
|
||||
"name": f"{Platform.NOTIFY}.{entry.title.lower().replace(' ', '_')}"
|
||||
},
|
||||
)
|
||||
|
||||
for lte_config in lte_configs:
|
||||
if lte_config[CONF_HOST] == entry.data[CONF_HOST]:
|
||||
if not lte_config[CONF_NOTIFY]:
|
||||
hass.async_create_task(
|
||||
discovery.async_load_platform(
|
||||
hass,
|
||||
Platform.NOTIFY,
|
||||
DOMAIN,
|
||||
{CONF_HOST: entry.data[CONF_HOST], CONF_NAME: DOMAIN},
|
||||
hass.data[DATA_HASS_CONFIG],
|
||||
)
|
||||
)
|
||||
break
|
||||
for notify_conf in lte_config[CONF_NOTIFY]:
|
||||
discovery_info = {
|
||||
CONF_HOST: lte_config[CONF_HOST],
|
||||
CONF_NAME: notify_conf.get(CONF_NAME),
|
||||
CONF_NOTIFY: notify_conf,
|
||||
}
|
||||
hass.async_create_task(
|
||||
discovery.async_load_platform(
|
||||
hass,
|
||||
Platform.NOTIFY,
|
||||
DOMAIN,
|
||||
discovery_info,
|
||||
hass.data[DATA_HASS_CONFIG],
|
||||
)
|
||||
)
|
||||
break
|
||||
|
@ -20,22 +20,6 @@ from .const import DEFAULT_HOST, DOMAIN, LOGGER, MANUFACTURER
|
||||
class NetgearLTEFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow for Netgear LTE."""
|
||||
|
||||
async def async_step_import(self, config: dict[str, Any]) -> ConfigFlowResult:
|
||||
"""Import a configuration from config.yaml."""
|
||||
host = config[CONF_HOST]
|
||||
password = config[CONF_PASSWORD]
|
||||
self._async_abort_entries_match({CONF_HOST: host})
|
||||
try:
|
||||
info = await self._async_validate_input(host, password)
|
||||
except InputValidationError:
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
await self.async_set_unique_id(info.serial_number)
|
||||
self._abort_if_unique_id_configured()
|
||||
return self.async_create_entry(
|
||||
title=f"{MANUFACTURER} {info.items['general.devicename']}",
|
||||
data={CONF_HOST: host, CONF_PASSWORD: password},
|
||||
)
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
|
@ -17,16 +17,6 @@
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"deprecated_notify": {
|
||||
"title": "The Netgear LTE notify service is changing",
|
||||
"description": "The Netgear LTE notify service was previously set up via YAML configuration.\n\nThis created a service for a specified recipient without having to include the phone number.\n\nPlease adjust any automations or scripts you may have to use the `{name}` service and include target for specifying a recipient."
|
||||
},
|
||||
"import_failure": {
|
||||
"title": "The Netgear LTE integration failed to import",
|
||||
"description": "The Netgear LTE notify service was previously set up via YAML configuration.\n\nAn error occurred when trying to communicate with the device while attempting to import the configuration to the UI.\n\nPlease remove the Netgear LTE notify section from your YAML configuration and set it up in the UI instead."
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
"delete_sms": {
|
||||
"name": "Delete SMS",
|
||||
|
@ -2,11 +2,9 @@
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.netgear_lte.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.const import CONF_SOURCE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
@ -41,14 +39,13 @@ async def test_flow_user_form(hass: HomeAssistant, connection: None) -> None:
|
||||
assert result["context"]["unique_id"] == "FFFFFFFFFFFFF"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("source", [SOURCE_USER, SOURCE_IMPORT])
|
||||
async def test_flow_already_configured(
|
||||
hass: HomeAssistant, setup_integration: None, source: str
|
||||
hass: HomeAssistant, setup_integration: None
|
||||
) -> None:
|
||||
"""Test config flow aborts when already configured."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={CONF_SOURCE: source},
|
||||
context={CONF_SOURCE: SOURCE_USER},
|
||||
data=CONF_DATA,
|
||||
)
|
||||
|
||||
@ -84,29 +81,3 @@ async def test_flow_user_unknown_error(hass: HomeAssistant, unknown: None) -> No
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"]["base"] == "unknown"
|
||||
|
||||
|
||||
async def test_flow_import(hass: HomeAssistant, connection: None) -> None:
|
||||
"""Test import step."""
|
||||
with _patch_setup():
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={CONF_SOURCE: SOURCE_IMPORT},
|
||||
data=CONF_DATA,
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == "Netgear LM1200"
|
||||
assert result["data"] == CONF_DATA
|
||||
|
||||
|
||||
async def test_flow_import_failure(hass: HomeAssistant, cannot_connect: None) -> None:
|
||||
"""Test import step failure."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={CONF_SOURCE: SOURCE_IMPORT},
|
||||
data=CONF_DATA,
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "cannot_connect"
|
||||
|
Loading…
x
Reference in New Issue
Block a user