use of org.openhab.core.thing.events.ChannelTriggeredEvent in project openhab-addons by openhab.
the class NeeoBrainService method handleSetValue.
/**
* Handle set value from the path
*
* @param resp the non-null response to write the response to
* @param pathInfo the non-null path information
*/
private void handleSetValue(HttpServletResponse resp, PathInfo pathInfo) {
Objects.requireNonNull(resp, "resp cannot be null");
Objects.requireNonNull(pathInfo, "pathInfo cannot be null");
logger.debug("handleSetValue {}", pathInfo);
final NeeoDevice device = context.getDefinitions().getDevice(pathInfo.getThingUid());
if (device != null) {
final NeeoDeviceChannel channel = device.getChannel(pathInfo.getItemName(), pathInfo.getSubType(), pathInfo.getChannelNbr());
if (channel != null && channel.getKind() == NeeoDeviceChannelKind.TRIGGER) {
String value = channel.getValue();
final ChannelTriggeredEvent event = ThingEventFactory.createTriggerEvent(value == null ? "" : value, new ChannelUID(device.getUid(), channel.getItemName()));
logger.debug("Posting triggered event: {}", event);
context.getEventPublisher().post(event);
} else {
try {
final Item item = context.getItemRegistry().getItem(pathInfo.getItemName());
final Command cmd = NeeoItemValueConverter.convert(item, pathInfo);
if (cmd != null) {
final ItemCommandEvent event = ItemEventFactory.createCommandEvent(item.getName(), cmd);
logger.debug("Posting item event: {}", event);
context.getEventPublisher().post(event);
} else {
logger.debug("Cannot set value - no command for path: {}", pathInfo);
}
} catch (ItemNotFoundException e) {
logger.debug("Cannot set value - no linked items: {}", pathInfo);
}
}
} else {
logger.debug("Cannot set value - no device definition: {}", pathInfo);
}
}
use of org.openhab.core.thing.events.ChannelTriggeredEvent in project jrule by seaside1.
the class JRuleEventSubscriber method receive.
@Override
public void receive(Event event) {
final String itemFromTopic = JRuleUtil.getItemNameFromTopic(event.getTopic());
if (//
event.getType().equals(ItemAddedEvent.TYPE) || //
event.getType().equals(ItemRemovedEvent.TYPE) || event.getType().equals(ItemUpdatedEvent.TYPE)) {
JRuleLog.debug(logger, LOG_NAME_SUBSCRIBER, "event processed as {}: topic {} payload: {}", PROPERTY_ITEM_REGISTRY_EVENT, event.getTopic(), event.getPayload());
propertyChangeSupport.firePropertyChange(PROPERTY_ITEM_REGISTRY_EVENT, null, event);
return;
}
if (jRuleMonitoredItems.contains(itemFromTopic)) {
JRuleLog.debug(logger, LOG_NAME_SUBSCRIBER, "Event processed as {}: topic {} payload: {}", PROPERTY_ITEM_EVENT, event.getTopic(), event.getPayload());
propertyChangeSupport.firePropertyChange(PROPERTY_ITEM_EVENT, null, event);
}
if (event.getType().equals(ChannelTriggeredEvent.TYPE)) {
ChannelTriggeredEvent channelTriggeredEvent = (ChannelTriggeredEvent) event;
String channel = channelTriggeredEvent.getChannel().toString();
if (jRuleMonitoredChannels.contains(channel)) {
JRuleLog.debug(logger, LOG_NAME_SUBSCRIBER, "Event processed as {}: topic {} payload: {}", PROPERTY_CHANNEL_EVENT, event.getTopic(), event.getPayload());
propertyChangeSupport.firePropertyChange(PROPERTY_CHANNEL_EVENT, null, event);
}
}
}
use of org.openhab.core.thing.events.ChannelTriggeredEvent in project openhab-core by openhab.
the class DSLScriptEngine method createEvaluationContext.
private DefaultEvaluationContext createEvaluationContext(Script script, IEvaluationContext specificContext) {
IEvaluationContext parentContext = specificContext;
if (specificContext == null && script instanceof ScriptImpl) {
XExpression xExpression = ((ScriptImpl) script).getXExpression();
if (xExpression != null) {
Resource resource = xExpression.eResource();
if (resource instanceof XtextResource) {
IResourceServiceProvider provider = ((XtextResource) resource).getResourceServiceProvider();
parentContext = provider.get(IEvaluationContext.class);
}
}
}
DefaultEvaluationContext evalContext = new DefaultEvaluationContext(parentContext);
for (Map.Entry<String, String> entry : IMPLICIT_VARS.entrySet()) {
Object value = context.getAttribute(entry.getKey());
if (value != null) {
QualifiedName qn = QualifiedName.create(entry.getValue());
if (evalContext.getValue(qn) == null) {
evalContext.newValue(qn, value);
} else {
evalContext.assignValue(qn, value);
}
}
}
// now add specific implicit vars, where we have to map the right content
Object value = context.getAttribute(OUTPUT_EVENT);
if (value instanceof ChannelTriggeredEvent) {
ChannelTriggeredEvent event = (ChannelTriggeredEvent) value;
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_RECEIVED_EVENT), event.getEvent());
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_TRIGGERING_CHANNEL), event.getChannel().getAsString());
}
if (value instanceof ItemEvent) {
ItemEvent event = (ItemEvent) value;
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_TRIGGERING_ITEM_NAME), event.getItemName());
}
if (value instanceof ThingStatusInfoChangedEvent) {
ThingStatusInfoChangedEvent event = (ThingStatusInfoChangedEvent) value;
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_TRIGGERING_THING), event.getThingUID().toString());
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_PREVIOUS_STATUS), event.getOldStatusInfo().getStatus().toString());
evalContext.newValue(QualifiedName.create(ScriptJvmModelInferrer.VAR_NEW_STATUS), event.getStatusInfo().getStatus().toString());
}
return evalContext;
}
use of org.openhab.core.thing.events.ChannelTriggeredEvent in project openhab-core by openhab.
the class ChannelEventTriggerHandler method apply.
@Override
public boolean apply(Event event) {
logger.trace("->FILTER: {}:{}", event.getTopic(), TOPIC);
boolean eventMatches = false;
if (event instanceof ChannelTriggeredEvent) {
ChannelTriggeredEvent cte = (ChannelTriggeredEvent) event;
if (channelUID.equals(cte.getChannel())) {
String eventOnChannel = this.eventOnChannel;
logger.trace("->FILTER: {}:{}", cte.getEvent(), eventOnChannel);
eventMatches = eventOnChannel == null || eventOnChannel.isBlank() || eventOnChannel.equals(cte.getEvent());
}
}
return eventMatches;
}
Aggregations