mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 15:57:06 +00:00
Huawei LTE SSDP improvements (#81643)
* Recognize more SSDP friendly names as "ours" * Trigger on SoyeaLink devices * Pass discovered URL through context, it does not persist via user_input * Use manufacturer from SSDP * Actually use serial number if available, update URL for configured * Remove heuristic friendly name filtering against non-LTE devices
This commit is contained in:
parent
9a25e75947
commit
f02b6f1119
@ -56,9 +56,11 @@ from .const import (
|
|||||||
ADMIN_SERVICES,
|
ADMIN_SERVICES,
|
||||||
ALL_KEYS,
|
ALL_KEYS,
|
||||||
ATTR_UNIQUE_ID,
|
ATTR_UNIQUE_ID,
|
||||||
|
CONF_MANUFACTURER,
|
||||||
CONF_UNAUTHENTICATED_MODE,
|
CONF_UNAUTHENTICATED_MODE,
|
||||||
CONNECTION_TIMEOUT,
|
CONNECTION_TIMEOUT,
|
||||||
DEFAULT_DEVICE_NAME,
|
DEFAULT_DEVICE_NAME,
|
||||||
|
DEFAULT_MANUFACTURER,
|
||||||
DEFAULT_NOTIFY_SERVICE_NAME,
|
DEFAULT_NOTIFY_SERVICE_NAME,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
KEY_DEVICE_BASIC_INFORMATION,
|
KEY_DEVICE_BASIC_INFORMATION,
|
||||||
@ -412,9 +414,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
device_info = DeviceInfo(
|
device_info = DeviceInfo(
|
||||||
configuration_url=router.url,
|
configuration_url=router.url,
|
||||||
connections=router.device_connections,
|
connections=router.device_connections,
|
||||||
|
default_manufacturer=DEFAULT_MANUFACTURER,
|
||||||
identifiers=router.device_identifiers,
|
identifiers=router.device_identifiers,
|
||||||
|
manufacturer=entry.data.get(CONF_MANUFACTURER),
|
||||||
name=router.device_name,
|
name=router.device_name,
|
||||||
manufacturer="Huawei",
|
|
||||||
)
|
)
|
||||||
hw_version = None
|
hw_version = None
|
||||||
sw_version = None
|
sw_version = None
|
||||||
|
@ -34,6 +34,7 @@ from homeassistant.core import callback
|
|||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
CONF_MANUFACTURER,
|
||||||
CONF_TRACK_WIRED_CLIENTS,
|
CONF_TRACK_WIRED_CLIENTS,
|
||||||
CONF_UNAUTHENTICATED_MODE,
|
CONF_UNAUTHENTICATED_MODE,
|
||||||
CONNECTION_TIMEOUT,
|
CONNECTION_TIMEOUT,
|
||||||
@ -208,7 +209,12 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
)
|
)
|
||||||
await self.hass.async_add_executor_job(self._logout, conn)
|
await self.hass.async_add_executor_job(self._logout, conn)
|
||||||
|
|
||||||
user_input[CONF_MAC] = get_device_macs(info, wlan_settings)
|
user_input.update(
|
||||||
|
{
|
||||||
|
CONF_MAC: get_device_macs(info, wlan_settings),
|
||||||
|
CONF_MANUFACTURER: self.context.get(CONF_MANUFACTURER),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
if not self.unique_id:
|
if not self.unique_id:
|
||||||
if serial_number := info.get("SerialNumber"):
|
if serial_number := info.get("SerialNumber"):
|
||||||
@ -228,16 +234,6 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
||||||
"""Handle SSDP initiated config flow."""
|
"""Handle SSDP initiated config flow."""
|
||||||
await self.async_set_unique_id(discovery_info.upnp[ssdp.ATTR_UPNP_UDN])
|
|
||||||
self._abort_if_unique_id_configured()
|
|
||||||
|
|
||||||
# Attempt to distinguish from other non-LTE Huawei router devices, at least
|
|
||||||
# some ones we are interested in have "Mobile Wi-Fi" friendlyName.
|
|
||||||
if (
|
|
||||||
"mobile"
|
|
||||||
not in discovery_info.upnp.get(ssdp.ATTR_UPNP_FRIENDLY_NAME, "").lower()
|
|
||||||
):
|
|
||||||
return self.async_abort(reason="not_huawei_lte")
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
assert discovery_info.ssdp_location
|
assert discovery_info.ssdp_location
|
||||||
@ -248,18 +244,22 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if serial_number := discovery_info.upnp.get(ssdp.ATTR_UPNP_SERIAL):
|
unique_id = discovery_info.upnp.get(
|
||||||
await self.async_set_unique_id(serial_number)
|
ssdp.ATTR_UPNP_SERIAL, discovery_info.upnp[ssdp.ATTR_UPNP_UDN]
|
||||||
self._abort_if_unique_id_configured()
|
)
|
||||||
else:
|
await self.async_set_unique_id(unique_id)
|
||||||
await self._async_handle_discovery_without_unique_id()
|
self._abort_if_unique_id_configured(updates={CONF_URL: url})
|
||||||
|
|
||||||
user_input = {CONF_URL: url}
|
self.context.update(
|
||||||
|
{
|
||||||
self.context["title_placeholders"] = {
|
"title_placeholders": {
|
||||||
CONF_NAME: discovery_info.upnp.get(ssdp.ATTR_UPNP_FRIENDLY_NAME)
|
CONF_NAME: discovery_info.upnp.get(ssdp.ATTR_UPNP_FRIENDLY_NAME)
|
||||||
}
|
},
|
||||||
return await self._async_show_user_form(user_input)
|
CONF_MANUFACTURER: discovery_info.upnp.get(ssdp.ATTR_UPNP_MANUFACTURER),
|
||||||
|
CONF_URL: url,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return await self._async_show_user_form()
|
||||||
|
|
||||||
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
|
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
|
||||||
"""Perform reauth upon an API authentication error."""
|
"""Perform reauth upon an API authentication error."""
|
||||||
|
@ -4,10 +4,12 @@ DOMAIN = "huawei_lte"
|
|||||||
|
|
||||||
ATTR_UNIQUE_ID = "unique_id"
|
ATTR_UNIQUE_ID = "unique_id"
|
||||||
|
|
||||||
|
CONF_MANUFACTURER = "manufacturer"
|
||||||
CONF_TRACK_WIRED_CLIENTS = "track_wired_clients"
|
CONF_TRACK_WIRED_CLIENTS = "track_wired_clients"
|
||||||
CONF_UNAUTHENTICATED_MODE = "unauthenticated_mode"
|
CONF_UNAUTHENTICATED_MODE = "unauthenticated_mode"
|
||||||
|
|
||||||
DEFAULT_DEVICE_NAME = "LTE"
|
DEFAULT_DEVICE_NAME = "LTE"
|
||||||
|
DEFAULT_MANUFACTURER = "Huawei Technologies Co., Ltd."
|
||||||
DEFAULT_NOTIFY_SERVICE_NAME = DOMAIN
|
DEFAULT_NOTIFY_SERVICE_NAME = DOMAIN
|
||||||
DEFAULT_TRACK_WIRED_CLIENTS = True
|
DEFAULT_TRACK_WIRED_CLIENTS = True
|
||||||
DEFAULT_UNAUTHENTICATED_MODE = False
|
DEFAULT_UNAUTHENTICATED_MODE = False
|
||||||
|
@ -12,6 +12,14 @@
|
|||||||
{
|
{
|
||||||
"deviceType": "urn:schemas-upnp-org:device:InternetGatewayDevice:1",
|
"deviceType": "urn:schemas-upnp-org:device:InternetGatewayDevice:1",
|
||||||
"manufacturer": "Huawei"
|
"manufacturer": "Huawei"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"deviceType": "urn:schemas-upnp-org:device:InternetGatewayDevice:1",
|
||||||
|
"manufacturer": "Huawei Technologies Co., Ltd."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"deviceType": "urn:schemas-upnp-org:device:InternetGatewayDevice:1",
|
||||||
|
"manufacturer": "SOYEA TECHNOLOGY CO., LTD."
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"codeowners": ["@scop", "@fphammerle"],
|
"codeowners": ["@scop", "@fphammerle"],
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"abort": {
|
"abort": {
|
||||||
"not_huawei_lte": "Not a Huawei LTE device",
|
|
||||||
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
|
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"abort": {
|
"abort": {
|
||||||
"not_huawei_lte": "Not a Huawei LTE device",
|
|
||||||
"reauth_successful": "Re-authentication was successful"
|
"reauth_successful": "Re-authentication was successful"
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
|
@ -146,6 +146,14 @@ SSDP = {
|
|||||||
"deviceType": "urn:schemas-upnp-org:device:InternetGatewayDevice:1",
|
"deviceType": "urn:schemas-upnp-org:device:InternetGatewayDevice:1",
|
||||||
"manufacturer": "Huawei",
|
"manufacturer": "Huawei",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"deviceType": "urn:schemas-upnp-org:device:InternetGatewayDevice:1",
|
||||||
|
"manufacturer": "Huawei Technologies Co., Ltd.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"deviceType": "urn:schemas-upnp-org:device:InternetGatewayDevice:1",
|
||||||
|
"manufacturer": "SOYEA TECHNOLOGY CO., LTD.",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
"hue": [
|
"hue": [
|
||||||
{
|
{
|
||||||
|
@ -235,15 +235,6 @@ async def test_success(hass, login_requests_mock):
|
|||||||
"errors": {},
|
"errors": {},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
(
|
|
||||||
{
|
|
||||||
ssdp.ATTR_UPNP_FRIENDLY_NAME: "Some other device",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": data_entry_flow.FlowResultType.ABORT,
|
|
||||||
"reason": "not_huawei_lte",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def test_ssdp(hass, upnp_data, expected_result):
|
async def test_ssdp(hass, upnp_data, expected_result):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user