public static BlindState transform(final StopMoveHolder.StopMove stopMoveType) throws CouldNotTransformException { switch (stopMoveType) { case STOP: return BlindState.newBuilder().setMovementState(BlindState.MovementState.STOP).build(); case MOVE: return BlindState.newBuilder().setMovementState(BlindState.MovementState.UNKNOWN).build(); default: throw new CouldNotTransformException("Could not transform " + StopMoveHolder.StopMove.class.getName() + "! " + StopMoveHolder.StopMove.class.getSimpleName() + "[" + stopMoveType.name() + "] is unknown!"); } }
@Override public Future<ActionFuture> setBlindState(final BlindState state) throws CouldNotPerformException { logger.debug("Setting [" + getLabel() + "] to BlindState [" + state + "]"); try { Services.verifyOperationServiceState(state); } catch (VerificationFailedException ex) { return FutureProcessor.canceledFuture(ActionFuture.class, ex); } // stop before moving in any direction. switch (state.getMovementState()) { case DOWN: case UP: try { blindStateService.setBlindState(state.toBuilder().setMovementState(BlindState.MovementState.STOP).build()).get(1000, TimeUnit.MILLISECONDS); } catch (ExecutionException | TimeoutException | InterruptedException ex) { if (ex instanceof InterruptedException) { Thread.currentThread().interrupt(); } ExceptionPrinter.printHistory(new CouldNotPerformException("Could not stop before inverse blind movement.", ex), logger, LogLevel.WARN); // continue without stop } } return blindStateService.setBlindState(state); }
public static BlindState transform(final UpDownHolder.UpDown upDownType) throws CouldNotTransformException { switch (upDownType) { case DOWN: return BlindState.newBuilder().setMovementState(BlindState.MovementState.DOWN).build(); case UP: return BlindState.newBuilder().setMovementState(BlindState.MovementState.UP).build(); default: throw new CouldNotTransformException("Could not transform " + UpDownHolder.UpDown.class.getName() + "! " + UpDownHolder.UpDown.class.getSimpleName() + "[" + upDownType.name() + "] is unknown!"); } }
return TimestampProcessor.updateTimestamp(timestamp, BlindState.newBuilder().setMovementState(mostOccurrences).setOpeningRatio(openingRatioAverage), TimeUnit.MICROSECONDS, logger).build();
case STOP: if (simulatedBlindState.getOpeningRatio() == MAX_OPENING_RATIO) { simulatedBlindState.setMovementState(BlindState.MovementState.DOWN); simulatedBlindState.setOpeningRatio(MAX_OPENING_RATIO - OPENING_RATIO_STEP); } else { simulatedBlindState.setMovementState(BlindState.MovementState.UP); simulatedBlindState.setOpeningRatio(MIN_OPENING_RATIO + OPENING_RATIO_STEP); simulatedBlindState.setOpeningRatio(simulatedBlindState.getOpeningRatio() - OPENING_RATIO_STEP); } else { simulatedBlindState.setMovementState(BlindState.MovementState.STOP); simulatedBlindState.setOpeningRatio(MIN_OPENING_RATIO); simulatedBlindState.setOpeningRatio(simulatedBlindState.getOpeningRatio() + OPENING_RATIO_STEP); } else { simulatedBlindState.setMovementState(BlindState.MovementState.STOP); simulatedBlindState.setOpeningRatio(MAX_OPENING_RATIO); simulatedBlindState.setMovementState(BlindState.MovementState.STOP); simulatedBlindState.setOpeningRatio(MAX_OPENING_RATIO); break;
private void regulateShutterLevelDown() { try { ActionDescriptionType.ActionDescription.Builder actionDescriptionBuilder = getNewActionDescription(ActionAuthorityType.ActionAuthority.getDefaultInstance(), ResourceAllocationType.ResourceAllocation.Initiator.SYSTEM, 1000 * 30, ResourceAllocationType.ResourceAllocation.Policy.FIRST, ResourceAllocationType.ResourceAllocation.Priority.NORMAL, locationRemote, BlindStateType.BlindState.newBuilder().setMovementState(BlindStateType.BlindState.MovementState.DOWN).build(), UnitTemplateType.UnitTemplate.UnitType.UNKNOWN, ServiceTemplateType.ServiceTemplate.ServiceType.BLIND_STATE_SERVICE, MultiResourceAllocationStrategyType.MultiResourceAllocationStrategy.Strategy.AT_LEAST_ONE); actionRescheduleHelper.startActionRescheduleing(locationRemote.applyAction(actionDescriptionBuilder.build()).get().toBuilder()); } catch (CouldNotPerformException | InterruptedException | ExecutionException ex) { logger.error("Could not dim lights.", ex); } }
private void regulateShutterLevelUp() { try { ActionDescriptionType.ActionDescription.Builder actionDescriptionBuilder = getNewActionDescription(ActionAuthorityType.ActionAuthority.getDefaultInstance(), ResourceAllocationType.ResourceAllocation.Initiator.SYSTEM, 1000 * 30, ResourceAllocationType.ResourceAllocation.Policy.FIRST, ResourceAllocationType.ResourceAllocation.Priority.NORMAL, locationRemote, BlindStateType.BlindState.newBuilder().setMovementState(BlindStateType.BlindState.MovementState.UP).build(), UnitTemplateType.UnitTemplate.UnitType.UNKNOWN, ServiceTemplateType.ServiceTemplate.ServiceType.BLIND_STATE_SERVICE, MultiResourceAllocationStrategyType.MultiResourceAllocationStrategy.Strategy.AT_LEAST_ONE); actionRescheduleHelper.startActionRescheduleing(locationRemote.applyAction(actionDescriptionBuilder.build()).get().toBuilder()); } catch (CouldNotPerformException | InterruptedException | ExecutionException ex) { logger.error("Could not dim lights.", ex); } } }
public Future<ActionFuture> setBlindState(BlindState.MovementState movementState) throws CouldNotPerformException { return RollerShutterRemote.this.setBlindState(BlindState.newBuilder().setMovementState(movementState).build()); }
/** * Creates a new custom service simulator. * * @param unitController the unit to simulate. */ public BlindStateServiceSimulator(UnitController unitController) { super(unitController, ServiceType.BLIND_STATE_SERVICE); this.simulatedBlindState = BlindState.newBuilder(); this.simulatedBlindState.setMovementState(BlindState.MovementState.STOP); this.simulatedBlindState.setOpeningRatio(100); }