/** * Copyright (c) 2014-2017 by the respective copyright holders. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ package org.eclipse.smarthome.binding.hue.internal.discovery; import static org.eclipse.smarthome.binding.hue.HueBindingConstants.*; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; import org.eclipse.smarthome.config.discovery.DiscoveryResult; import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder; import org.eclipse.smarthome.config.discovery.UpnpDiscoveryParticipant; import org.eclipse.smarthome.core.thing.ThingTypeUID; import org.eclipse.smarthome.core.thing.ThingUID; import org.jupnp.model.meta.DeviceDetails; import org.jupnp.model.meta.ModelDetails; import org.jupnp.model.meta.RemoteDevice; /** * The {@link HueBridgeDiscoveryParticipant} is responsible for discovering new and * removed hue bridges. It uses the central {@link UpnpDiscoveryService}. * * @author Kai Kreuzer - Initial contribution * @author Thomas Höfer - Added representation */ public class HueBridgeDiscoveryParticipant implements UpnpDiscoveryParticipant { @Override public Set<ThingTypeUID> getSupportedThingTypeUIDs() { return Collections.singleton(THING_TYPE_BRIDGE); } @Override public DiscoveryResult createResult(RemoteDevice device) { ThingUID uid = getThingUID(device); if (uid != null) { Map<String, Object> properties = new HashMap<>(2); properties.put(HOST, device.getDetails().getBaseURL().getHost()); properties.put(SERIAL_NUMBER, device.getDetails().getSerialNumber()); DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties) .withLabel(device.getDetails().getFriendlyName()).withRepresentationProperty(SERIAL_NUMBER).build(); return result; } else { return null; } } @Override public ThingUID getThingUID(RemoteDevice device) { DeviceDetails details = device.getDetails(); if (details != null) { ModelDetails modelDetails = details.getModelDetails(); if (modelDetails != null) { String modelName = modelDetails.getModelName(); if (modelName != null) { if (modelName.startsWith("Philips hue bridge")) { return new ThingUID(THING_TYPE_BRIDGE, details.getSerialNumber()); } } } } return null; } }