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));
}
}
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;
}
}
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);
}
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());
}
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);
}
Aggregations