Search in sources :

Example 1 with ThingStatus

use of org.eclipse.smarthome.core.thing.ThingStatus in project smarthome by eclipse.

the class MagicDelayedOnlineHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    if (channelUID.getId().equals("number")) {
        if (command instanceof DecimalType) {
            DecimalType cmd = (DecimalType) command;
            int cmdInt = cmd.intValue();
            ThingStatus status = cmdInt > 0 ? ThingStatus.ONLINE : ThingStatus.OFFLINE;
            int waitTime = Math.abs(cmd.intValue());
            scheduler.schedule(() -> updateStatus(status), waitTime, TimeUnit.SECONDS);
        }
    }
}
Also used : ThingStatus(org.eclipse.smarthome.core.thing.ThingStatus) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType)

Example 2 with ThingStatus

use of org.eclipse.smarthome.core.thing.ThingStatus in project smarthome by eclipse.

the class RuleTriggerManager method internalGetThingRules.

private Iterable<Rule> internalGetThingRules(TriggerTypes triggerType, String thingUid, ThingStatus oldStatus, ThingStatus newStatus) {
    List<Rule> result = new ArrayList<>();
    Iterable<Rule> rules = getAllRules(triggerType, thingUid);
    switch(triggerType) {
        case THINGUPDATE:
            for (Rule rule : rules) {
                for (EventTrigger t : rule.getEventtrigger()) {
                    if (t instanceof ThingStateUpdateEventTrigger) {
                        ThingStateUpdateEventTrigger tt = (ThingStateUpdateEventTrigger) t;
                        if (tt.getThing().equals(thingUid)) {
                            String stateString = tt.getState();
                            if (stateString != null) {
                                ThingStatus triggerState = ThingStatus.valueOf(stateString);
                                if (!newStatus.equals(triggerState)) {
                                    continue;
                                }
                            }
                            result.add(rule);
                        }
                    }
                }
            }
            break;
        case THINGCHANGE:
            for (Rule rule : rules) {
                for (EventTrigger t : rule.getEventtrigger()) {
                    if (t instanceof ThingStateChangedEventTrigger) {
                        ThingStateChangedEventTrigger ct = (ThingStateChangedEventTrigger) t;
                        if (ct.getThing().equals(thingUid)) {
                            String oldStatusString = ct.getOldState();
                            if (oldStatusString != null) {
                                ThingStatus triggerOldState = ThingStatus.valueOf(oldStatusString);
                                if (!oldStatus.equals(triggerOldState)) {
                                    continue;
                                }
                            }
                            String newStatusString = ct.getNewState();
                            if (newStatusString != null) {
                                ThingStatus triggerNewState = ThingStatus.valueOf(newStatusString);
                                if (!newStatus.equals(triggerNewState)) {
                                    continue;
                                }
                            }
                            result.add(rule);
                        }
                    }
                }
            }
            break;
        default:
            break;
    }
    return result;
}
Also used : ThingStateUpdateEventTrigger(org.eclipse.smarthome.model.rule.rules.ThingStateUpdateEventTrigger) ThingStatus(org.eclipse.smarthome.core.thing.ThingStatus) ArrayList(java.util.ArrayList) Rule(org.eclipse.smarthome.model.rule.rules.Rule) UpdateEventTrigger(org.eclipse.smarthome.model.rule.rules.UpdateEventTrigger) ThingStateChangedEventTrigger(org.eclipse.smarthome.model.rule.rules.ThingStateChangedEventTrigger) ThingStateUpdateEventTrigger(org.eclipse.smarthome.model.rule.rules.ThingStateUpdateEventTrigger) EventTrigger(org.eclipse.smarthome.model.rule.rules.EventTrigger) ChangedEventTrigger(org.eclipse.smarthome.model.rule.rules.ChangedEventTrigger) GroupMemberUpdateEventTrigger(org.eclipse.smarthome.model.rule.rules.GroupMemberUpdateEventTrigger) GroupMemberChangedEventTrigger(org.eclipse.smarthome.model.rule.rules.GroupMemberChangedEventTrigger) GroupMemberCommandEventTrigger(org.eclipse.smarthome.model.rule.rules.GroupMemberCommandEventTrigger) CommandEventTrigger(org.eclipse.smarthome.model.rule.rules.CommandEventTrigger) ThingStateChangedEventTrigger(org.eclipse.smarthome.model.rule.rules.ThingStateChangedEventTrigger)

Example 3 with ThingStatus

use of org.eclipse.smarthome.core.thing.ThingStatus in project smarthome by eclipse.

the class AutomaticInboxProcessor method receiveTypedEvent.

@Override
public void receiveTypedEvent(ThingStatusInfoChangedEvent event) {
    if (autoIgnore) {
        Thing thing = thingRegistry.get(event.getThingUID());
        ThingStatus thingStatus = event.getStatusInfo().getStatus();
        autoIgnore(thing, thingStatus);
    }
}
Also used : ThingStatus(org.eclipse.smarthome.core.thing.ThingStatus) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 4 with ThingStatus

use of org.eclipse.smarthome.core.thing.ThingStatus in project smarthome by eclipse.

the class RuleEngineImpl method receiveThingStatus.

private void receiveThingStatus(ThingStatusInfoChangedEvent event) {
    String thingUid = event.getThingUID().getAsString();
    ThingStatus oldStatus = event.getOldStatusInfo().getStatus();
    ThingStatus newStatus = event.getStatusInfo().getStatus();
    Iterable<Rule> rules = triggerManager.getRules(THINGUPDATE, thingUid, newStatus);
    executeRules(rules);
    if (oldStatus != newStatus) {
        rules = triggerManager.getRules(THINGCHANGE, thingUid, oldStatus, newStatus);
        executeRules(rules, oldStatus);
    }
}
Also used : ThingStatus(org.eclipse.smarthome.core.thing.ThingStatus) Rule(org.eclipse.smarthome.model.rule.rules.Rule)

Aggregations

ThingStatus (org.eclipse.smarthome.core.thing.ThingStatus)4 Rule (org.eclipse.smarthome.model.rule.rules.Rule)2 ArrayList (java.util.ArrayList)1 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)1 Thing (org.eclipse.smarthome.core.thing.Thing)1 ChangedEventTrigger (org.eclipse.smarthome.model.rule.rules.ChangedEventTrigger)1 CommandEventTrigger (org.eclipse.smarthome.model.rule.rules.CommandEventTrigger)1 EventTrigger (org.eclipse.smarthome.model.rule.rules.EventTrigger)1 GroupMemberChangedEventTrigger (org.eclipse.smarthome.model.rule.rules.GroupMemberChangedEventTrigger)1 GroupMemberCommandEventTrigger (org.eclipse.smarthome.model.rule.rules.GroupMemberCommandEventTrigger)1 GroupMemberUpdateEventTrigger (org.eclipse.smarthome.model.rule.rules.GroupMemberUpdateEventTrigger)1 ThingStateChangedEventTrigger (org.eclipse.smarthome.model.rule.rules.ThingStateChangedEventTrigger)1 ThingStateUpdateEventTrigger (org.eclipse.smarthome.model.rule.rules.ThingStateUpdateEventTrigger)1 UpdateEventTrigger (org.eclipse.smarthome.model.rule.rules.UpdateEventTrigger)1