#Is there an API to list ESPHome devices?

1 messages · Page 1 of 1 (latest)

dire shale
#

I am looking to collect and add event listeners to several esphome devices. Is there a built in mechanism to do so? Something like below:

    if "esphome" not in hass.data:
        _LOGGER.error("ESPHome integration is not loaded!")
        return False

    # Get ESPHome devices correctly
    esphome_data = hass.data["esphome"]
    esphome_devices = esphome_data.devices if hasattr(esphome_data, "devices") else { _LOGGER.warning(f"NO DEVICES") }

    _LOGGER.warning(f"ESPHome Devices Found: {len(esphome_devices)}")

    # Filter only "connected-button" devices
    connected_buttons = [
        device for device in esphome_devices.values()
        _LOGGER.warning(f"Device Title: {device.config_entry.title.lower()}")
        _LOGGER.warning(f"Device Name: {device.config_entry.data.get('name', 'no-name')}")
        if "connected" in device.config_entry.data.get("name", "").lower()
    ]