Explicitly set unique ids for GDACS integration (#32203)
* explicitly set unique ids * use config flow's unique id * use config's unique id
This commit is contained in:
parent
2390a7f365
commit
adb3bb3653
3 changed files with 22 additions and 6 deletions
|
@ -190,7 +190,11 @@ class GdacsFeedEntityManager:
|
|||
async def _generate_entity(self, external_id):
|
||||
"""Generate new entity."""
|
||||
async_dispatcher_send(
|
||||
self._hass, self.async_event_new_entity(), self, external_id
|
||||
self._hass,
|
||||
self.async_event_new_entity(),
|
||||
self,
|
||||
self._config_entry.unique_id,
|
||||
external_id,
|
||||
)
|
||||
|
||||
async def _update_entity(self, external_id):
|
||||
|
|
|
@ -49,9 +49,9 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||
manager = hass.data[DOMAIN][FEED][entry.entry_id]
|
||||
|
||||
@callback
|
||||
def async_add_geolocation(feed_manager, external_id):
|
||||
def async_add_geolocation(feed_manager, integration_id, external_id):
|
||||
"""Add gelocation entity from feed."""
|
||||
new_entity = GdacsEvent(feed_manager, external_id)
|
||||
new_entity = GdacsEvent(feed_manager, integration_id, external_id)
|
||||
_LOGGER.debug("Adding geolocation %s", new_entity)
|
||||
async_add_entities([new_entity], True)
|
||||
|
||||
|
@ -69,9 +69,10 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||
class GdacsEvent(GeolocationEvent):
|
||||
"""This represents an external event with GDACS feed data."""
|
||||
|
||||
def __init__(self, feed_manager, external_id):
|
||||
def __init__(self, feed_manager, integration_id, external_id):
|
||||
"""Initialize entity with data from feed entry."""
|
||||
self._feed_manager = feed_manager
|
||||
self._integration_id = integration_id
|
||||
self._external_id = external_id
|
||||
self._title = None
|
||||
self._distance = None
|
||||
|
@ -162,6 +163,11 @@ class GdacsEvent(GeolocationEvent):
|
|||
self._vulnerability = round(self._vulnerability, 1)
|
||||
self._version = feed_entry.version
|
||||
|
||||
@property
|
||||
def unique_id(self) -> Optional[str]:
|
||||
"""Return a unique ID containing latitude/longitude and external id."""
|
||||
return f"{self._integration_id}_{self._external_id}"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon to use in the frontend, if any."""
|
||||
|
|
|
@ -28,7 +28,7 @@ PARALLEL_UPDATES = 0
|
|||
async def async_setup_entry(hass, entry, async_add_entities):
|
||||
"""Set up the GDACS Feed platform."""
|
||||
manager = hass.data[DOMAIN][FEED][entry.entry_id]
|
||||
sensor = GdacsSensor(entry.entry_id, entry.title, manager)
|
||||
sensor = GdacsSensor(entry.entry_id, entry.unique_id, entry.title, manager)
|
||||
async_add_entities([sensor])
|
||||
_LOGGER.debug("Sensor setup done")
|
||||
|
||||
|
@ -36,9 +36,10 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||
class GdacsSensor(Entity):
|
||||
"""This is a status sensor for the GDACS integration."""
|
||||
|
||||
def __init__(self, config_entry_id, config_title, manager):
|
||||
def __init__(self, config_entry_id, config_unique_id, config_title, manager):
|
||||
"""Initialize entity."""
|
||||
self._config_entry_id = config_entry_id
|
||||
self._config_unique_id = config_unique_id
|
||||
self._config_title = config_title
|
||||
self._manager = manager
|
||||
self._status = None
|
||||
|
@ -107,6 +108,11 @@ class GdacsSensor(Entity):
|
|||
"""Return the state of the sensor."""
|
||||
return self._total
|
||||
|
||||
@property
|
||||
def unique_id(self) -> Optional[str]:
|
||||
"""Return a unique ID containing latitude/longitude."""
|
||||
return self._config_unique_id
|
||||
|
||||
@property
|
||||
def name(self) -> Optional[str]:
|
||||
"""Return the name of the entity."""
|
||||
|
|
Loading…
Add table
Reference in a new issue