From 88c751df7a59ea3444b997d16ebee01abd0752ab Mon Sep 17 00:00:00 2001
From: Fredrik Erlandsson <fredrik.e@gmail.com>
Date: Mon, 23 Sep 2024 20:09:07 +0200
Subject: [PATCH] Fix point calls config entry to a platform multiple times
 (#126535)

* fix multiple async_forward_entry_setups calls

* ensure entity is at the right place
---
 homeassistant/components/point/__init__.py | 26 ++++++++++------------
 homeassistant/components/point/const.py    |  2 +-
 2 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/homeassistant/components/point/__init__.py b/homeassistant/components/point/__init__.py
index dff3acd9e6b..e446606f191 100644
--- a/homeassistant/components/point/__init__.py
+++ b/homeassistant/components/point/__init__.py
@@ -136,7 +136,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: PointConfigEntry) -> boo
     entry.runtime_data = PointData(client)
 
     await async_setup_webhook(hass, entry, point_session)
-    # Entries are added in the client.update() function.
+    await hass.config_entries.async_forward_entry_setups(
+        entry, [*PLATFORMS, Platform.ALARM_CONTROL_PANEL]
+    )
 
     return True
 
@@ -225,27 +227,23 @@ class MinutPointClient:
             async_dispatcher_send(self._hass, SIGNAL_UPDATE_ENTITY)
             return
 
-        async def new_device(device_id, platform):
-            """Load new device."""
-            async_dispatcher_send(
-                self._hass, POINT_DISCOVERY_NEW.format(platform, DOMAIN), device_id
-            )
-
         self._is_available = True
         for home_id in self._client.homes:
             if home_id not in self._known_homes:
-                await self._hass.config_entries.async_forward_entry_setups(
-                    self._config_entry, [Platform.ALARM_CONTROL_PANEL]
+                async_dispatcher_send(
+                    self._hass,
+                    POINT_DISCOVERY_NEW.format(Platform.ALARM_CONTROL_PANEL),
+                    home_id,
                 )
-                await new_device(home_id, "alarm_control_panel")
                 self._known_homes.add(home_id)
         for device in self._client.devices:
             if device.device_id not in self._known_devices:
-                await self._hass.config_entries.async_forward_entry_setups(
-                    self._config_entry, PLATFORMS
-                )
                 for platform in PLATFORMS:
-                    await new_device(device.device_id, platform)
+                    async_dispatcher_send(
+                        self._hass,
+                        POINT_DISCOVERY_NEW.format(platform),
+                        device.device_id,
+                    )
                 self._known_devices.add(device.device_id)
         async_dispatcher_send(self._hass, SIGNAL_UPDATE_ENTITY)
 
diff --git a/homeassistant/components/point/const.py b/homeassistant/components/point/const.py
index 1c2720749e6..1122cf69c0a 100644
--- a/homeassistant/components/point/const.py
+++ b/homeassistant/components/point/const.py
@@ -12,7 +12,7 @@ EVENT_RECEIVED = "point_webhook_received"
 SIGNAL_UPDATE_ENTITY = "point_update"
 SIGNAL_WEBHOOK = "point_webhook"
 
-POINT_DISCOVERY_NEW = "point_new_{}_{}"
+POINT_DISCOVERY_NEW = "point_new_{}"
 
 OAUTH2_AUTHORIZE = "https://api.minut.com/v8/oauth/authorize"
 OAUTH2_TOKEN = "https://api.minut.com/v8/oauth/token"
-- 
GitLab