diff --git a/custom_components/openhasp/__init__.py b/custom_components/openhasp/__init__.py index f79d816..8fe591f 100644 --- a/custom_components/openhasp/__init__.py +++ b/custom_components/openhasp/__init__.py @@ -500,6 +500,13 @@ async def lwt_message_received(msg): EVENT_HASP_PLATE_ONLINE, {CONF_PLATE: self._entry.data[CONF_HWID]}, ) + # Ensure any existing subscriptions are removed before + # re-registering, to avoid duplicate event handlers after + # a HA reload while the plate remains online (retained LWT + # message triggers this handler again on re-subscription). + for obj in self._objects: + await obj.disable_object() + if self._pages_jsonl: await self.async_load_page(self._pages_jsonl) else: @@ -858,4 +865,4 @@ async def message_received(msg): ) _LOGGER.debug("Subscribe to '%s' events on '%s'", self.obj_id, self.state_topic) - return await async_subscribe(self.hass, self.state_topic, message_received) + return await async_subscribe(self.hass, self.state_topic, message_received) \ No newline at end of file