use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.
the class CommunicationManager method receiveTrigger.
private void receiveTrigger(ChannelTriggeredEvent channelTriggeredEvent) {
final ChannelUID channelUID = channelTriggeredEvent.getChannel();
final String event = channelTriggeredEvent.getEvent();
final Thing thing = getThing(channelUID.getThingUID());
handleCallFromHandler(channelUID, thing, profile -> {
if (profile instanceof TriggerProfile) {
((TriggerProfile) profile).onTriggerFromHandler(event);
}
});
}
use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.
the class CommunicationManager method handleEvent.
private <T extends Type> void handleEvent(String itemName, T type, String source, Function<@Nullable String, @Nullable List<Class<? extends T>>> acceptedTypesFunction, ProfileAction<T> action) {
final Item item = getItem(itemName);
if (item == null) {
logger.debug("Received an event for item {} which does not exist", itemName);
return;
}
itemChannelLinkRegistry.stream().filter(link -> {
// all links for the item
return link.getItemName().equals(itemName);
}).filter(link -> {
// make sure the command event is not sent back to its source
return !link.getLinkedUID().toString().equals(source);
}).forEach(link -> {
ChannelUID channelUID = link.getLinkedUID();
Thing thing = getThing(channelUID.getThingUID());
if (thing != null) {
Channel channel = thing.getChannel(channelUID.getId());
if (channel != null) {
@Nullable T convertedType = toAcceptedType(type, channel, acceptedTypesFunction);
if (convertedType != null) {
if (thing.getHandler() != null) {
Profile profile = getProfile(link, item, thing);
action.handle(profile, thing, convertedType);
}
} else {
logger.debug("Received event '{}' ({}) could not be converted to any type accepted by item '{}' ({})", type, type.getClass().getSimpleName(), itemName, item.getType());
}
} else {
logger.debug("Received event '{}' for non-existing channel '{}', not forwarding it to the handler", type, channelUID);
}
} else {
logger.debug("Received event '{}' for non-existing thing '{}', not forwarding it to the handler", type, channelUID.getThingUID());
}
});
}
use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.
the class ThingFactoryHelper method createChannel.
private static Channel createChannel(ChannelDefinition channelDefinition, ThingUID thingUID, String groupId, ConfigDescriptionRegistry configDescriptionRegistry) {
ChannelType type = withChannelTypeRegistry(channelTypeRegistry -> {
return (channelTypeRegistry != null) ? channelTypeRegistry.getChannelType(channelDefinition.getChannelTypeUID()) : null;
});
if (type == null) {
logger.warn("Could not create channel '{}' for thing type '{}', because channel type '{}' could not be found.", channelDefinition.getId(), thingUID, channelDefinition.getChannelTypeUID());
return null;
}
ChannelUID channelUID = new ChannelUID(thingUID, groupId, channelDefinition.getId());
ChannelBuilder channelBuilder = createChannelBuilder(channelUID, type, configDescriptionRegistry);
// If we want to override the label, add it...
if (channelDefinition.getLabel() != null) {
channelBuilder = channelBuilder.withLabel(channelDefinition.getLabel());
}
// If we want to override the description, add it...
if (channelDefinition.getDescription() != null) {
channelBuilder = channelBuilder.withDescription(channelDefinition.getDescription());
}
channelBuilder = channelBuilder.withProperties(channelDefinition.getProperties());
return channelBuilder.build();
}
use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.
the class BaseThingHandler method updateState.
/**
* Updates the state of the thing. Will use the thing UID to infer the
* unique channel UID from the given ID.
*
* @param channel ID id of the channel, which was updated
* @param state new state
* @throws IllegalStateException if handler is not initialized correctly, because no callback is present
*/
protected void updateState(String channelID, State state) {
ChannelUID channelUID = new ChannelUID(this.getThing().getUID(), channelID);
updateState(channelUID, state);
}
use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.
the class BaseThingHandler method postCommand.
/**
* Sends a command for a channel of the thing.
*
* @param channelID id of the channel, which sends the command
* @param command command
* @throws IllegalStateException if handler is not initialized correctly, because no callback is present
*/
protected void postCommand(String channelID, Command command) {
ChannelUID channelUID = new ChannelUID(this.getThing().getUID(), channelID);
postCommand(channelUID, command);
}
Aggregations