mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add Huawei LTE device registry support (#28594)
This commit is contained in:
parent
64166583b3
commit
4f56f4e7e9
@ -6,7 +6,7 @@ from functools import partial
|
|||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
import ipaddress
|
import ipaddress
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Callable, Dict, List, Set
|
from typing import Any, Callable, Dict, List, Set, Tuple
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
import attr
|
import attr
|
||||||
@ -36,6 +36,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import CALLBACK_TYPE
|
from homeassistant.core import CALLBACK_TYPE
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers import config_validation as cv, discovery
|
from homeassistant.helpers import config_validation as cv, discovery
|
||||||
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import (
|
||||||
async_dispatcher_connect,
|
async_dispatcher_connect,
|
||||||
async_dispatcher_send,
|
async_dispatcher_send,
|
||||||
@ -135,6 +136,11 @@ class Router:
|
|||||||
pass
|
pass
|
||||||
return DEFAULT_DEVICE_NAME
|
return DEFAULT_DEVICE_NAME
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_connections(self) -> Set[Tuple[str, str]]:
|
||||||
|
"""Get router connections for device registry."""
|
||||||
|
return {(dr.CONNECTION_NETWORK_MAC, self.mac)}
|
||||||
|
|
||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
"""Update router data."""
|
"""Update router data."""
|
||||||
|
|
||||||
@ -283,6 +289,30 @@ async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry)
|
|||||||
# Clear all subscriptions, enabled entities will push back theirs
|
# Clear all subscriptions, enabled entities will push back theirs
|
||||||
router.subscriptions.clear()
|
router.subscriptions.clear()
|
||||||
|
|
||||||
|
# Set up device registry
|
||||||
|
device_data = {}
|
||||||
|
sw_version = None
|
||||||
|
if router.data.get(KEY_DEVICE_INFORMATION):
|
||||||
|
device_info = router.data[KEY_DEVICE_INFORMATION]
|
||||||
|
serial_number = device_info.get("SerialNumber")
|
||||||
|
if serial_number:
|
||||||
|
device_data["identifiers"] = {(DOMAIN, serial_number)}
|
||||||
|
sw_version = device_info.get("SoftwareVersion")
|
||||||
|
if device_info.get("DeviceName"):
|
||||||
|
device_data["model"] = device_info["DeviceName"]
|
||||||
|
if not sw_version and router.data.get(KEY_DEVICE_BASIC_INFORMATION):
|
||||||
|
sw_version = router.data[KEY_DEVICE_BASIC_INFORMATION].get("SoftwareVersion")
|
||||||
|
if sw_version:
|
||||||
|
device_data["sw_version"] = sw_version
|
||||||
|
device_registry = await dr.async_get_registry(hass)
|
||||||
|
device_registry.async_get_or_create(
|
||||||
|
config_entry_id=config_entry.entry_id,
|
||||||
|
connections=router.device_connections,
|
||||||
|
name=router.device_name,
|
||||||
|
manufacturer="Huawei",
|
||||||
|
**device_data,
|
||||||
|
)
|
||||||
|
|
||||||
# Forward config entry setup to platforms
|
# Forward config entry setup to platforms
|
||||||
for domain in (DEVICE_TRACKER_DOMAIN, SENSOR_DOMAIN, SWITCH_DOMAIN):
|
for domain in (DEVICE_TRACKER_DOMAIN, SENSOR_DOMAIN, SWITCH_DOMAIN):
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
@ -408,6 +438,11 @@ class HuaweiLteBaseEntity(Entity):
|
|||||||
"""Huawei LTE entities report their state without polling."""
|
"""Huawei LTE entities report their state without polling."""
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_info(self) -> Dict[str, Any]:
|
||||||
|
"""Get info for matching with parent router."""
|
||||||
|
return {"connections": self.router.device_connections}
|
||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Update state."""
|
"""Update state."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
Loading…
x
Reference in New Issue
Block a user