Exemple #1
0
async def async_setup_platform(hass,
                               config,
                               async_add_devices,
                               discovery_info=None):
    """Set up Scenes."""
    if discovery_info is None:
        return
    value_template = config.get(CONF_VALUE_TEMPLATE)
    if value_template is not None:
        value_template.hass = hass

    config = hass.data[DOMAIN]
    loxconfig = config['loxconfig']

    async def async_call():
        devices = []
        entity_ids = hass.states.async_entity_ids("LIGHT")
        for _ in entity_ids:
            state = hass.states.get(_)
            att = state.attributes
            if "plattform" in att and att['plattform'] == DOMAIN:
                entity = hass.data['light'].get_entity(state.entity_id)
                if entity.device_class == "lightcontrollerv2":
                    for effect in entity.effect_list:
                        mood_id = entity.get_id_by_moodname(effect)
                        uuid = entity.uuid
                        devices.append(
                            Loxonelightscene(
                                "{}_{}".format(entity.name, effect), mood_id,
                                uuid))
        async_add_devices(devices)

    if config[CONF_SCENE_GEN]:
        async_call_later(hass, 0.2, async_call())
    return True
Exemple #2
0
async def async_setup_entry(hass, config_entry, async_add_devices):
    """Set up Scenes."""
    delay_scene = config_entry.options.get("generate_scenes_delay",
                                           DEFAULT_DELAY_SCENE)

    miniserver = get_miniserver_from_config(hass, hass.data[DOMAIN])
    if miniserver is None:
        return False

    async def gen_scenes(_):
        devices = []
        entity_ids = hass.states.async_entity_ids("LIGHT")
        for _ in entity_ids:
            state = hass.states.get(_)
            att = state.attributes
            if "plattform" in att and att['plattform'] == DOMAIN:
                entity = hass.data['light'].get_entity(state.entity_id)
                if entity.device_class == "LightControllerV2":
                    for effect in entity.effect_list:
                        mood_id = entity.get_id_by_moodname(effect)
                        uuid = entity.uuidAction
                        devices.append(
                            Loxonelightscene(
                                "{}-{}".format(entity.name, effect), mood_id,
                                uuid))
        async_add_devices(devices, True)

    if miniserver.config_entry.options.get(CONF_SCENE_GEN, False):
        async_call_later(hass, delay_scene, gen_scenes)

    return True