Orphaned Devices?

In my custom component, when I delete all of the entities that a device belongs to, the orphaned devices remain. I’ve tried using async_purge_expired_orphaned_devices() in my init routine, however, that doesn’t seem to remove them.

When I try to explicitly remove them using the device_id, I get a key not found error.

I’m stumped. This is how the device is defined on the sensor entities.

    def device_info(self) -> DeviceInfo:
        """Return the device info."""
        return DeviceInfo(
                (DOMAIN, "dmp-%s-zone-%s" % (self._account_number,
            manufacturer='Digital Monitoring Products',
            via_device=(DOMAIN, "dmp-%s-panel" % (self._account_number))

async_purge_expired_orphaned_devices() is a db clean up routine for the database and will only clean up deleted devices. You should get an instance of the device registry and use async_remove_device(device_id). The device id is generated when the device is created so you may need to use async_get_device to get its device id from its identifier.

1 Like

Reviving old thread, how are you able to delete entities in your integration?

It’s a bug, I’ve been buried though between my day job and trying to get my master’s degree at the same time. I have line of sight to fixing it, I just have to sit down and make the adjustment.

In short what happened was I originally was using async_get_registry as part of my options flow, however that was deprecated in core and was preventing the component from loading. So I replaced it with async_get(self.hass), but apparently didn’t actually test the options flow. Even though the change made the component work again, the options flow does not. I have to make a couple adjustments to fix that and then we should be back in business.

I bumped it back up on my Todo list, sorry it’s taking so long for me to get to.

1 Like

Thanks for the response. Good luck with your master’s degree.