Search in sources :

Example 21 with DiscoveryResult

use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.

the class FSInternetRadioDiscoveryParticipantJavaTest method validDiscoveryResultIfWithoutBaseUrl.

/**
 * Verify valid DiscoveryResult with FSInterntRadio device without base URL.
 *
 * @throws ValidationException
 */
@SuppressWarnings("null")
@Test
public void validDiscoveryResultIfWithoutBaseUrl() throws ValidationException {
    RemoteDevice fsInternetRadioDeviceWithoutUrl = createDefaultFSInternetRadioDevice(null);
    final DiscoveryResult result = discoveryParticipant.createResult(fsInternetRadioDeviceWithoutUrl);
    assertEquals(new ThingUID(DEFAULT_RADIO_THING_UID), result.getThingUID());
    assertEquals(FSInternetRadioBindingConstants.THING_TYPE_RADIO, result.getThingTypeUID());
    assertEquals(DEFAULT_RADIO_MANIFACTURER, result.getProperties().get(FSInternetRadioBindingConstants.PROPERTY_MANUFACTURER));
    assertEquals(DEFAULT_RADIO_MODEL_NUMBER, result.getProperties().get(FSInternetRadioBindingConstants.PROPERTY_MODEL));
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) RemoteDevice(org.jupnp.model.meta.RemoteDevice) Test(org.junit.Test)

Example 22 with DiscoveryResult

use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.

the class HueBridgeNupnpDiscovery method discoverHueBridges.

/**
 * Discover available Hue Bridges and then add them in the discovery inbox
 */
private void discoverHueBridges() {
    for (BridgeJsonParameters bridge : getBridgeList()) {
        if (isReachableAndValidHueBridge(bridge)) {
            String host = bridge.getInternalIpAddress();
            String serialNumber = bridge.getId().substring(0, 6) + bridge.getId().substring(10);
            ThingUID uid = new ThingUID(THING_TYPE_BRIDGE, serialNumber);
            DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(buildProperties(host, serialNumber)).withLabel(LABEL_PATTERN.replace("IP", host)).withRepresentationProperty(SERIAL_NUMBER).build();
            thingDiscovered(result);
        }
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Example 23 with DiscoveryResult

use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.

the class MagicDiscoveryService method startScan.

@Override
protected void startScan() {
    String serialNumber = createRandomSerialNumber();
    DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(new ThingUID(MagicBindingConstants.THING_TYPE_CONFIG_THING, serialNumber)).withRepresentationProperty(Thing.PROPERTY_SERIAL_NUMBER).withProperty(Thing.PROPERTY_SERIAL_NUMBER, serialNumber).withLabel("Magic Thing").build();
    thingDiscovered(discoveryResult);
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Example 24 with DiscoveryResult

use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.

the class DeviceDiscoveryService method onDeviceAddedInternal.

private void onDeviceAddedInternal(GeneralDeviceInformation device) {
    boolean isSupported = false;
    if (device instanceof Device) {
        Device tempDevice = (Device) device;
        if ((tempDevice.isSensorDevice() && deviceType.equals(tempDevice.getHWinfo().replaceAll("-", ""))) || (deviceType.equals(tempDevice.getHWinfo().substring(0, 2)) && (tempDevice.isDeviceWithOutput() || tempDevice.isBinaryInputDevice()) && tempDevice.isPresent())) {
            isSupported = true;
        }
    } else if (device instanceof Circuit && DsDeviceThingTypeProvider.SupportedThingTypes.circuit.toString().equals(deviceType)) {
        isSupported = true;
    }
    if (isSupported) {
        ThingUID thingUID = getThingUID(device);
        if (thingUID != null) {
            Map<String, Object> properties = new HashMap<>(1);
            properties.put(DigitalSTROMBindingConstants.DEVICE_DSID, device.getDSID().getValue());
            String deviceName = null;
            if (StringUtils.isNotBlank(device.getName())) {
                deviceName = device.getName();
            } else {
                // if no name is set, the dSID will be used as name
                deviceName = device.getDSID().getValue();
            }
            DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties).withBridge(bridgeUID).withLabel(deviceName).build();
            thingDiscovered(discoveryResult);
        } else {
            if (device instanceof Device) {
                logger.debug("Discovered unsupported device hardware type '{}' with uid {}", ((Device) device).getHWinfo(), device.getDSUID());
            }
        }
    } else {
        if (device instanceof Device) {
            logger.debug("Discovered device with disabled or no output mode. Device was not added to inbox. " + "Device information: hardware info: {}, dSUID: {}, device-name: {}, output value: {}", ((Device) device).getHWinfo(), device.getDSUID(), device.getName(), ((Device) device).getOutputMode());
        }
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) HashMap(java.util.HashMap) Device(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Device) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Circuit(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Circuit)

Example 25 with DiscoveryResult

use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.

the class SceneDiscoveryService method onSceneAddedInternal.

private void onSceneAddedInternal(InternalScene scene) {
    logger.debug("{}", scene.getSceneType());
    if (scene != null && scene.getSceneType().equals(sceneType)) {
        if (!ignoredScene(scene.getSceneID()) && !ignoreGroup(scene.getGroupID())) {
            ThingUID thingUID = getThingUID(scene);
            if (thingUID != null) {
                ThingUID bridgeUID = bridgeHandler.getThing().getUID();
                Map<String, Object> properties = new HashMap<>();
                properties.put(ZONE_ID, scene.getZoneID());
                properties.put(GROUP_ID, scene.getGroupID());
                if (SceneEnum.containsScene(scene.getSceneID())) {
                    properties.put(SCENE_ID, SceneEnum.getScene(scene.getSceneID()).toString());
                } else {
                    logger.debug("discovered scene: name '{}' with id {} have an invalid scene-ID", scene.getSceneName(), scene.getID());
                }
                DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties).withBridge(bridgeUID).withLabel(scene.getSceneName()).build();
                thingDiscovered(discoveryResult);
            } else {
                logger.debug("discovered unsupported scene: name '{}' with id {}", scene.getSceneName(), scene.getID());
            }
        }
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) HashMap(java.util.HashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Aggregations

DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)42 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)29 HashMap (java.util.HashMap)16 Test (org.junit.Test)14 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)12 Collection (java.util.Collection)4 DiscoveryListener (org.eclipse.smarthome.config.discovery.DiscoveryListener)4 DiscoveryService (org.eclipse.smarthome.config.discovery.DiscoveryService)4 ThingStatusInfo (org.eclipse.smarthome.core.thing.ThingStatusInfo)4 DiscoveryResultFlag (org.eclipse.smarthome.config.discovery.DiscoveryResultFlag)3 InboxPredicates.forThingUID (org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingUID)3 Thing (org.eclipse.smarthome.core.thing.Thing)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 Date (java.util.Date)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Collectors (java.util.stream.Collectors)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 Configuration (org.eclipse.smarthome.config.core.Configuration)2