Java Code Examples for org.eclipse.smarthome.core.thing.Thing#getChannels()

The following examples show how to use org.eclipse.smarthome.core.thing.Thing#getChannels() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThingLinkManagerOSGiTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void assertThatLinksAreRemovedUponThingRemoval() {
    ThingUID thingUID = new ThingUID("hue:lamp:lamp1");
    Thing thing = thingRegistry.createThingOfType(new ThingTypeUID("hue:lamp"), thingUID, null, "test thing",
            new Configuration());

    List<Channel> channels = thing.getChannels();
    assertThat(channels.size(), is(1));
    Channel channel = channels.get(0);

    managedThingProvider.add(thing);
    waitForAssert(() -> assertThat(itemChannelLinkRegistry.getLinkedItems(channel.getUID()).size(), is(1)));

    managedThingProvider.remove(thingUID);
    waitForAssert(() -> assertThat(itemChannelLinkRegistry.getLinkedItems(channel.getUID()).size(), is(0)));
}
 
Example 2
Source File: ThingLinkManager.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void receiveTypedEvent(ThingStatusInfoChangedEvent event) {
    // when a thing handler is successfully initialized (i.e. it goes from INITIALIZING to UNKNOWN, ONLINE or
    // OFFLINE), we need to make sure that channelLinked() is called for all existing links
    if (ThingStatus.INITIALIZING.equals(event.getOldStatusInfo().getStatus())) {
        if (ThingHandlerHelper.isHandlerInitialized(event.getStatusInfo().getStatus())) {
            Thing thing = thingRegistry.get(event.getThingUID());
            if (thing != null) {
                for (Channel channel : thing.getChannels()) {
                    if (itemChannelLinkRegistry.getLinkedItemNames(channel.getUID()).size() > 0) {
                        informHandlerAboutLinkedChannel(thing, channel);
                    }
                }
            }
        }
    }
}
 
Example 3
Source File: ThingDTOMapper.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example 4
Source File: ThingLinkManager.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void added(Provider<Thing> provider, Thing thing) {
    List<Channel> channels = thing.getChannels();
    for (Channel channel : channels) {
        createLinkIfNotAdvanced(channel);
    }
}
 
Example 5
Source File: ThingLinkManager.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void removed(Provider<Thing> provider, Thing thing) {
    List<Channel> channels = thing.getChannels();
    for (Channel channel : channels) {
        ItemChannelLink link = new ItemChannelLink(deriveItemName(channel.getUID()), channel.getUID());
        itemChannelLinkRegistry.remove(link.getUID());
    }
}
 
Example 6
Source File: ChannelItemProvider.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void added(Thing element) {
    if (!initialized) {
        return;
    }
    for (Channel channel : element.getChannels()) {
        for (ItemChannelLink link : linkRegistry.getLinks(channel.getUID())) {
            createItemForLink(link);
        }
    }
}
 
Example 7
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isInitializable(Thing thing, ThingType thingType) {
    if (!isComplete(thingType, thing.getUID(), tt -> tt.getConfigDescriptionURI(), thing.getConfiguration())) {
        return false;
    }

    for (Channel channel : thing.getChannels()) {
        ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID());
        if (!isComplete(channelType, channel.getUID(), ct -> ct.getConfigDescriptionURI(),
                channel.getConfiguration())) {
            return false;
        }
    }

    return true;
}
 
Example 8
Source File: ThingHelper.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Indicates whether two {@link Thing}s are technical equal.
 *
 * @param a Thing object
 * @param b another Thing object
 * @return true whether a and b are equal, otherwise false
 */
public static boolean equals(Thing a, Thing b) {
    if (!a.getUID().equals(b.getUID())) {
        return false;
    }
    // bridge
    if (!Objects.equals(a.getBridgeUID(), b.getBridgeUID())) {
        return false;
    }
    // configuration
    if (!Objects.equals(a.getConfiguration(), b.getConfiguration())) {
        return false;
    }
    // label
    if (!Objects.equals(a.getLabel(), b.getLabel())) {
        return false;
    }
    // location
    if (!Objects.equals(a.getLocation(), b.getLocation())) {
        return false;
    }
    // channels
    List<Channel> channelsOfA = a.getChannels();
    List<Channel> channelsOfB = b.getChannels();
    if (channelsOfA.size() != channelsOfB.size()) {
        return false;
    }
    if (!toString(channelsOfA).equals(toString(channelsOfB))) {
        return false;
    }
    return true;
}
 
Example 9
Source File: ThingResource.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private Map<String, Set<String>> getLinkedItemsMap(Thing thing) {
    Map<String, Set<String>> linkedItemsMap = new HashMap<>();
    for (Channel channel : thing.getChannels()) {
        Set<String> linkedItems = itemChannelLinkRegistry.getLinkedItemNames(channel.getUID());
        linkedItemsMap.put(channel.getUID().getId(), linkedItems);
    }
    return linkedItemsMap;
}
 
Example 10
Source File: HomematicBridgeHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Updates the thing for the given Homematic device.
 */
private void updateThing(HmDevice device) {
    Thing hmThing = getThingByUID(UidUtils.generateThingUID(device, getThing()));
    if (hmThing != null) {
        HomematicThingHandler thingHandler = (HomematicThingHandler) hmThing.getHandler();
        if (thingHandler != null) {
            thingHandler.thingUpdated(hmThing);
            for (Channel channel : hmThing.getChannels()) {
                thingHandler.handleRefresh(channel.getUID());
            }
        }
    }
}