Search in sources :

Example 1 with ChannelTriggeredEvent

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);
    }
}
Also used : Item(org.openhab.core.items.Item) NeeoDeviceChannel(org.openhab.io.neeo.internal.models.NeeoDeviceChannel) ItemCommandEvent(org.openhab.core.items.events.ItemCommandEvent) Command(org.openhab.core.types.Command) ChannelUID(org.openhab.core.thing.ChannelUID) ChannelTriggeredEvent(org.openhab.core.thing.events.ChannelTriggeredEvent) NeeoDevice(org.openhab.io.neeo.internal.models.NeeoDevice) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException)

Example 2 with ChannelTriggeredEvent

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);
        }
    }
}
Also used : ChannelTriggeredEvent(org.openhab.core.thing.events.ChannelTriggeredEvent)

Example 3 with ChannelTriggeredEvent

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;
}
Also used : ItemEvent(org.openhab.core.items.events.ItemEvent) DefaultEvaluationContext(org.eclipse.xtext.xbase.interpreter.impl.DefaultEvaluationContext) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IEvaluationContext(org.eclipse.xtext.xbase.interpreter.IEvaluationContext) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ChannelTriggeredEvent(org.openhab.core.thing.events.ChannelTriggeredEvent) XtextResource(org.eclipse.xtext.resource.XtextResource) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) ThingStatusInfoChangedEvent(org.openhab.core.thing.events.ThingStatusInfoChangedEvent) XExpression(org.eclipse.xtext.xbase.XExpression) Map(java.util.Map)

Example 4 with ChannelTriggeredEvent

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;
}
Also used : ChannelTriggeredEvent(org.openhab.core.thing.events.ChannelTriggeredEvent)

Aggregations

ChannelTriggeredEvent (org.openhab.core.thing.events.ChannelTriggeredEvent)4 Map (java.util.Map)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 XExpression (org.eclipse.xtext.xbase.XExpression)1 IEvaluationContext (org.eclipse.xtext.xbase.interpreter.IEvaluationContext)1 DefaultEvaluationContext (org.eclipse.xtext.xbase.interpreter.impl.DefaultEvaluationContext)1 Item (org.openhab.core.items.Item)1 ItemNotFoundException (org.openhab.core.items.ItemNotFoundException)1 ItemCommandEvent (org.openhab.core.items.events.ItemCommandEvent)1 ItemEvent (org.openhab.core.items.events.ItemEvent)1 ChannelUID (org.openhab.core.thing.ChannelUID)1 ThingStatusInfoChangedEvent (org.openhab.core.thing.events.ThingStatusInfoChangedEvent)1 Command (org.openhab.core.types.Command)1 NeeoDevice (org.openhab.io.neeo.internal.models.NeeoDevice)1 NeeoDeviceChannel (org.openhab.io.neeo.internal.models.NeeoDeviceChannel)1