def setup_platform(hass, config, add_devices, discovery_info=None):
    'Set up the Bose Soundtouch platform.'
    if (DATA_SOUNDTOUCH not in hass.data):
        hass.data[DATA_SOUNDTOUCH] = []
    if discovery_info:
        host = discovery_info['host']
        port = int(discovery_info['port'])
        if (host in [device.config['host'] for device in hass.data[DATA_SOUNDTOUCH]]):
            return
        remote_config = {'id': 'ha.component.soundtouch', 'host': host, 'port': port}
        soundtouch_device = SoundTouchDevice(None, remote_config)
        hass.data[DATA_SOUNDTOUCH].append(soundtouch_device)
        add_devices([soundtouch_device])
    else:
        name = config.get(CONF_NAME)
        remote_config = {'id': 'ha.component.soundtouch', 'port': config.get(CONF_PORT), 'host': config.get(CONF_HOST)}
        soundtouch_device = SoundTouchDevice(name, remote_config)
        hass.data[DATA_SOUNDTOUCH].append(soundtouch_device)
        add_devices([soundtouch_device])

    def service_handle(service):
        'Handle the applying of a service.'
        master_device_id = service.data.get('master')
        slaves_ids = service.data.get('slaves')
        slaves = []
        if slaves_ids:
            slaves = [device for device in hass.data[DATA_SOUNDTOUCH] if (device.entity_id in slaves_ids)]
        master = next([device for device in hass.data[DATA_SOUNDTOUCH] if (device.entity_id == master_device_id)].__iter__(), None)
        if (master is None):
            _LOGGER.warning('Unable to find master with entity_id: %s', str(master_device_id))
            return
        if (service.service == SERVICE_PLAY_EVERYWHERE):
            slaves = [d for d in hass.data[DATA_SOUNDTOUCH] if (d.entity_id != master_device_id)]
            master.create_zone(slaves)
        elif (service.service == SERVICE_CREATE_ZONE):
            master.create_zone(slaves)
        elif (service.service == SERVICE_REMOVE_ZONE_SLAVE):
            master.remove_zone_slave(slaves)
        elif (service.service == SERVICE_ADD_ZONE_SLAVE):
            master.add_zone_slave(slaves)
    hass.services.register(DOMAIN, SERVICE_PLAY_EVERYWHERE, service_handle, schema=SOUNDTOUCH_PLAY_EVERYWHERE)
    hass.services.register(DOMAIN, SERVICE_CREATE_ZONE, service_handle, schema=SOUNDTOUCH_CREATE_ZONE_SCHEMA)
    hass.services.register(DOMAIN, SERVICE_REMOVE_ZONE_SLAVE, service_handle, schema=SOUNDTOUCH_REMOVE_ZONE_SCHEMA)
    hass.services.register(DOMAIN, SERVICE_ADD_ZONE_SLAVE, service_handle, schema=SOUNDTOUCH_ADD_ZONE_SCHEMA)
Set up the Bose Soundtouch platform.
def setup_platform(hass, config, add_devices, discovery_info=None):
    
    if (DATA_SOUNDTOUCH not in hass.data):
        hass.data[DATA_SOUNDTOUCH] = []
    if discovery_info:
        host = discovery_info['host']
        port = int(discovery_info['port'])
        if (host in [device.config['host'] for device in hass.data[DATA_SOUNDTOUCH]]):
            return
        remote_config = {'id': 'ha.component.soundtouch', 'host': host, 'port': port}
        soundtouch_device = SoundTouchDevice(None, remote_config)
        hass.data[DATA_SOUNDTOUCH].append(soundtouch_device)
        add_devices([soundtouch_device])
    else:
        name = config.get(CONF_NAME)
        remote_config = {'id': 'ha.component.soundtouch', 'port': config.get(CONF_PORT), 'host': config.get(CONF_HOST)}
        soundtouch_device = SoundTouchDevice(name, remote_config)
        hass.data[DATA_SOUNDTOUCH].append(soundtouch_device)
        add_devices([soundtouch_device])

    def service_handle(service):
        'Handle the applying of a service.'
        master_device_id = service.data.get('master')
        slaves_ids = service.data.get('slaves')
        slaves = []
        if slaves_ids:
            slaves = [device for device in hass.data[DATA_SOUNDTOUCH] if (device.entity_id in slaves_ids)]
        master = next([device for device in hass.data[DATA_SOUNDTOUCH] if (device.entity_id == master_device_id)].__iter__(), None)
        if (master is None):
            _LOGGER.warning('Unable to find master with entity_id: %s', str(master_device_id))
            return
        if (service.service == SERVICE_PLAY_EVERYWHERE):
            slaves = [d for d in hass.data[DATA_SOUNDTOUCH] if (d.entity_id != master_device_id)]
            master.create_zone(slaves)
        elif (service.service == SERVICE_CREATE_ZONE):
            master.create_zone(slaves)
        elif (service.service == SERVICE_REMOVE_ZONE_SLAVE):
            master.remove_zone_slave(slaves)
        elif (service.service == SERVICE_ADD_ZONE_SLAVE):
            master.add_zone_slave(slaves)
    hass.services.register(DOMAIN, SERVICE_PLAY_EVERYWHERE, service_handle, schema=SOUNDTOUCH_PLAY_EVERYWHERE)
    hass.services.register(DOMAIN, SERVICE_CREATE_ZONE, service_handle, schema=SOUNDTOUCH_CREATE_ZONE_SCHEMA)
    hass.services.register(DOMAIN, SERVICE_REMOVE_ZONE_SLAVE, service_handle, schema=SOUNDTOUCH_REMOVE_ZONE_SCHEMA)
    hass.services.register(DOMAIN, SERVICE_ADD_ZONE_SLAVE, service_handle, schema=SOUNDTOUCH_ADD_ZONE_SCHEMA)