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

The following examples show how to use org.eclipse.smarthome.core.thing.Thing#getChannel() . 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: ThingLinkManager.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void added(ItemChannelLink itemChannelLink) {
    if (itemRegistry.get(itemChannelLink.getItemName()) == null) {
        // Don't inform about the link if the item does not exist.
        // The handler will be informed on item creation.
        return;
    }
    ChannelUID channelUID = itemChannelLink.getLinkedUID();
    Thing thing = thingRegistry.get(channelUID.getThingUID());
    if (thing != null) {
        Channel channel = thing.getChannel(channelUID.getId());
        if (channel != null) {
            ThingLinkManager.this.informHandlerAboutLinkedChannel(thing, channel);
        }
    }
}
 
Example 2
Source File: ThingLinkManager.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void removed(ItemChannelLink itemChannelLink) {
    /*
     * Don't check for item existence here.
     * If an item and its link are removed before the registry change listener methods are called,
     * a check for the item could prevent that the handler is informed about the unlink at all.
     */
    ChannelUID channelUID = itemChannelLink.getLinkedUID();
    Thing thing = thingRegistry.get(channelUID.getThingUID());
    if (thing != null) {
        Channel channel = thing.getChannel(channelUID.getId());
        if (channel != null) {
            ThingLinkManager.this.informHandlerAboutUnlinkedChannel(thing, channel);
        }
    }
}
 
Example 3
Source File: ItemChannelLinkConfigDescriptionProvider.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ConfigDescription getConfigDescription(URI uri, Locale locale) {
    if (SCHEME.equals(uri.getScheme())) {
        ItemChannelLink link = itemChannelLinkRegistry.get(uri.getSchemeSpecificPart());
        if (link == null) {
            return null;
        }
        Item item = itemRegistry.get(link.getItemName());
        if (item == null) {
            return null;
        }
        Thing thing = thingRegistry.get(link.getLinkedUID().getThingUID());
        if (thing == null) {
            return null;
        }
        Channel channel = thing.getChannel(link.getLinkedUID().getId());
        if (channel == null) {
            return null;
        }
        ConfigDescriptionParameter paramProfile = ConfigDescriptionParameterBuilder.create(PARAM_PROFILE, Type.TEXT)
                .withLabel("Profile").withDescription("the profile to use").withRequired(false)
                .withLimitToOptions(true).withOptions(getOptions(link, item, channel, locale)).build();
        return new ConfigDescription(uri, Collections.singletonList(paramProfile));
    }
    return null;
}
 
Example 4
Source File: CommunicationManager.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private @Nullable ProfileTypeUID determineProfileTypeUID(ItemChannelLink link, Item item, @Nullable Thing thing) {
    ProfileTypeUID profileTypeUID = getConfiguredProfileTypeUID(link);
    Channel channel = null;
    if (profileTypeUID == null) {
        if (thing == null) {
            return null;
        }

        channel = thing.getChannel(link.getLinkedUID().getId());
        if (channel == null) {
            return null;
        }

        // ask advisors
        profileTypeUID = getAdvice(link, item, channel);

        if (profileTypeUID == null) {
            // ask default advisor
            logger.trace("No profile advisor found for link {}, falling back to the defaults", link);
            profileTypeUID = defaultProfileFactory.getSuggestedProfileTypeUID(channel, item.getType());
        }
    }
    return profileTypeUID;
}
 
Example 5
Source File: DS2438.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void configureChannels() {
    Thing thing = callback.getThing();

    Channel humidityChannel = thing.getChannel(CHANNEL_HUMIDITY);
    if (humidityChannel != null) {
        Configuration channelConfiguration = humidityChannel.getConfiguration();
        if (channelConfiguration.get(CONFIG_HUMIDITY) != null) {
            humidityParameter.set(THING_TYPE_OWSERVER,
                    new OwserverDeviceParameter((String) channelConfiguration.get(CONFIG_HUMIDITY)));
        } else {
            humidityParameter.set(THING_TYPE_OWSERVER, new OwserverDeviceParameter("/humidity"));
        }
    }

    isConfigured = true;
}
 
Example 6
Source File: DS18x20.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void configureChannels() throws OwException {
    Thing thing = callback.getThing();
    Channel temperatureChannel = thing.getChannel(CHANNEL_TEMPERATURE);

    if (temperatureChannel != null) {
        Configuration channelConfiguration = temperatureChannel.getConfiguration();
        if (channelConfiguration.containsKey(CONFIG_RESOLUTION)) {
            temperatureParamater.set(THING_TYPE_OWSERVER, new OwserverDeviceParameter(
                    "/temperature" + (String) channelConfiguration.get(CONFIG_RESOLUTION)));
        } else {
            temperatureParamater.set(THING_TYPE_OWSERVER, new OwserverDeviceParameter("/temperature"));
        }
        if (channelConfiguration.containsKey(CONFIG_IGNORE_POR)) {
            ignorePOR = (Boolean) channelConfiguration.get(CONFIG_IGNORE_POR);
        } else {
            ignorePOR = false;
        }
    } else {
        throw new OwException(CHANNEL_TEMPERATURE + " not found");
    }

    isConfigured = true;
}
 
Example 7
Source File: DS1923.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void configureChannels() throws OwException {
    Thing thing = callback.getThing();
    Channel temperatureChannel = thing.getChannel(CHANNEL_TEMPERATURE);

    if (temperatureChannel != null) {
        temperatureParameter.set(THING_TYPE_OWSERVER, new OwserverDeviceParameter("/temperature"));
    } else {
        throw new OwException(CHANNEL_TEMPERATURE + " not found");
    }

    Channel humidityChannel = thing.getChannel(CHANNEL_HUMIDITY);
    if (humidityChannel != null) {
        humidityParameterR.set(THING_TYPE_OWSERVER, new OwserverDeviceParameter("/humidity"));
    }

    isConfigured = true;
}
 
Example 8
Source File: ChannelStateDescriptionProviderOSGiTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private static @NonNull Channel getChannel(final @NonNull Thing thing, final @NonNull String channelId) {
    final Channel channel = thing.getChannel(channelId);
    if (channel == null) {
        throw new IllegalArgumentException(String.format("The thing '%s' does not seems to contain a channel '%s'.",
                thing.getUID(), channelId));
    } else {
        return channel;
    }
}
 
Example 9
Source File: ThingLinkManager.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void added(Item element) {
    for (final ChannelUID channelUID : itemChannelLinkRegistry.getBoundChannels(element.getName())) {
        final Thing thing = thingRegistry.get(channelUID.getThingUID());
        if (thing != null) {
            final Channel channel = thing.getChannel(channelUID.getId());
            if (channel != null) {
                ThingLinkManager.this.informHandlerAboutLinkedChannel(thing, channel);
            }
        }
    }
}
 
Example 10
Source File: ThingLinkManager.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void removed(Item element) {
    for (final ChannelUID channelUID : itemChannelLinkRegistry.getBoundChannels(element.getName())) {
        final Thing thing = thingRegistry.get(channelUID.getThingUID());
        if (thing != null) {
            final Channel channel = thing.getChannel(channelUID.getId());
            if (channel != null) {
                ThingLinkManager.this.informHandlerAboutUnlinkedChannel(thing, channel);
            }
        }
    }
}
 
Example 11
Source File: ThingConfigDescriptionAliasProvider.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private @Nullable URI getChannelConfigDescriptionURI(URI uri) {
    String stringUID = uri.getSchemeSpecificPart();
    if (uri.getFragment() != null) {
        stringUID = stringUID + "#" + uri.getFragment();
    }
    ChannelUID channelUID = new ChannelUID(stringUID);
    ThingUID thingUID = channelUID.getThingUID();

    // First, get the thing so we get access to the channel type via the channel
    Thing thing = thingRegistry.get(thingUID);
    if (thing == null) {
        return null;
    }

    Channel channel = thing.getChannel(channelUID.getId());
    if (channel == null) {
        return null;
    }

    ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID());
    if (channelType == null) {
        return null;
    }

    // Get the config description URI for this channel type
    URI configURI = channelType.getConfigDescriptionURI();
    return configURI;
}
 
Example 12
Source File: ThingRegistryImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Channel getChannel(ChannelUID channelUID) {
    ThingUID thingUID = channelUID.getThingUID();
    Thing thing = get(thingUID);
    if (thing != null) {
        return thing.getChannel(channelUID.getId());
    }
    return null;
}
 
Example 13
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ChannelBuilder editChannel(Thing thing, ChannelUID channelUID) {
    Channel channel = thing.getChannel(channelUID.getId());
    if (channel == null) {
        throw new IllegalArgumentException(
                String.format("Channel '%s' does not exist for thing '%s'", channelUID, thing.getUID()));
    }
    return ChannelBuilder.create(channel);
}
 
Example 14
Source File: AbstractDigitalOwDevice.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void configureChannels() throws OwException {
    Thing thing = callback.getThing();
    OwDynamicStateDescriptionProvider dynamicStateDescriptionProvider = callback
            .getDynamicStateDescriptionProvider();

    for (Integer i = 0; i < ioConfig.size(); i++) {
        String channelId = ioConfig.get(i).getChannelId();
        Channel channel = thing.getChannel(channelId);

        if (channel != null) {
            Configuration channelConfig = channel.getConfiguration();

            try {
                if (channelConfig.get(CONFIG_DIGITAL_MODE) != null) {
                    ioConfig.get(i).setIoMode((String) channelConfig.get(CONFIG_DIGITAL_MODE));
                }
                if (channelConfig.get(CONFIG_DIGITAL_LOGIC) != null) {
                    ioConfig.get(i).setIoLogic((String) channelConfig.get(CONFIG_DIGITAL_LOGIC));
                }
            } catch (IllegalArgumentException e) {
                throw new OwException(channelId + " has invalid configuration");
            }

            if (dynamicStateDescriptionProvider != null) {
                dynamicStateDescriptionProvider.setDescription(ioConfig.get(i).getChannelUID(),
                        new StateDescription(null, null, null, null, ioConfig.get(i).isInput(), null));
            } else {
                logger.debug(
                        "state description may be inaccurate, state description provider not available in thing {}",
                        thing.getUID());
            }

            logger.debug("configured {} channel {}: {}", thing.getUID(), i, ioConfig.get(i));
        } else {
            throw new OwException(channelId + " not found");
        }
    }

    isConfigured = true;
}
 
Example 15
Source File: FSInternetRadioHandlerJavaTest.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
private static @NonNull Channel getChannel(final @NonNull Thing thing, final @NonNull String channelId) {
    final Channel channel = thing.getChannel(channelId);
    Assert.assertNotNull(channel);
    return channel;
}