From 3c0f7669337f2fcd55eaaa343cc4b227de294681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 16 Aug 2020 14:38:12 +0300 Subject: [PATCH] Huawei LTE device registry improvements (#38925) * Fix getting software version in unauthenticated mode * Add serial number device identifier if available --- homeassistant/components/huawei_lte/__init__.py | 14 +++++++++++++- homeassistant/components/huawei_lte/const.py | 8 +++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/huawei_lte/__init__.py b/homeassistant/components/huawei_lte/__init__.py index 6788f476ddd..8b12cd0975e 100644 --- a/homeassistant/components/huawei_lte/__init__.py +++ b/homeassistant/components/huawei_lte/__init__.py @@ -162,6 +162,14 @@ class Router: pass return DEFAULT_DEVICE_NAME + @property + def device_identifiers(self) -> Set[Tuple[str, str]]: + """Get router identifiers for device registry.""" + try: + return {(DOMAIN, self.data[KEY_DEVICE_INFORMATION]["SerialNumber"])} + except (KeyError, TypeError): + return set() + @property def device_connections(self) -> Set[Tuple[str, str]]: """Get router connections for device registry.""" @@ -390,6 +398,7 @@ async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry) device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, connections=router.device_connections, + identifiers=router.device_identifiers, name=router.device_name, manufacturer="Huawei", **device_data, @@ -594,7 +603,10 @@ class HuaweiLteBaseEntity(Entity): @property def device_info(self) -> Dict[str, Any]: """Get info for matching with parent router.""" - return {"connections": self.router.device_connections} + return { + "identifiers": self.router.device_identifiers, + "connections": self.router.device_connections, + } async def async_update(self) -> None: """Update state.""" diff --git a/homeassistant/components/huawei_lte/const.py b/homeassistant/components/huawei_lte/const.py index 1019d4d19cd..2c5a3f8a9f6 100644 --- a/homeassistant/components/huawei_lte/const.py +++ b/homeassistant/components/huawei_lte/const.py @@ -53,4 +53,10 @@ SENSOR_KEYS = { SWITCH_KEYS = {KEY_DIALUP_MOBILE_DATASWITCH} -ALL_KEYS = BINARY_SENSOR_KEYS | DEVICE_TRACKER_KEYS | SENSOR_KEYS | SWITCH_KEYS +ALL_KEYS = ( + BINARY_SENSOR_KEYS + | DEVICE_TRACKER_KEYS + | SENSOR_KEYS + | SWITCH_KEYS + | {KEY_DEVICE_BASIC_INFORMATION} +)