Add multiple sensors with one config entry

I build a custom component, but I can’t figure out how to setup platforms multiple times. (for every “device”)

When I run this only one device gets created and every other one gets a ValueError: Config entry has already been setup! Can somebody help me with this?

Here is my code:
In __init__.py

def handle_asterisk_event(event, manager, hass, entry):
    _LOGGER.info("event.headers: " + json.dumps(event.headers))
    _LOGGER.info("ObjectName: " + event.get_header("ObjectName"))
    _extension = event.get_header("ObjectName")
    hass.data[DOMAIN][entry.entry_id] = _extension
    hass.config_entries.async_setup_platforms(entry, PLATFORMS)

In sensor.py

async def async_setup_entry(hass, entry, async_add_devices):
    """Setting up every extension."""
    extension = hass.data[DOMAIN][entry.entry_id]
    entry_id = entry.entry_id
    _LOGGER.warning(f"Setting up asterisk extension device for extension {extension}")
    async_add_devices([AsteriskExtension(hass, extension, entry_id)], True)

This function is being called for every device I want to set up.

Thanks for helping. :slight_smile: