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
This commit is contained in:
Fredrik Erlandsson 2024-09-23 20:09:07 +02:00 committed by GitHub
parent 788d9571b5
commit 88c751df7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 15 deletions

View file

@ -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)

View file

@ -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"