@Override protected void updateDynamicComponents() { try { openingRatioBar.setValue((int) getProviderService().getBlindState().getOpeningRatio()); openingRatioBar.setString("Opening Ratio = " + openingRatioBar.getValue() + "%"); switch (getProviderService().getBlindState().getMovementState()) { case UP: movementStatePanel.setBackground(Color.GREEN.darker()); break; case DOWN: movementStatePanel.setBackground(Color.RED.darker()); break; case STOP: movementStatePanel.setBackground(Color.CYAN.darker()); break; case UNKNOWN: movementStatePanel.setBackground(Color.GRAY); break; default: break; } movementStateLabel.setText(getProviderService().getBlindState().getMovementState().name()); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, logger); } } }
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); } }
switch (service.getBlindState().getMovementState()) { case DOWN: down++; openingRatioAverage += service.getBlindState().getOpeningRatio(); timestamp = Math.max(timestamp, service.getBlindState().getTimestamp().getTime()); return TimestampProcessor.updateTimestamp(timestamp, BlindState.newBuilder().setMovementState(mostOccurrences).setOpeningRatio(openingRatioAverage), TimeUnit.MICROSECONDS, logger).build();
ResourceAllocationType.ResourceAllocation.Priority.EMERGENCY, locationRemote, BlindStateType.BlindState.newBuilder().setOpeningRatio(100.0).build(), UnitType.UNKNOWN, ServiceTemplateType.ServiceTemplate.ServiceType.BLIND_STATE_SERVICE,
@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); }
static void verifyBlindState(final BlindState blindState) throws VerificationFailedException { try { if (!blindState.hasMovementState() && !blindState.hasOpeningRatio()) { throw new VerificationFailedException("MovementState and OpeningRatio not available!", new InvalidStateException(blindState.toString())); } if (blindState.hasOpeningRatio() && blindState.getOpeningRatio() < 0) { throw new VerificationFailedException("Opening ratio of blind state out of range with value[" + blindState.getOpeningRatio() + "]!", new InvalidStateException(blindState.toString())); } if (blindState.hasMovementState()) { switch (blindState.getMovementState()) { case UNKNOWN: throw new VerificationFailedException("MovementState unknown!", new InvalidStateException(blindState.toString())); default: break; } } } catch (final CouldNotPerformException ex) { throw new VerificationFailedException("BlindState not valid!", 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 static StopMoveHolder transform(BlindState blindState) throws TypeNotSupportedException, CouldNotTransformException { switch (blindState.getMovementState()) { case STOP: return StopMoveHolder.newBuilder().setState(StopMoveHolder.StopMove.STOP).build(); case UP: return StopMoveHolder.newBuilder().setState(StopMoveHolder.StopMove.MOVE).build(); case DOWN: return StopMoveHolder.newBuilder().setState(StopMoveHolder.StopMove.MOVE).build(); case UNKNOWN: throw new TypeNotSupportedException(blindState, StopMoveHolder.StopMove.class); default: throw new CouldNotTransformException("Could not transform " + BlindState.class.getName() + "! " + BlindState.class.getSimpleName() + "[" + blindState.getMovementState().name() + "] is unknown!"); } } }
public static UpDownHolder transform(final BlindState blindState) throws TypeNotSupportedException, CouldNotTransformException { switch (blindState.getMovementState()) { case DOWN: return UpDownHolder.newBuilder().setState(UpDownHolder.UpDown.DOWN).build(); case UP: return UpDownHolder.newBuilder().setState(UpDownHolder.UpDown.UP).build(); case UNKNOWN: throw new TypeNotSupportedException(blindState, UpDownHolder.UpDown.class); default: throw new CouldNotTransformException("Could not transform " + BlindState.class.getName() + "! " + BlindState.class.getSimpleName() + "[" + blindState.getMovementState().name() + "] is unknown!"); } } }
public Future<ActionFuture> setBlindState(BlindState.MovementState movementState) throws CouldNotPerformException { return RollerShutterRemote.this.setBlindState(BlindState.newBuilder().setMovementState(movementState).build()); }
/** * Method returns the state source(s) result(s) (contains state value(s)) of the input blindState. * * @param blindState The BlindState. * @return state source(s) result(s) of the input state. */ private List<RdfNodeObject> blindStateSources(final BlindState blindState) { final List<RdfNodeObject> stateSources = new ArrayList<>(); final String blindMovementStateVal = blindState.getMovementState().toString(); stateSources.add(new RdfNodeObject(new ArrayList<String>() {{add(blindMovementStateVal);}}, false)); final String blindOpeningRationVal = "\"" + String.valueOf(blindState.getOpeningRatio()) + "\"^^NS:Percent"; stateSources.add(new RdfNodeObject(new ArrayList<String>() {{add(blindOpeningRationVal);}}, true)); return stateSources; }
/** * 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); }
/** * Transform a number to a brightness state by setting the number as the brightness value. * * @param value the brightness value * @return the corresponding brightness state */ public static BlindState transform(final Double value) { BlindState.Builder state = BlindState.newBuilder(); state.setOpeningRatio(value); return state.build(); }
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!"); } }
@Override public Future<ActionFuture> setBlindState(final BlindState state) throws CouldNotPerformException { switch (state.getMovementState()) { case UP: return executeCommand(OpenHABCommandFactory.newUpDownCommand(state)); case DOWN: return executeCommand(OpenHABCommandFactory.newUpDownCommand(state)); case STOP: return executeCommand(OpenHABCommandFactory.newStopMoveCommand(state)); default: throw new CouldNotPerformException("Cannot ste unknown state [" + state + "]"); } }
/** * Get the brightness value. * * @param blindState the state to transform * @return the current brightness value */ public static Double transform(BlindState blindState) { return blindState.getOpeningRatio(); } }
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!"); } }