Search in sources :

Example 1 with ItemStateChangedEvent

use of org.eclipse.smarthome.core.items.events.ItemStateChangedEvent in project smarthome by eclipse.

the class ItemStateTriggerHandler method receive.

@Override
public void receive(Event event) {
    if (ruleEngineCallback != null) {
        logger.trace("Received Event: Source: {} Topic: {} Type: {}  Payload: {}", event.getSource(), event.getTopic(), event.getType(), event.getPayload());
        Map<String, Object> values = new HashMap<>();
        if (event instanceof ItemStateEvent && UPDATE_MODULE_TYPE_ID.equals(module.getTypeUID())) {
            State state = ((ItemStateEvent) event).getItemState();
            if ((this.state == null || this.state.equals(state.toFullString()))) {
                values.put("state", state);
            }
        } else if (event instanceof ItemStateChangedEvent && CHANGE_MODULE_TYPE_ID.equals(module.getTypeUID())) {
            State state = ((ItemStateChangedEvent) event).getItemState();
            State oldState = ((ItemStateChangedEvent) event).getOldItemState();
            if (stateMatches(this.state, state) && stateMatches(this.previousState, oldState)) {
                values.put("oldState", oldState);
                values.put("newState", state);
            }
        }
        if (!values.isEmpty()) {
            values.put("event", event);
            ruleEngineCallback.triggered(this.module, values);
        }
    }
}
Also used : HashMap(java.util.HashMap) ItemStateChangedEvent(org.eclipse.smarthome.core.items.events.ItemStateChangedEvent) GroupItemStateChangedEvent(org.eclipse.smarthome.core.items.events.GroupItemStateChangedEvent) State(org.eclipse.smarthome.core.types.State) ItemStateEvent(org.eclipse.smarthome.core.items.events.ItemStateEvent)

Aggregations

HashMap (java.util.HashMap)1 GroupItemStateChangedEvent (org.eclipse.smarthome.core.items.events.GroupItemStateChangedEvent)1 ItemStateChangedEvent (org.eclipse.smarthome.core.items.events.ItemStateChangedEvent)1 ItemStateEvent (org.eclipse.smarthome.core.items.events.ItemStateEvent)1 State (org.eclipse.smarthome.core.types.State)1