mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
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.
This commit is contained in:
parent
1deb4c68f3
commit
4c31317c06
@ -55,7 +55,7 @@ from homeassistant.helpers.typing import ConfigType
|
|||||||
from .const import (
|
from .const import (
|
||||||
ADMIN_SERVICES,
|
ADMIN_SERVICES,
|
||||||
ALL_KEYS,
|
ALL_KEYS,
|
||||||
ATTR_UNIQUE_ID,
|
ATTR_CONFIG_ENTRY_ID,
|
||||||
CONF_MANUFACTURER,
|
CONF_MANUFACTURER,
|
||||||
CONF_UNAUTHENTICATED_MODE,
|
CONF_UNAUTHENTICATED_MODE,
|
||||||
CONNECTION_TIMEOUT,
|
CONNECTION_TIMEOUT,
|
||||||
@ -387,7 +387,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# Store reference to router
|
# 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
|
# Clear all subscriptions, enabled entities will push back theirs
|
||||||
router.subscriptions.clear()
|
router.subscriptions.clear()
|
||||||
@ -449,7 +449,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
Platform.NOTIFY,
|
Platform.NOTIFY,
|
||||||
DOMAIN,
|
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_NAME: entry.options.get(CONF_NAME, DEFAULT_NOTIFY_SERVICE_NAME),
|
||||||
CONF_RECIPIENT: entry.options.get(CONF_RECIPIENT),
|
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)
|
await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
|
||||||
|
|
||||||
# Forget about the router and invoke its cleanup
|
# 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)
|
await hass.async_add_executor_job(router.cleanup)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -33,7 +33,7 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up from config entry."""
|
"""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] = []
|
entities: list[Entity] = []
|
||||||
|
|
||||||
if router.data.get(KEY_MONITORING_STATUS):
|
if router.data.get(KEY_MONITORING_STATUS):
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
DOMAIN = "huawei_lte"
|
DOMAIN = "huawei_lte"
|
||||||
|
|
||||||
ATTR_UNIQUE_ID = "unique_id"
|
ATTR_CONFIG_ENTRY_ID = "config_entry_id"
|
||||||
|
|
||||||
CONF_MANUFACTURER = "manufacturer"
|
CONF_MANUFACTURER = "manufacturer"
|
||||||
CONF_TRACK_WIRED_CLIENTS = "track_wired_clients"
|
CONF_TRACK_WIRED_CLIENTS = "track_wired_clients"
|
||||||
|
@ -60,7 +60,7 @@ async def async_setup_entry(
|
|||||||
# Grab hosts list once to examine whether the initial fetch has got some data for
|
# 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
|
# us, i.e. if wlan host list is supported. Only set up a subscription and proceed
|
||||||
# with adding and tracking entities if it is.
|
# 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:
|
if (hosts := _get_hosts(router, True)) is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from . import Router
|
from . import Router
|
||||||
from .const import ATTR_UNIQUE_ID, DOMAIN
|
from .const import ATTR_CONFIG_ENTRY_ID, DOMAIN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ async def async_get_service(
|
|||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return 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 []
|
default_targets = discovery_info[CONF_RECIPIENT] or []
|
||||||
|
|
||||||
return HuaweiLteSmsNotificationService(router, default_targets)
|
return HuaweiLteSmsNotificationService(router, default_targets)
|
||||||
|
@ -627,7 +627,7 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up from config entry."""
|
"""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] = []
|
sensors: list[Entity] = []
|
||||||
for key in SENSOR_KEYS:
|
for key in SENSOR_KEYS:
|
||||||
if not (items := router.data.get(key)):
|
if not (items := router.data.get(key)):
|
||||||
|
@ -31,7 +31,7 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up from config entry."""
|
"""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] = []
|
switches: list[Entity] = []
|
||||||
|
|
||||||
if router.data.get(KEY_DIALUP_MOBILE_DATASWITCH):
|
if router.data.get(KEY_DIALUP_MOBILE_DATASWITCH):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user