Search in sources :

Example 1 with ThingDTO

use of org.eclipse.smarthome.core.thing.dto.ThingDTO in project smarthome by eclipse.

the class EnrichedThingDTOMapper method map.

/**
 * Maps thing into enriched thing data transfer object.
 *
 * @param thing the thing
 * @param thingStatusInfo the thing status information to be used for the enriched object
 * @param firmwareStatus the firmwareStatus to be used for the enriched object
 * @param linkedItemsMap the map of linked items to be injected into the enriched object
 * @param editable true if this thing can be edited
 * @return the enriched thing DTO object
 */
public static EnrichedThingDTO map(Thing thing, ThingStatusInfo thingStatusInfo, FirmwareStatusDTO firmwareStatus, Map<String, Set<String>> linkedItemsMap, boolean editable) {
    ThingDTO thingDTO = ThingDTOMapper.map(thing);
    List<ChannelDTO> channels = new ArrayList<>();
    for (ChannelDTO channel : thingDTO.channels) {
        Set<String> linkedItems = linkedItemsMap != null ? linkedItemsMap.get(channel.id) : Collections.emptySet();
        channels.add(new EnrichedChannelDTO(channel, linkedItems));
    }
    return new EnrichedThingDTO(thingDTO, channels, thingStatusInfo, firmwareStatus, editable);
}
Also used : ThingDTO(org.eclipse.smarthome.core.thing.dto.ThingDTO) ChannelDTO(org.eclipse.smarthome.core.thing.dto.ChannelDTO) ArrayList(java.util.ArrayList)

Example 2 with ThingDTO

use of org.eclipse.smarthome.core.thing.dto.ThingDTO in project smarthome by eclipse.

the class ThingEventFactory method createUpdateEvent.

/**
 * Creates a thing updated event.
 *
 * @param thing the thing
 * @param oldThing the old thing
 * @return the created thing updated event
 * @throws IllegalArgumentException if thing or oldThing is null
 */
public static ThingUpdatedEvent createUpdateEvent(Thing thing, Thing oldThing) {
    assertValidArgument(thing);
    assertValidArgument(oldThing);
    String topic = buildTopic(THING_UPDATED_EVENT_TOPIC, thing.getUID());
    ThingDTO thingDTO = map(thing);
    ThingDTO oldThingDTO = map(oldThing);
    List<ThingDTO> thingDTOs = new LinkedList<>();
    thingDTOs.add(thingDTO);
    thingDTOs.add(oldThingDTO);
    String payload = serializePayload(thingDTOs);
    return new ThingUpdatedEvent(topic, payload, thingDTO, oldThingDTO);
}
Also used : ThingDTO(org.eclipse.smarthome.core.thing.dto.ThingDTO) LinkedList(java.util.LinkedList)

Example 3 with ThingDTO

use of org.eclipse.smarthome.core.thing.dto.ThingDTO in project smarthome by eclipse.

the class ThingEventFactory method createAddedEvent.

/**
 * Creates a thing added event.
 *
 * @param thing the thing
 * @return the created thing added event
 * @throws IllegalArgumentException if thing is null
 */
public static ThingAddedEvent createAddedEvent(Thing thing) {
    assertValidArgument(thing);
    String topic = buildTopic(THING_ADDED_EVENT_TOPIC, thing.getUID());
    ThingDTO thingDTO = map(thing);
    String payload = serializePayload(thingDTO);
    return new ThingAddedEvent(topic, payload, thingDTO);
}
Also used : ThingDTO(org.eclipse.smarthome.core.thing.dto.ThingDTO)

Example 4 with ThingDTO

use of org.eclipse.smarthome.core.thing.dto.ThingDTO in project smarthome by eclipse.

the class ThingEventFactory method createRemovedEvent.

/**
 * Creates a thing removed event.
 *
 * @param thing the thing
 * @return the created thing removed event
 * @throws IllegalArgumentException if thing is null
 */
public static ThingRemovedEvent createRemovedEvent(Thing thing) {
    assertValidArgument(thing);
    String topic = buildTopic(THING_REMOVED_EVENT_TOPIC, thing.getUID());
    ThingDTO thingDTO = map(thing);
    String payload = serializePayload(thingDTO);
    return new ThingRemovedEvent(topic, payload, thingDTO);
}
Also used : ThingDTO(org.eclipse.smarthome.core.thing.dto.ThingDTO)

Aggregations

ThingDTO (org.eclipse.smarthome.core.thing.dto.ThingDTO)4 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 ChannelDTO (org.eclipse.smarthome.core.thing.dto.ChannelDTO)1