Key Huawei LTE routers in hass.data by config entry rather than unique id (#85788)

Key routers in hass.data by config entry rather than unique id

There's no particular reason to key them by the unique id; the config
entry id is a stronger, always available guarantee, and a much more
common convention across the HA codebase.

At some point, we might conceivably support devices we can't find a
proper unique id for; this would work for that purpose as well.
pull/85438/head^2
Ville Skyttä 2023-01-13 10:20:24 +02:00 committed by GitHub
parent 1deb4c68f3
commit 4c31317c06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 11 additions and 11 deletions

View File

@ -55,7 +55,7 @@ from homeassistant.helpers.typing import ConfigType
from .const import (
ADMIN_SERVICES,
ALL_KEYS,
ATTR_UNIQUE_ID,
ATTR_CONFIG_ENTRY_ID,
CONF_MANUFACTURER,
CONF_UNAUTHENTICATED_MODE,
CONNECTION_TIMEOUT,
@ -387,7 +387,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return False
# Store reference to router
hass.data[DOMAIN].routers[entry.unique_id] = router
hass.data[DOMAIN].routers[entry.entry_id] = router
# Clear all subscriptions, enabled entities will push back theirs
router.subscriptions.clear()
@ -449,7 +449,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
Platform.NOTIFY,
DOMAIN,
{
ATTR_UNIQUE_ID: entry.unique_id,
ATTR_CONFIG_ENTRY_ID: entry.entry_id,
CONF_NAME: entry.options.get(CONF_NAME, DEFAULT_NOTIFY_SERVICE_NAME),
CONF_RECIPIENT: entry.options.get(CONF_RECIPIENT),
},
@ -484,7 +484,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
# Forget about the router and invoke its cleanup
router = hass.data[DOMAIN].routers.pop(config_entry.unique_id)
router = hass.data[DOMAIN].routers.pop(config_entry.entry_id)
await hass.async_add_executor_job(router.cleanup)
return True

View File

@ -33,7 +33,7 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up from config entry."""
router = hass.data[DOMAIN].routers[config_entry.unique_id]
router = hass.data[DOMAIN].routers[config_entry.entry_id]
entities: list[Entity] = []
if router.data.get(KEY_MONITORING_STATUS):

View File

@ -2,7 +2,7 @@
DOMAIN = "huawei_lte"
ATTR_UNIQUE_ID = "unique_id"
ATTR_CONFIG_ENTRY_ID = "config_entry_id"
CONF_MANUFACTURER = "manufacturer"
CONF_TRACK_WIRED_CLIENTS = "track_wired_clients"

View File

@ -60,7 +60,7 @@ async def async_setup_entry(
# Grab hosts list once to examine whether the initial fetch has got some data for
# us, i.e. if wlan host list is supported. Only set up a subscription and proceed
# with adding and tracking entities if it is.
router = hass.data[DOMAIN].routers[config_entry.unique_id]
router = hass.data[DOMAIN].routers[config_entry.entry_id]
if (hosts := _get_hosts(router, True)) is None:
return

View File

@ -14,7 +14,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import Router
from .const import ATTR_UNIQUE_ID, DOMAIN
from .const import ATTR_CONFIG_ENTRY_ID, DOMAIN
_LOGGER = logging.getLogger(__name__)
@ -28,7 +28,7 @@ async def async_get_service(
if discovery_info is None:
return None
router = hass.data[DOMAIN].routers[discovery_info[ATTR_UNIQUE_ID]]
router = hass.data[DOMAIN].routers[discovery_info[ATTR_CONFIG_ENTRY_ID]]
default_targets = discovery_info[CONF_RECIPIENT] or []
return HuaweiLteSmsNotificationService(router, default_targets)

View File

@ -627,7 +627,7 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up from config entry."""
router = hass.data[DOMAIN].routers[config_entry.unique_id]
router = hass.data[DOMAIN].routers[config_entry.entry_id]
sensors: list[Entity] = []
for key in SENSOR_KEYS:
if not (items := router.data.get(key)):

View File

@ -31,7 +31,7 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up from config entry."""
router = hass.data[DOMAIN].routers[config_entry.unique_id]
router = hass.data[DOMAIN].routers[config_entry.entry_id]
switches: list[Entity] = []
if router.data.get(KEY_DIALUP_MOBILE_DATASWITCH):