mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Fix huawei_lte current month up/download sensor error on delete (#100506)
Deleting one of them prematurely deleted the last reset item subscription that is shared between the two.
This commit is contained in:
parent
7aa02b8621
commit
2794ab1782
@ -143,9 +143,11 @@ class Router:
|
|||||||
url: str
|
url: str
|
||||||
|
|
||||||
data: dict[str, Any] = field(default_factory=dict, init=False)
|
data: dict[str, Any] = field(default_factory=dict, init=False)
|
||||||
subscriptions: dict[str, set[str]] = field(
|
# Values are lists rather than sets, because the same item may be used by more than
|
||||||
|
# one thing, such as MonthDuration for CurrentMonth{Download,Upload}.
|
||||||
|
subscriptions: dict[str, list[str]] = field(
|
||||||
default_factory=lambda: defaultdict(
|
default_factory=lambda: defaultdict(
|
||||||
set, ((x, {"initial_scan"}) for x in ALL_KEYS)
|
list, ((x, ["initial_scan"]) for x in ALL_KEYS)
|
||||||
),
|
),
|
||||||
init=False,
|
init=False,
|
||||||
)
|
)
|
||||||
|
@ -65,7 +65,9 @@ class HuaweiLteBaseBinarySensor(HuaweiLteBaseEntityWithDevice, BinarySensorEntit
|
|||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Subscribe to needed data on add."""
|
"""Subscribe to needed data on add."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
self.router.subscriptions[self.key].add(f"{BINARY_SENSOR_DOMAIN}/{self.item}")
|
self.router.subscriptions[self.key].append(
|
||||||
|
f"{BINARY_SENSOR_DOMAIN}/{self.item}"
|
||||||
|
)
|
||||||
|
|
||||||
async def async_will_remove_from_hass(self) -> None:
|
async def async_will_remove_from_hass(self) -> None:
|
||||||
"""Unsubscribe from needed data on remove."""
|
"""Unsubscribe from needed data on remove."""
|
||||||
|
@ -90,8 +90,8 @@ async def async_setup_entry(
|
|||||||
async_add_entities(known_entities, True)
|
async_add_entities(known_entities, True)
|
||||||
|
|
||||||
# Tell parent router to poll hosts list to gather new devices
|
# Tell parent router to poll hosts list to gather new devices
|
||||||
router.subscriptions[KEY_LAN_HOST_INFO].add(_DEVICE_SCAN)
|
router.subscriptions[KEY_LAN_HOST_INFO].append(_DEVICE_SCAN)
|
||||||
router.subscriptions[KEY_WLAN_HOST_LIST].add(_DEVICE_SCAN)
|
router.subscriptions[KEY_WLAN_HOST_LIST].append(_DEVICE_SCAN)
|
||||||
|
|
||||||
async def _async_maybe_add_new_entities(unique_id: str) -> None:
|
async def _async_maybe_add_new_entities(unique_id: str) -> None:
|
||||||
"""Add new entities if the update signal comes from our router."""
|
"""Add new entities if the update signal comes from our router."""
|
||||||
|
@ -724,9 +724,9 @@ class HuaweiLteSensor(HuaweiLteBaseEntityWithDevice, SensorEntity):
|
|||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Subscribe to needed data on add."""
|
"""Subscribe to needed data on add."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
self.router.subscriptions[self.key].add(f"{SENSOR_DOMAIN}/{self.item}")
|
self.router.subscriptions[self.key].append(f"{SENSOR_DOMAIN}/{self.item}")
|
||||||
if self.entity_description.last_reset_item:
|
if self.entity_description.last_reset_item:
|
||||||
self.router.subscriptions[self.key].add(
|
self.router.subscriptions[self.key].append(
|
||||||
f"{SENSOR_DOMAIN}/{self.entity_description.last_reset_item}"
|
f"{SENSOR_DOMAIN}/{self.entity_description.last_reset_item}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ class HuaweiLteBaseSwitch(HuaweiLteBaseEntityWithDevice, SwitchEntity):
|
|||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Subscribe to needed data on add."""
|
"""Subscribe to needed data on add."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
self.router.subscriptions[self.key].add(f"{SWITCH_DOMAIN}/{self.item}")
|
self.router.subscriptions[self.key].append(f"{SWITCH_DOMAIN}/{self.item}")
|
||||||
|
|
||||||
async def async_will_remove_from_hass(self) -> None:
|
async def async_will_remove_from_hass(self) -> None:
|
||||||
"""Unsubscribe from needed data on remove."""
|
"""Unsubscribe from needed data on remove."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user