Search in sources :

Example 41 with ThingUID

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

the class SonosHandlerFactory method createThing.

@Override
public Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID, ThingUID bridgeUID) {
    if (SonosBindingConstants.SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) {
        ThingUID sonosDeviceUID = getPlayerUID(thingTypeUID, thingUID, configuration);
        logger.debug("Creating a sonos thing with ID '{}'", sonosDeviceUID);
        return super.createThing(thingTypeUID, configuration, sonosDeviceUID, null);
    }
    throw new IllegalArgumentException("The thing type " + thingTypeUID + " is not supported by the sonos binding.");
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Example 42 with ThingUID

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

the class LIRCRemoteDiscoveryService method addRemote.

private void addRemote(ThingUID bridge, String remote) {
    ThingTypeUID uid = LIRCBindingConstants.THING_TYPE_REMOTE;
    ThingUID thingUID = new ThingUID(uid, bridge, remote);
    if (thingUID != null) {
        if (discoveryServiceCallback != null && discoveryServiceCallback.getExistingDiscoveryResult(thingUID) != null) {
            // Ignore this remote as we already know about it
            logger.debug("Remote {}: Already known.", remote);
            return;
        }
        logger.trace("Remote {}: Discovered new remote.", remote);
        Map<String, Object> properties = new HashMap<>(1);
        properties.put(LIRCBindingConstants.PROPERTY_REMOTE, remote);
        DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withLabel(remote).withBridge(bridge).withProperties(properties).build();
        thingDiscovered(discoveryResult);
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) HashMap(java.util.HashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID)

Example 43 with ThingUID

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

the class DiscoveryServiceRegistryOSGiTest method testGetExistingThing.

@Test
public void testGetExistingThing() {
    ThingUID thingUID = new ThingUID(EXTENDED_BINDING_ID, "foo");
    // verify that the callback has been set
    assertNotNull(extendedDiscoveryServiceMock.discoveryServiceCallback);
    // verify that the thing cannot be found if it's not there
    assertNull(extendedDiscoveryServiceMock.discoveryServiceCallback.getExistingThing(thingUID));
    thingRegistry.add(ThingBuilder.create(new ThingTypeUID(EXTENDED_BINDING_ID, EXTENDED_THING_TYPE), thingUID).build());
    // verify that the existing Thing can be accessed
    assertNotNull(extendedDiscoveryServiceMock.discoveryServiceCallback.getExistingThing(thingUID));
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 44 with ThingUID

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

the class ThingHelper method merge.

/**
 * Merges the content of a ThingDTO with an existing Thing.
 * Where ever the DTO has null values, the content of the original Thing is kept.
 * Where ever the DTO has non-null values, these are used.
 * In consequence, care must be taken when the content of a list (like configuration, properties or channels) is to
 * be updated - the DTO must contain the full list, otherwise entries will be deleted.
 *
 * @param thing the Thing instance to merge the new content into
 * @param updatedContents a DTO which carries the updated content
 * @return A Thing instance, which is the result of the merge
 */
public static Thing merge(Thing thing, ThingDTO updatedContents) {
    ThingBuilder builder;
    if (thing instanceof Bridge) {
        builder = BridgeBuilder.create(thing.getThingTypeUID(), thing.getUID());
    } else {
        builder = ThingBuilder.create(thing.getThingTypeUID(), thing.getUID());
    }
    // Update the label
    if (updatedContents.label != null) {
        builder.withLabel(updatedContents.label);
    } else {
        builder.withLabel(thing.getLabel());
    }
    // Update the location
    if (updatedContents.location != null) {
        builder.withLocation(updatedContents.location);
    } else {
        builder.withLocation(thing.getLocation());
    }
    // update bridge UID
    if (updatedContents.bridgeUID != null) {
        builder.withBridge(new ThingUID(updatedContents.bridgeUID));
    } else {
        builder.withBridge(thing.getBridgeUID());
    }
    // update thing configuration
    if (updatedContents.configuration != null && !updatedContents.configuration.keySet().isEmpty()) {
        builder.withConfiguration(new Configuration(updatedContents.configuration));
    } else {
        builder.withConfiguration(thing.getConfiguration());
    }
    // update thing properties
    if (updatedContents.properties != null) {
        builder.withProperties(updatedContents.properties);
    } else {
        builder.withProperties(thing.getProperties());
    }
    // Update the channels
    if (updatedContents.channels != null) {
        for (ChannelDTO channelDTO : updatedContents.channels) {
            builder.withChannel(ChannelDTOMapper.map(channelDTO));
        }
    } else {
        builder.withChannels(thing.getChannels());
    }
    if (updatedContents.location != null) {
        builder.withLocation(updatedContents.location);
    } else {
        builder.withLocation(thing.getLocation());
    }
    Thing mergedThing = builder.build();
    // keep all child things in place on a merged bridge
    if (mergedThing instanceof BridgeImpl && thing instanceof Bridge) {
        Bridge bridge = (Bridge) thing;
        BridgeImpl mergedBridge = (BridgeImpl) mergedThing;
        for (Thing child : bridge.getThings()) {
            mergedBridge.addThing(child);
        }
    }
    return mergedThing;
}
Also used : BridgeImpl(org.eclipse.smarthome.core.thing.internal.BridgeImpl) ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) Configuration(org.eclipse.smarthome.config.core.Configuration) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ChannelDTO(org.eclipse.smarthome.core.thing.dto.ChannelDTO) Bridge(org.eclipse.smarthome.core.thing.Bridge) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 45 with ThingUID

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

the class FSInternetRadioDiscoveryParticipant method createResult.

@Override
public DiscoveryResult createResult(RemoteDevice device) {
    final ThingUID uid = getThingUID(device);
    if (uid != null) {
        final Map<String, Object> properties = new HashMap<>(1);
        final String ip = getIp(device);
        if (ip != null) {
            properties.put(CONFIG_PROPERTY_IP, ip);
            // add manufacturer and model, if provided
            final String manufacturer = getManufacturer(device);
            if (manufacturer != null) {
                properties.put(PROPERTY_MANUFACTURER, manufacturer);
            }
            final String model = getModel(device);
            if (model != null) {
                properties.put(PROPERTY_MODEL, model);
            }
            final DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(device.getDisplayString()).build();
            return result;
        }
    }
    return null;
}
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