/** * Method returns the state source(s) result(s) (contains state value(s)) of the input activationState. * * @param activationState The ActivationState. * @return state source(s) result(s) of the input state. */ private List<RdfNodeObject> activationStateSources(final ActivationState activationState) { final List<RdfNodeObject> stateSources = new ArrayList<>(); final String activationStateVal = activationState.getValue().toString(); stateSources.add(new RdfNodeObject(new ArrayList<String>() {{add(activationStateVal);}}, false)); return stateSources; }
public PresenceLightAgent() throws InstantiationException { super(PresenceLightAgent.class); actionRescheduleHelper = new ActionRescheduler(RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationState> source, ActivationState data) -> { logger.warn("New trigger state: " + data.getValue()); GlobalCachedExecutorService.submit(() -> { if (data.getValue().equals(ActivationState.State.ACTIVE)) { switchlightsOn(); } else { logger.warn("Stop execution"); actionRescheduleHelper.stopExecution(); } return null; }); }; }
private boolean verifyAndCondition() throws CouldNotPerformException { for (AbstractTrigger abstractTrigger : triggerListAND) { if (!abstractTrigger.getActivationState().getValue().equals(ActivationState.State.ACTIVE) && !abstractTrigger.getActivationState().getValue().equals(ActivationState.State.UNKNOWN)) { return false; } } return !triggerListAND.isEmpty(); }
public TriggerPool() throws InstantiationException { triggerListAND = new ArrayList(); triggerListOR = new ArrayList(); active = false; triggerAndObserver = (Observable<ActivationState> source, ActivationState data) -> { verifyCondition(); }; triggerOrObserver = (Observable<ActivationState> source, ActivationState data) -> { if (data.getValue().equals(ActivationState.State.ACTIVE)) { if (!getActivationState().getValue().equals(ActivationState.State.ACTIVE)) { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.ACTIVE).build())); } } else { verifyCondition(); } }; try { notifyChange(TimestampProcessor.updateTimestampWithCurrentTime(ActivationState.newBuilder().setValue(ActivationState.State.UNKNOWN).build())); } catch (CouldNotPerformException ex) { throw new InstantiationException("Could not set initial state", ex); } }
private void activationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_activationButtonActionPerformed try { switch (getOperationService().getActivationState().getValue()) { case ACTIVE: notifyActionProcessing(getOperationService().setActivationState(DEACTIVE)); break; case DEACTIVE: case UNKNOWN: notifyActionProcessing(getOperationService().setActivationState(ACTIVE)); break; default: throw new InvalidStateException("State[" + getProviderService().getActivationState().getValue() + "] is unknown."); } } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(new CouldNotPerformException("Could not set activation state!", ex), logger); } }//GEN-LAST:event_activationButtonActionPerformed
@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); } }
public static OpenhabCommandType.OpenhabCommand.Builder newOnOffCommand(final ActivationState state) throws CouldNotPerformException { return newOnOffCommand(state.getValue()); }
public AbsenceEnergySavingAgent() throws InstantiationException { super(AbsenceEnergySavingAgent.class); actionRescheduleHelper = new ActionRescheduler(ActionRescheduler.RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationStateType.ActivationState> source, ActivationStateType.ActivationState data) -> { GlobalCachedExecutorService.submit(() -> { if (data.getValue().equals(ActivationStateType.ActivationState.State.ACTIVE)) { switchlightsOff(); switchMultimediaOff(); } else { actionRescheduleHelper.stopExecution(); } return null; }); }; }
public RandomLightPatternAgent() throws InstantiationException { super(RandomLightPatternAgent.class); actionRescheduleHelper = new ActionRescheduler(ActionRescheduler.RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationStateType.ActivationState> source, ActivationStateType.ActivationState data) -> { GlobalCachedExecutorService.submit(() -> { if (data.getValue().equals(ActivationStateType.ActivationState.State.ACTIVE)) { makeRandomLightPattern(); } else { stopRandomLightPattern(); } return null; }); }; }
public IlluminationRollerShutterAgent() throws InstantiationException { super(IlluminationRollerShutterAgent.class); actionRescheduleHelper = new ActionRescheduler(ActionRescheduler.RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationState> source, ActivationState data) -> { if (data.getValue().equals(ActivationState.State.ACTIVE)) { if (locationRemote.getIlluminanceState().getIlluminance() > MAXIMUM_WANTED_ILLUMINATION) { regulateShutterLevelDown(); } else if (locationRemote.getIlluminanceState().getIlluminance() < MINIMUM_NEEDED_ILLUMINATION) { regulateShutterLevelUp(); } } else { actionRescheduleHelper.stopExecution(); } }; }
public static OpenhabCommandType.OpenhabCommand.Builder newOnOffCommand(final ActivationState state) throws CouldNotPerformException { return newOnOffCommand(state.getValue()); }
public TemperatureControllerAgent() throws InstantiationException { super(TemperatureControllerAgent.class); previousTemperatureState = new HashMap(); actionRescheduleHelper = new ActionRescheduler(ActionRescheduler.RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationState> source, ActivationState data) -> { if (data.getValue().equals(ActivationState.State.ACTIVE)) { regulateTemperature(); } else { actionRescheduleHelper.stopExecution(); restoreTemperature(); } }; }
public HeaterEnergySavingAgent() throws InstantiationException { super(HeaterEnergySavingAgent.class); previousTemperatureState = new HashMap(); actionRescheduleHelper = new ActionRescheduler(ActionRescheduler.RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationState> source, ActivationState data) -> { if (data.getValue().equals(ActivationState.State.ACTIVE)) { regulateHeater(); } else { actionRescheduleHelper.stopExecution(); restoreTemperatureState(); } }; }
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())); } } }
public IlluminationLightSavingAgent() throws InstantiationException { super(IlluminationLightSavingAgent.class); actionRescheduleHelper = new ActionRescheduler(ActionRescheduler.RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationState> source, ActivationState data) -> { if (data.getValue().equals(ActivationState.State.ACTIVE)) { regulateLightIntensity(); } else { actionRescheduleHelper.stopExecution(); } }; }
@Override public Future<ActionFuture> setActivationState(final ActivationState activationState) throws CouldNotPerformException { logger.info("Calling remote setActivationState to [" + activationState.getValue() + "] for agent"); ActionDescription.Builder actionDescription = ActionDescriptionProcessor.getActionDescription(ActionAuthority.getDefaultInstance(), ResourceAllocation.Initiator.SYSTEM); try { return applyAction(updateActionDescription(actionDescription, activationState, ServiceType.ACTIVATION_STATE_SERVICE).build()); } catch (InterruptedException ex) { throw new CouldNotPerformException("Interrupted while setting activationState.", ex); } }
public FireAlarmAgent() throws InstantiationException { super(FireAlarmAgent.class); actionRescheduleHelper = new ActionRescheduler(ActionRescheduler.RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationState> source, ActivationState data) -> { if (data.getValue().equals(ActivationState.State.ACTIVE)) { alarmRoutine(); } else { actionRescheduleHelper.stopExecution(); } }; }
private boolean verifyOrCondition() throws CouldNotPerformException { for (AbstractTrigger abstractTrigger : triggerListOR) { if (abstractTrigger.getActivationState().getValue().equals(ActivationState.State.ACTIVE)) { return true; } } return false; }
public NearFieldLightAgent() throws InstantiationException { super(NearFieldLightAgent.class); actionRescheduleHelper = new ActionRescheduler(ActionRescheduler.RescheduleOption.EXTEND, 30); triggerHolderObserver = (Observable<ActivationState> source, ActivationState data) -> { if (data.getValue().equals(ActivationState.State.ACTIVE)) { dimmLights(); } else { actionRescheduleHelper.stopExecution(); } }; }