Search in sources :

Example 56 with ThingUID

use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.

the class BridgeMDNSDiscoveryParticipant method getThingUID.

@Override
public ThingUID getThingUID(ServiceInfo service) {
    if (service.getApplication().contains("dssweb")) {
        String hostAddress = service.getName() + "." + service.getDomain() + ".";
        DsAPI digitalSTROMClient = new DsAPIImpl(hostAddress, Config.DEFAULT_CONNECTION_TIMEOUT, Config.DEFAULT_READ_TIMEOUT, true);
        Map<String, String> dsidMap = digitalSTROMClient.getDSID(null);
        String dSID = null;
        if (dsidMap != null) {
            dSID = dsidMap.get(JSONApiResponseKeysEnum.DSID.getKey());
        }
        if (StringUtils.isNotBlank(dSID)) {
            return new ThingUID(DigitalSTROMBindingConstants.THING_TYPE_DSS_BRIDGE, dSID);
        } else {
            logger.error("Can't get server dSID to generate thing UID. Please add the server manually.");
        }
    }
    return null;
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) DsAPI(org.eclipse.smarthome.binding.digitalstrom.internal.lib.serverconnection.DsAPI) DsAPIImpl(org.eclipse.smarthome.binding.digitalstrom.internal.lib.serverconnection.impl.DsAPIImpl)

Example 57 with ThingUID

use of org.eclipse.smarthome.core.thing.ThingUID 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 58 with ThingUID

use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.

the class DeviceDiscoveryService method getThingUID.

private ThingUID getThingUID(GeneralDeviceInformation device) {
    ThingUID bridgeUID = bridgeHandler.getThing().getUID();
    ThingTypeUID thingTypeUID = null;
    if (device instanceof Device) {
        Device tempDevice = (Device) device;
        thingTypeUID = new ThingTypeUID(BINDING_ID, tempDevice.getHWinfo().substring(0, 2));
        if (tempDevice.isSensorDevice() && deviceType.equals(tempDevice.getHWinfo().replaceAll("-", ""))) {
            thingTypeUID = new ThingTypeUID(BINDING_ID, deviceType);
        }
    } else {
        thingTypeUID = new ThingTypeUID(BINDING_ID, DsDeviceThingTypeProvider.SupportedThingTypes.circuit.toString());
    }
    if (getSupportedThingTypes().contains(thingTypeUID)) {
        String thingDeviceId = device.getDSID().toString();
        ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, thingDeviceId);
        return thingUID;
    } else {
        return null;
    }
}
Also used : Device(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Device) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID)

Example 59 with ThingUID

use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.

the class SceneDiscoveryService method getThingUID.

private ThingUID getThingUID(InternalScene scene) {
    ThingUID bridgeUID = bridgeHandler.getThing().getUID();
    ThingTypeUID thingTypeUID = new ThingTypeUID(BINDING_ID, sceneType);
    if (getSupportedThingTypes().contains(thingTypeUID)) {
        String thingSceneId = scene.getID();
        ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, thingSceneId);
        return thingUID;
    } else {
        return null;
    }
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID)

Example 60 with ThingUID

use of org.eclipse.smarthome.core.thing.ThingUID 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

ThingUID (org.eclipse.smarthome.core.thing.ThingUID)99 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)29 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)27 Thing (org.eclipse.smarthome.core.thing.Thing)26 Test (org.junit.Test)25 HashMap (java.util.HashMap)21 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)14 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 Path (javax.ws.rs.Path)9 JsonObject (com.google.gson.JsonObject)8 JsonParser (com.google.gson.JsonParser)7 RolesAllowed (javax.annotation.security.RolesAllowed)7 Locale (java.util.Locale)6 Nullable (org.eclipse.jdt.annotation.Nullable)6 Consumes (javax.ws.rs.Consumes)5 Configuration (org.eclipse.smarthome.config.core.Configuration)5 Collection (java.util.Collection)4 GET (javax.ws.rs.GET)4 InboxPredicates.forThingUID (org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingUID)4