From 87e377cf8489646f62e76e5644f57a2e6524a260 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Sun, 21 Jul 2024 12:36:06 +0200 Subject: [PATCH] Ensure mqtt subscriptions are in a set (#122201) --- homeassistant/components/mqtt/__init__.py | 2 +- homeassistant/components/mqtt/client.py | 8 ++++---- homeassistant/components/mqtt/models.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py index ed87a99386b..5f7f1b1d330 100644 --- a/homeassistant/components/mqtt/__init__.py +++ b/homeassistant/components/mqtt/__init__.py @@ -254,7 +254,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: mqtt_data.client.async_restore_tracked_subscriptions( mqtt_data.subscriptions_to_restore ) - mqtt_data.subscriptions_to_restore = [] + mqtt_data.subscriptions_to_restore = set() mqtt_data.reload_dispatchers.append( entry.add_update_listener(_async_config_entry_updated) ) diff --git a/homeassistant/components/mqtt/client.py b/homeassistant/components/mqtt/client.py index 2ebd105b432..6762f440c5a 100644 --- a/homeassistant/components/mqtt/client.py +++ b/homeassistant/components/mqtt/client.py @@ -427,12 +427,12 @@ class MQTT: await self.async_init_client() @property - def subscriptions(self) -> list[Subscription]: + def subscriptions(self) -> set[Subscription]: """Return the tracked subscriptions.""" - return [ + return { *chain.from_iterable(self._simple_subscriptions.values()), *self._wildcard_subscriptions, - ] + } def cleanup(self) -> None: """Clean up listeners.""" @@ -735,7 +735,7 @@ class MQTT: @callback def async_restore_tracked_subscriptions( - self, subscriptions: list[Subscription] + self, subscriptions: set[Subscription] ) -> None: """Restore tracked subscriptions after reload.""" for subscription in subscriptions: diff --git a/homeassistant/components/mqtt/models.py b/homeassistant/components/mqtt/models.py index e5a9a9c44da..c355510a5c2 100644 --- a/homeassistant/components/mqtt/models.py +++ b/homeassistant/components/mqtt/models.py @@ -423,7 +423,7 @@ class MqttData: reload_handlers: dict[str, CALLBACK_TYPE] = field(default_factory=dict) reload_schema: dict[str, VolSchemaType] = field(default_factory=dict) state_write_requests: EntityTopicState = field(default_factory=EntityTopicState) - subscriptions_to_restore: list[Subscription] = field(default_factory=list) + subscriptions_to_restore: set[Subscription] = field(default_factory=set) tags: dict[str, dict[str, MQTTTagScanner]] = field(default_factory=dict)