def service_handler(service):
    'Dispatch service calls to target entities.'
    params = {key: value for (key, value) in service.data.items() if (key != ATTR_ENTITY_ID)}
    entity_ids = service.data.get(ATTR_ENTITY_ID)
    if entity_ids:
        target_devices = [dev for dev in hass.data[DATA_KEY].values() if (dev.entity_id in entity_ids)]
    else:
        target_devices = hass.data[DATA_KEY].values()
    for target_device in target_devices:
        if (service.service == SERVICE_SET_MODE):
            target_device.set_mode(**params)
Dispatch service calls to target entities.
def service_handler(service):
    
    params = {key: value for (key, value) in service.data.items() if (key != ATTR_ENTITY_ID)}
    entity_ids = service.data.get(ATTR_ENTITY_ID)
    if entity_ids:
        target_devices = [dev for dev in hass.data[DATA_KEY].values() if (dev.entity_id in entity_ids)]
    else:
        target_devices = hass.data[DATA_KEY].values()
    for target_device in target_devices:
        if (service.service == SERVICE_SET_MODE):
            target_device.set_mode(**params)