Skip to content

Commit 4c31317

Browse files
authored
Key Huawei LTE routers in hass.data by config entry rather than unique id (home-assistant#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.
1 parent 1deb4c6 commit 4c31317

File tree

7 files changed

+11
-11
lines changed

7 files changed

+11
-11
lines changed

homeassistant/components/huawei_lte/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
from .const import (
5656
ADMIN_SERVICES,
5757
ALL_KEYS,
58-
ATTR_UNIQUE_ID,
58+
ATTR_CONFIG_ENTRY_ID,
5959
CONF_MANUFACTURER,
6060
CONF_UNAUTHENTICATED_MODE,
6161
CONNECTION_TIMEOUT,
@@ -387,7 +387,7 @@ def get_connection() -> Connection:
387387
return False
388388

389389
# Store reference to router
390-
hass.data[DOMAIN].routers[entry.unique_id] = router
390+
hass.data[DOMAIN].routers[entry.entry_id] = router
391391

392392
# Clear all subscriptions, enabled entities will push back theirs
393393
router.subscriptions.clear()
@@ -449,7 +449,7 @@ def get_connection() -> Connection:
449449
Platform.NOTIFY,
450450
DOMAIN,
451451
{
452-
ATTR_UNIQUE_ID: entry.unique_id,
452+
ATTR_CONFIG_ENTRY_ID: entry.entry_id,
453453
CONF_NAME: entry.options.get(CONF_NAME, DEFAULT_NOTIFY_SERVICE_NAME),
454454
CONF_RECIPIENT: entry.options.get(CONF_RECIPIENT),
455455
},
@@ -484,7 +484,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
484484
await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
485485

486486
# Forget about the router and invoke its cleanup
487-
router = hass.data[DOMAIN].routers.pop(config_entry.unique_id)
487+
router = hass.data[DOMAIN].routers.pop(config_entry.entry_id)
488488
await hass.async_add_executor_job(router.cleanup)
489489

490490
return True

homeassistant/components/huawei_lte/binary_sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def async_setup_entry(
3333
async_add_entities: AddEntitiesCallback,
3434
) -> None:
3535
"""Set up from config entry."""
36-
router = hass.data[DOMAIN].routers[config_entry.unique_id]
36+
router = hass.data[DOMAIN].routers[config_entry.entry_id]
3737
entities: list[Entity] = []
3838

3939
if router.data.get(KEY_MONITORING_STATUS):

homeassistant/components/huawei_lte/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
DOMAIN = "huawei_lte"
44

5-
ATTR_UNIQUE_ID = "unique_id"
5+
ATTR_CONFIG_ENTRY_ID = "config_entry_id"
66

77
CONF_MANUFACTURER = "manufacturer"
88
CONF_TRACK_WIRED_CLIENTS = "track_wired_clients"

homeassistant/components/huawei_lte/device_tracker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async def async_setup_entry(
6060
# Grab hosts list once to examine whether the initial fetch has got some data for
6161
# us, i.e. if wlan host list is supported. Only set up a subscription and proceed
6262
# with adding and tracking entities if it is.
63-
router = hass.data[DOMAIN].routers[config_entry.unique_id]
63+
router = hass.data[DOMAIN].routers[config_entry.entry_id]
6464
if (hosts := _get_hosts(router, True)) is None:
6565
return
6666

homeassistant/components/huawei_lte/notify.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
1515

1616
from . import Router
17-
from .const import ATTR_UNIQUE_ID, DOMAIN
17+
from .const import ATTR_CONFIG_ENTRY_ID, DOMAIN
1818

1919
_LOGGER = logging.getLogger(__name__)
2020

@@ -28,7 +28,7 @@ async def async_get_service(
2828
if discovery_info is None:
2929
return None
3030

31-
router = hass.data[DOMAIN].routers[discovery_info[ATTR_UNIQUE_ID]]
31+
router = hass.data[DOMAIN].routers[discovery_info[ATTR_CONFIG_ENTRY_ID]]
3232
default_targets = discovery_info[CONF_RECIPIENT] or []
3333

3434
return HuaweiLteSmsNotificationService(router, default_targets)

homeassistant/components/huawei_lte/sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ async def async_setup_entry(
627627
async_add_entities: AddEntitiesCallback,
628628
) -> None:
629629
"""Set up from config entry."""
630-
router = hass.data[DOMAIN].routers[config_entry.unique_id]
630+
router = hass.data[DOMAIN].routers[config_entry.entry_id]
631631
sensors: list[Entity] = []
632632
for key in SENSOR_KEYS:
633633
if not (items := router.data.get(key)):

homeassistant/components/huawei_lte/switch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async def async_setup_entry(
3131
async_add_entities: AddEntitiesCallback,
3232
) -> None:
3333
"""Set up from config entry."""
34-
router = hass.data[DOMAIN].routers[config_entry.unique_id]
34+
router = hass.data[DOMAIN].routers[config_entry.entry_id]
3535
switches: list[Entity] = []
3636

3737
if router.data.get(KEY_DIALUP_MOBILE_DATASWITCH):

0 commit comments

Comments
 (0)