def _switches_with_lights(
    hass: HomeAssistant,
    lights: list[str],
    expand_light_groups: bool = True,
) -> list[AdaptiveSwitch]:
    """Get all switches that control at least one of the lights passed."""
    config_entries = hass.config_entries.async_entries(DOMAIN)
    data = hass.data[DOMAIN]
    switches = []
    all_check_lights = (
        _expand_light_groups(hass, lights) if expand_light_groups else set(lights)
    )
    for config in config_entries:
        entry = data.get(config.entry_id)
        if entry is None:  # entry might be disabled and therefore missing
            continue
        switch = data[config.entry_id][SWITCH_DOMAIN]
        switch._expand_light_groups()
        # Check if any of the lights are in the switch's lights
        if set(switch.lights) & set(all_check_lights):
            switches.append(switch)
    return switches
Get all switches that control at least one of the lights passed.
custom_components/adaptive_lighting/switch.py