public static ActivationState transform(final OnOffHolder.OnOff onOffType) throws CouldNotTransformException { switch (onOffType) { case OFF: return ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build(); case ON: return ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build(); default: throw new CouldNotTransformException("Could not transform " + OnOffHolder.OnOff.class.getName() + "! " + OnOffHolder.OnOff.class.getSimpleName() + "[" + onOffType.name() + "] is unknown!"); } }
public static ActivationState transform(OnOffHolderType.OnOffHolder.OnOff onOffType) throws CouldNotTransformException { switch (onOffType) { case OFF: return ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build(); case ON: return ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build(); default: throw new CouldNotTransformException("Could not transform " + OnOffHolderType.OnOffHolder.OnOff.class.getName() + "! " + OnOffHolderType.OnOffHolder.OnOff.class.getSimpleName() + "[" + onOffType.name() + "] is unknown!"); } }
public static ActivationState transform(OnOffHolderType.OnOffHolder.OnOff onOffType) throws CouldNotTransformException { switch (onOffType) { case OFF: return ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build(); case ON: return ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build(); default: throw new CouldNotTransformException("Could not transform " + OnOffHolderType.OnOffHolder.OnOff.class.getName() + "! " + OnOffHolderType.OnOffHolder.OnOff.class.getSimpleName() + "[" + onOffType.name() + "] is unknown!"); } }
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 void enable() throws CouldNotPerformException, InterruptedException { try { synchronized (enablingLock) { enabled = true; activate(); if (detectAutostart()) { setActivationState(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build()).get(); } else { setActivationState(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build()).get(); } } } catch (ExecutionException ex) { throw new CouldNotPerformException("Could not enable " + this, ex); } }
@Override public void enable() throws CouldNotPerformException, InterruptedException { try { synchronized (enablingLock) { super.enable(); if (detectAutostart()) { setActivationState(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build()).get(); } else { setActivationState(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build()).get(); } } } catch (ExecutionException ex) { throw new CouldNotPerformException("Could not diable " + this, ex); } }
@RPCMethod public Future<ActionFuture> setActivationState(final ActivationState activationState) throws CouldNotPerformException;
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() { 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())); } } }
@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 SceneControllerImpl() throws org.openbase.jul.exception.InstantiationException { super(SceneControllerImpl.class, SceneData.newBuilder()); this.buttonRemoteSet = new HashSet<>(); this.remoteActionList = new ArrayList<>(); this.buttonObserver = (final Observable<ButtonData> source, ButtonData data) -> { // skip initial button state synchronization during system startup if (data.getButtonStateLast().getValue().equals(State.UNKNOWN)) { return; } if (data.getButtonState().getValue().equals(ButtonState.State.PRESSED)) { setActivationState(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build()); } }; }
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); } }
@Override public void disable() throws CouldNotPerformException, InterruptedException { try { synchronized (enablingLock) { cancelExecution(); enabled = false; setActivationState(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build()).get(); deactivate(); } } catch (ExecutionException ex) { throw new CouldNotPerformException("Could not disable " + this, 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())); }
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())); }
@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 { locationRemote.removeDataObserver(dataObserver); connectionRemote.removeDataObserver(dataObserver); locationRemote.removeConnectionStateObserver(connectionObserver); connectionRemote.removeConnectionStateObserver(connectionObserver); active = false; 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 disable() throws CouldNotPerformException, InterruptedException { try { synchronized (enablingLock) { executing = false; setActivationState(ActivationState.newBuilder().setValue(ActivationState.State.DEACTIVE).build()).get(); super.disable(); } } catch (ExecutionException ex) { throw new CouldNotPerformException("Could not diable " + this, ex); } }