@Override public Future<ActionFuture> setColorState(ColorState state) throws CouldNotPerformException { return update(TimestampProcessor.updateTimestampWithCurrentTime(state), unit, ServiceType.COLOR_STATE_SERVICE); } };
@Override public Future<ActionFuture> setStandbyState(StandbyStateType.StandbyState state) throws CouldNotPerformException { return update(TimestampProcessor.updateTimestampWithCurrentTime(state), unit, ServiceType.STANDBY_STATE_SERVICE); } };
@Override public Future<ActionFuture> setTargetTemperatureState(TemperatureState state) throws CouldNotPerformException { return update(TimestampProcessor.updateTimestampWithCurrentTime(state), unit, ServiceType.TARGET_TEMPERATURE_STATE_SERVICE); } };
@Override public Future<ActionFuture> setBrightnessState(BrightnessState state) throws CouldNotPerformException { return update(TimestampProcessor.updateTimestampWithCurrentTime(state), unit, ServiceType.BRIGHTNESS_STATE_SERVICE); } };
@Override public Future<ActionFuture> setPowerState(PowerState state) throws CouldNotPerformException { return update(TimestampProcessor.updateTimestampWithCurrentTime(state), unit, ServiceType.POWER_STATE_SERVICE); } };
@Override public Future<ActionFuture> setBlindState(BlindState state) throws CouldNotPerformException { return update(TimestampProcessor.updateTimestampWithCurrentTime(state), unit, ServiceType.BLIND_STATE_SERVICE); } };
/** * Method updates the timestamp field of the given message with the current time. * In case of an error the original message is returned. * * @param <M> the message type of the message to update. * @param messageOrBuilder the message * @param logger the logger which is used for printing the exception stack in case something went wrong. * @return the updated message or the original one in case of errors. */ public static <M extends MessageOrBuilder> M updateTimestampWithCurrentTime(final M messageOrBuilder, final Logger logger) { try { return updateTimestampWithCurrentTime(messageOrBuilder); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, logger); return messageOrBuilder; } } }
@Override public void deactivate() throws CouldNotPerformException, InterruptedException { unitRemote.removeDataObserver(dataObserver); unitRemote.removeConnectionStateObserver(connectionObserver); active = false; notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.UNKNOWN).build())); }
@Override public void deactivate() throws CouldNotPerformException, InterruptedException { unitRemote.removeDataObserver(dataObserver); unitRemote.removeConnectionStateObserver(connectionObserver); active = false; notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.UNKNOWN).build())); }
public AbstractTrigger() throws InstantiationException { this.triggerObservable = new ObservableImpl<>(this); try { this.triggerObservable.notifyObservers(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.UNKNOWN).build())); } catch (CouldNotPerformException ex) { throw new InstantiationException("Could not set initial state", ex); } }
@Override public void deactivate() throws CouldNotPerformException, InterruptedException { unitRemote.removeDataObserver(dataObserver); unitRemote.removeConnectionStateObserver(connectionObserver); active = false; notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.UNKNOWN).build())); }
private void verifyCondition() { try { if (locationRemote.getData().getPresenceState().getValue().equals(PresenceState.State.PRESENT) && (connectionRemote.getDoorState().getValue().equals(DoorState.State.OPEN) || connectionRemote.getWindowState().getValue().equals(WindowState.State.OPEN))) { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build())); } else { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build())); } } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory("Could not verify trigger state " + this, ex, LoggerFactory.getLogger(getClass())); } } }
public NeighborConnectionPresenceTrigger(final LocationRemote locationRemote, final ConnectionRemote connectionRemote) throws org.openbase.jul.exception.InstantiationException { super(); this.locationRemote = locationRemote; this.connectionRemote = connectionRemote; dataObserver = (source, data) -> { verifyCondition(); }; connectionObserver = (Observable<Remote.ConnectionState> source, Remote.ConnectionState data) -> { if (data.equals(Remote.ConnectionState.CONNECTED)) { verifyCondition(); } else { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.UNKNOWN).build())); } }; }
private void verifyCondition() throws CouldNotPerformException { if (verifyOrCondition() || verifyAndCondition()) { if (!getActivationState().getValue().equals(ActivationState.State.ACTIVE)) { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build())); } } else { if (!getActivationState().getValue().equals(ActivationState.State.DEACTIVE)) { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build())); } } }
@Override public void deactivate() throws CouldNotPerformException, InterruptedException { locationRemote.removeDataObserver(dataObserver); connectionRemote.removeDataObserver(dataObserver); locationRemote.removeConnectionStateObserver(connectionObserver); connectionRemote.removeConnectionStateObserver(connectionObserver); active = false; notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.UNKNOWN).build())); }
@Override public void deactivate() throws CouldNotPerformException, InterruptedException { for (AbstractTrigger abstractTrigger : triggerListAND) { abstractTrigger.deregisterObserver(triggerAndObserver); abstractTrigger.deactivate(); } for (AbstractTrigger abstractTrigger : triggerListOR) { abstractTrigger.deregisterObserver(triggerOrObserver); abstractTrigger.deactivate(); } notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.UNKNOWN).build())); active = false; }
public OntologyTrigger(TriggerConfig config) throws InstantiationException { super(); triggerObserver = (Observable<ActivationState.State> source, ActivationState.State data) -> { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(data).build())); }; try { final TriggerFactory triggerFactory = new TriggerFactory(); trigger = triggerFactory.newInstance(config); trigger.addObserver(triggerObserver); } catch (CouldNotPerformException | InterruptedException ex) { throw new InstantiationException("Could not instantiate OntologyTrigger", ex); } }
public GenericValueBoundaryBCOTrigger(final UR unitRemote, final double boundary, final TriggerOperation triggerOperation, ServiceType serviceType, String specificValueCall) throws InstantiationException { super(); this.unitRemote = unitRemote; this.serviceType = serviceType; this.boundary = boundary; this.triggerOperation = triggerOperation; this.specificValueCall = specificValueCall; dataObserver = (Observable<DT> source, DT data) -> { verifyCondition(data); }; connectionObserver = (Observable<Remote.ConnectionState> source, Remote.ConnectionState data) -> { if (data.equals(Remote.ConnectionState.CONNECTED)) { verifyCondition((DT) unitRemote.getData()); } else { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.UNKNOWN).build())); } }; }
public GenericBCOTrigger(final UR unitRemote, final STE targetState, final ServiceType serviceType) throws InstantiationException { super(); this.unitRemote = unitRemote; this.targetState = targetState; this.serviceType = serviceType; dataObserver = (Observable<DT> source, DT data) -> { verifyCondition(data); }; connectionObserver = (Observable<ConnectionState> source, ConnectionState data) -> { if (data.equals(ConnectionState.CONNECTED)) { verifyCondition((DT) unitRemote.getData()); } else { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.UNKNOWN).build())); } }; }
@Override public ActivationState getActivationState(final UnitType unitType) throws NotAvailableException { ActivationState.State activationStateValue = ActivationState.State.DEACTIVE; try { for (ActivationStateOperationService service : getServices(unitType)) { if (!((UnitRemote) service).isDataAvailable()) { continue; } if (service.getActivationState().getValue() == ActivationState.State.ACTIVE) { activationStateValue = ActivationState.State.ACTIVE; } } return TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(activationStateValue)).build(); } catch (CouldNotPerformException ex) { throw new NotAvailableException("ActivationState", ex); } }