Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Huawei LTE SSDP improvements #81643

Merged
merged 8 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion homeassistant/components/huawei_lte/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@
ADMIN_SERVICES,
ALL_KEYS,
ATTR_UNIQUE_ID,
CONF_MANUFACTURER,
CONF_UNAUTHENTICATED_MODE,
CONNECTION_TIMEOUT,
DEFAULT_DEVICE_NAME,
DEFAULT_MANUFACTURER,
DEFAULT_NOTIFY_SERVICE_NAME,
DOMAIN,
KEY_DEVICE_BASIC_INFORMATION,
Expand Down Expand Up @@ -412,9 +414,10 @@ def get_connection() -> Connection:
device_info = DeviceInfo(
configuration_url=router.url,
connections=router.device_connections,
default_manufacturer=DEFAULT_MANUFACTURER,
identifiers=router.device_identifiers,
manufacturer=entry.data.get(CONF_MANUFACTURER),
name=router.device_name,
manufacturer="Huawei",
)
hw_version = None
sw_version = None
Expand Down
36 changes: 25 additions & 11 deletions homeassistant/components/huawei_lte/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from collections.abc import Mapping
import logging
import re
from typing import TYPE_CHECKING, Any
from urllib.parse import urlparse

Expand Down Expand Up @@ -34,6 +35,7 @@
from homeassistant.data_entry_flow import FlowResult

from .const import (
CONF_MANUFACTURER,
CONF_TRACK_WIRED_CLIENTS,
CONF_UNAUTHENTICATED_MODE,
CONNECTION_TIMEOUT,
Expand Down Expand Up @@ -208,7 +210,12 @@ def get_device_info(
)
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 serial_number := info.get("SerialNumber"):
Expand All @@ -232,10 +239,13 @@ async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowRes
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()
# some of the ones we are interested in include friendlyNames like
# "Mobile Wi-Fi", "4G CPE 3", and "华为4G路由 B525". (The last one is
# an example why there are no word boundary markers around the regex.)
if not re.search(
r"[45]G|LTE|Mobile",
discovery_info.upnp.get(ssdp.ATTR_UPNP_FRIENDLY_NAME, ""),
re.IGNORECASE,
):
return self.async_abort(reason="not_huawei_lte")

Expand All @@ -254,12 +264,16 @@ async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowRes
else:
await self._async_handle_discovery_without_unique_id()

user_input = {CONF_URL: url}

self.context["title_placeholders"] = {
CONF_NAME: discovery_info.upnp.get(ssdp.ATTR_UPNP_FRIENDLY_NAME)
}
return await self._async_show_user_form(user_input)
self.context.update(
{
"title_placeholders": {
CONF_NAME: discovery_info.upnp.get(ssdp.ATTR_UPNP_FRIENDLY_NAME)
},
CONF_MANUFACTURER: discovery_info.upnp.get(ssdp.ATTR_UPNP_MANUFACTURER),
CONF_URL: url,
}
)
return await self._async_show_user_form()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: We should not move directly to another step's form. The form is private to the step method. Await the step method to move to that step.


async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
"""Perform reauth upon an API authentication error."""
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/huawei_lte/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

ATTR_UNIQUE_ID = "unique_id"

CONF_MANUFACTURER = "manufacturer"
CONF_TRACK_WIRED_CLIENTS = "track_wired_clients"
CONF_UNAUTHENTICATED_MODE = "unauthenticated_mode"

DEFAULT_DEVICE_NAME = "LTE"
DEFAULT_MANUFACTURER = "Huawei Technologies Co., Ltd."
DEFAULT_NOTIFY_SERVICE_NAME = DOMAIN
DEFAULT_TRACK_WIRED_CLIENTS = True
DEFAULT_UNAUTHENTICATED_MODE = False
Expand Down
6 changes: 5 additions & 1 deletion homeassistant/components/huawei_lte/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
"ssdp": [
{
"deviceType": "urn:schemas-upnp-org:device:InternetGatewayDevice:1",
"manufacturer": "Huawei"
"manufacturer": "Huawei Technologies Co., Ltd."
},
{
"deviceType": "urn:schemas-upnp-org:device:InternetGatewayDevice:1",
"manufacturer": "SOYEA TECHNOLOGY CO., LTD."
}
],
"codeowners": ["@scop", "@fphammerle"],
Expand Down
6 changes: 5 additions & 1 deletion homeassistant/generated/ssdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@
"huawei_lte": [
{
"deviceType": "urn:schemas-upnp-org:device:InternetGatewayDevice:1",
"manufacturer": "Huawei",
"manufacturer": "Huawei Technologies Co., Ltd.",
},
{
"deviceType": "urn:schemas-upnp-org:device:InternetGatewayDevice:1",
"manufacturer": "SOYEA TECHNOLOGY CO., LTD.",
},
],
"hue": [
Expand Down