Search in sources :

Example 26 with ThingUID

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

the class ThingConsoleCommandExtension method printThings.

private void printThings(Console console, Collection<Thing> things) {
    if (things.isEmpty()) {
        console.println("No things found.");
    }
    for (Thing thing : things) {
        String id = thing.getUID().toString();
        String thingType = thing instanceof Bridge ? "Bridge" : "Thing";
        ThingStatusInfo status = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, null);
        ThingUID bridgeUID = thing.getBridgeUID();
        String label = thing.getLabel();
        console.println(String.format("%s (Type=%s, Status=%s, Label=%s, Bridge=%s)", id, thingType, status, label, bridgeUID));
    }
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo) Thing(org.eclipse.smarthome.core.thing.Thing) Bridge(org.eclipse.smarthome.core.thing.Bridge)

Example 27 with ThingUID

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

the class BaseThingHandlerFactory method createThing.

/**
 * Creates a thing based on given thing type uid.
 *
 * @param thingTypeUID thing type uid (must not be null)
 * @param thingUID thingUID (can be null)
 * @param configuration (must not be null)
 * @param bridgeUID (can be null)
 * @return thing (can be null, if thing type is unknown)
 */
@Override
@Nullable
public Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, @Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) {
    ThingUID effectiveUID = thingUID != null ? thingUID : ThingFactory.generateRandomThingUID(thingTypeUID);
    ThingType thingType = getThingTypeByUID(thingTypeUID);
    if (thingType != null) {
        Thing thing = ThingFactory.createThing(thingType, effectiveUID, configuration, bridgeUID, getConfigDescriptionRegistry());
        return thing;
    } else {
        return null;
    }
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) Thing(org.eclipse.smarthome.core.thing.Thing) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 28 with ThingUID

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

the class ThingDTOMapper method map.

/**
 * Maps thing DTO into thing
 *
 * @param thingDTO the thingDTO
 * @return the corresponding thing
 */
public static Thing map(ThingDTO thingDTO) {
    ThingUID thingUID = new ThingUID(thingDTO.UID);
    ThingTypeUID thingTypeUID = thingDTO.thingTypeUID == null ? new ThingTypeUID("") : new ThingTypeUID(thingDTO.thingTypeUID);
    Thing thing = ThingBuilder.create(thingTypeUID, thingUID).build();
    return ThingHelper.merge(thing, thingDTO);
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 29 with ThingUID

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

the class ThingDTOMapper method map.

/**
 * Maps thing into thing data transfer object (DTO).
 *
 * @param thing the thing
 * @return the thing DTO object
 */
public static ThingDTO map(Thing thing) {
    List<ChannelDTO> channelDTOs = new ArrayList<>();
    for (Channel channel : thing.getChannels()) {
        ChannelDTO channelDTO = ChannelDTOMapper.map(channel);
        channelDTOs.add(channelDTO);
    }
    String thingTypeUID = thing.getThingTypeUID().getAsString();
    String thingUID = thing.getUID().toString();
    final ThingUID bridgeUID = thing.getBridgeUID();
    return new ThingDTO(thingTypeUID, thingUID, thing.getLabel(), bridgeUID != null ? bridgeUID.toString() : null, channelDTOs, toMap(thing.getConfiguration()), thing.getProperties(), thing.getLocation());
}
Also used : Channel(org.eclipse.smarthome.core.thing.Channel) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ArrayList(java.util.ArrayList)

Example 30 with ThingUID

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

the class ThingEventFactory method createStatusInfoEvent.

private Event createStatusInfoEvent(String topic, String payload) throws Exception {
    String[] topicElements = getTopicElements(topic);
    if (topicElements.length != 4) {
        throw new IllegalArgumentException("ThingStatusInfoEvent creation failed, invalid topic: " + topic);
    }
    ThingUID thingUID = new ThingUID(topicElements[2]);
    ThingStatusInfo thingStatusInfo = deserializePayload(payload, ThingStatusInfo.class);
    return new ThingStatusInfoEvent(topic, payload, thingUID, thingStatusInfo);
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo)

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