ResourceAllocationType.ResourceAllocation.Priority.NORMAL, currentLocation, PowerState.newBuilder().setValue(PowerState.State.ON).build(), UnitType.LIGHT, ServiceTemplateType.ServiceTemplate.ServiceType.POWER_STATE_SERVICE, ResourceAllocationType.ResourceAllocation.Priority.NORMAL, currentLocation, PowerState.newBuilder().setValue(PowerState.State.OFF).build(), UnitType.LIGHT, ServiceTemplateType.ServiceTemplate.ServiceType.POWER_STATE_SERVICE,
ResourceAllocationType.ResourceAllocation.Priority.NORMAL, ambientLightGroup, PowerState.newBuilder().setValue(PowerState.State.OFF).build(), UnitType.LIGHT, ServiceTemplateType.ServiceTemplate.ServiceType.POWER_STATE_SERVICE, ResourceAllocationType.ResourceAllocation.Priority.NORMAL, locationRemote, PowerState.newBuilder().setValue(PowerState.State.OFF).build(), UnitType.LIGHT, ServiceTemplateType.ServiceTemplate.ServiceType.POWER_STATE_SERVICE,
timeout.restart(); if (location.getPowerState(UnitType.COLORABLE_LIGHT).getValue() != State.ON || !isColorReached(location.getColor().getHsbColor(), COLOR_ORANGE)) { if (location.getPowerState(UnitType.LIGHT).getValue() == State.ON && (timeout == null || timeout.isExpired() || !timeout.isActive())) {
latestPowerStateTarget = PowerState.State.OFF; for (UnitRemote targetRemote : targetRemotes) { if (getPowerState(targetRemote).getValue() == PowerState.State.ON) { latestPowerStateTarget = PowerState.State.ON; break;
ResourceAllocationType.ResourceAllocation.Priority.EMERGENCY, locationRemote, PowerState.newBuilder().setValue(PowerState.State.ON).build(), UnitType.LIGHT, ServiceTemplateType.ServiceTemplate.ServiceType.POWER_STATE_SERVICE,
private void switchMultimediaOff() { try { List<? extends UnitGroupRemote> unitsByLabel = Units.getUnitsByLabel(locationRemote.getLabel().concat("MultimediaGroup"), true, Units.UNITGROUP); if (!unitsByLabel.isEmpty()) { UnitGroupRemote multimediaGroup = unitsByLabel.get(0); ActionDescriptionType.ActionDescription.Builder actionDescriptionBuilder = getNewActionDescription(ActionAuthorityType.ActionAuthority.getDefaultInstance(), ResourceAllocationType.ResourceAllocation.Initiator.SYSTEM, 1000 * 30, ResourceAllocationType.ResourceAllocation.Policy.FIRST, ResourceAllocationType.ResourceAllocation.Priority.NORMAL, multimediaGroup, PowerState.newBuilder().setValue(PowerState.State.OFF).build(), UnitType.UNKNOWN, ServiceTemplateType.ServiceTemplate.ServiceType.POWER_STATE_SERVICE, MultiResourceAllocationStrategy.Strategy.AT_LEAST_ONE); actionRescheduleHelper.addRescheduleAction(multimediaGroup.applyAction(actionDescriptionBuilder.build()).get().toBuilder()); } } catch (NotAvailableException ex) { logger.info("MultimediaGroup not available."); } catch (InterruptedException ex) { logger.error("Could not get MultimediaGroup!"); } catch (CouldNotPerformException ex) { logger.error("Could not set Powerstate of MultimediaGroup."); } catch (ExecutionException ex) { logger.error("Could not set Powerstate of MultimediaGroup!"); } } }
PowerState.State newState; try { switch (serviceRemote.getPowerState().getValue()) { case OFF: case UNKNOWN: serviceRemote.setPowerState(PowerState.newBuilder().setValue(newState).build()); } catch (CouldNotPerformException ex) { throw new CouldNotPerformException("Could not switch power state.", ex);
handleSourcePowerStateUpdate(((PowerState) data).getValue()); } catch (Exception ex) { ExceptionPrinter.printHistory(ex, logger); sourceRequestObserver = (final Observable<GeneratedMessage> source, GeneratedMessage data) -> { try { handleSourcePowerStateRequest(((PowerState) data).getValue()); } catch (Exception ex) { ExceptionPrinter.printHistory(ex, logger); targetObserver = (final Observable<GeneratedMessage> source, GeneratedMessage data) -> { try { handleTargetPowerStateUpdate(((PowerState) data).getValue()); } catch (Exception ex) { ExceptionPrinter.printHistory(ex, logger); targetRequestObserer = (final Observable<GeneratedMessage> source, GeneratedMessage data) -> { try { handleTargetPowerStateRequest(((PowerState) data).getValue()); } catch (Exception ex) { ExceptionPrinter.printHistory(ex, logger);
@Override public LocationRemote newInstance(final UnitConfig locationUnitConfig) throws org.openbase.jul.exception.InstantiationException, InterruptedException { try { LocationRemote locationRemote = Units.getUnit(locationUnitConfig, false, Units.LOCATION); locationRemote.addDataObserver((final Observable<LocationData> source, LocationData data) -> { // some locations do not have units for a given state so this state will not be set in LocationData and should not be updated in openhab if (data.hasColorState()) { openHABRemote.postUpdate(OpenHABCommandFactory.newHSBCommand(data.getColorState().getColor().getHsbColor()).setItem(generateItemId(locationUnitConfig, ServiceType.COLOR_STATE_SERVICE)).build()); } if (data.hasPowerState()) { openHABRemote.postUpdate(OpenHABCommandFactory.newOnOffCommand(data.getPowerState().getValue()).setItem(generateItemId(locationUnitConfig, ServiceType.POWER_STATE_SERVICE)).build()); } if (data.hasPowerConsumptionState()) { openHABRemote.postUpdate(OpenHABCommandFactory.newDecimalCommand(data.getPowerConsumptionState().getConsumption()).setItem(generateItemId(locationUnitConfig, ServiceType.POWER_CONSUMPTION_STATE_SERVICE)).build()); } if (data.hasMotionState()) { // post a 1 for motion and a 0 for no motion double number = data.getMotionState().getValue() == MotionStateType.MotionState.State.MOTION ? 1.0 : 0.0; openHABRemote.postUpdate(OpenHABCommandFactory.newDecimalCommand(number).setItem(generateItemId(locationUnitConfig, ServiceType.MOTION_STATE_SERVICE)).build()); } if (data.hasTemperatureState()) { openHABRemote.postUpdate(OpenHABCommandFactory.newDecimalCommand(data.getTemperatureState().getTemperature()).setItem(generateItemId(locationUnitConfig, ServiceType.TEMPERATURE_STATE_SERVICE)).build()); } }); return locationRemote; } catch (CouldNotPerformException ex) { throw new org.openbase.jul.exception.InstantiationException(LocationRemote.class, ex); } }
@Override protected void updateDynamicComponents() { try { logger.info("state: " + getProviderService().getPowerState().getValue().name()); switch (getProviderService().getPowerState().getValue()) { case ON: powerStatusLabel.setForeground(Color.BLACK); powerStatePanel.setBackground(Color.GREEN.darker()); powerButton.setText("Switch Off"); break; case OFF: powerStatusLabel.setForeground(Color.LIGHT_GRAY); powerStatePanel.setBackground(Color.GRAY.darker()); powerButton.setText("Switch On"); break; case UNKNOWN: powerStatusLabel.setForeground(Color.BLACK); powerStatePanel.setBackground(Color.ORANGE.darker()); powerButton.setText("Switch Off"); break; default: throw new InvalidStateException("State[" + getProviderService().getPowerState().getValue() + "] is unknown."); } powerStatusLabel.setText("Current PowerState = " + StringProcessor.transformUpperCaseToCamelCase(getProviderService().getPowerState().getValue().name())); } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(ex, logger); } } }
private void handleTargetColorStateUpdate(final ColorState colorState, final UnitRemote colorableLightRemote) throws CouldNotPerformException { synchronized (AGENT_LOCK) { // if the color state changes turn source on before if (getPowerState(sourceRemote).getValue() != PowerState.State.ON) { final Future future = setPowerState(sourceRemote, ON); GlobalCachedExecutorService.submit(() -> { try { // wait for source remote to go on future.get(5, TimeUnit.SECONDS); // apply colorState again Services.invokeOperationServiceMethod(ServiceType.COLOR_STATE_SERVICE, colorableLightRemote, colorState); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } catch (Exception ex) { ExceptionPrinter.printHistoryAndReturnThrowable(new CouldNotPerformException("Could not set color state after turning on source", ex), logger); } }); setPowerState(sourceRemote, ON); } } }
/** * Handle a new requested power state for a target remote. * * @param powerState The requested power state for the target remote. */ private void handleTargetPowerStateRequest(final PowerState.State powerState) { logger.debug("Handle new RequestedValue[" + powerState + "] for target"); synchronized (AGENT_LOCK) { try { // if on is requested on a target and the source is not yet on turn it on if (powerState == PowerState.State.ON && latestPowerStateTarget == PowerState.State.OFF) { if (getPowerState(sourceRemote).getValue() != PowerState.State.ON) { setPowerState(sourceRemote, ON); } } } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory("Could not handle target power state request!", ex, logger); } } }
private void powerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_powerButtonActionPerformed try { switch (getOperationService().getPowerState().getValue()) { case ON: notifyActionProcessing(getOperationService().setPowerState(OFF)); break; case OFF: case UNKNOWN: notifyActionProcessing(getOperationService().setPowerState(ON)); break; default: throw new InvalidStateException("State[" + getProviderService().getPowerState().getValue() + "] is unknown."); } } catch (CouldNotPerformException ex) { ExceptionPrinter.printHistory(new CouldNotPerformException("Could not set power state!", ex), logger); } }//GEN-LAST:event_powerButtonActionPerformed
@Override public UnitGroupRemote newInstance(final UnitConfig unitGroupUnitConfig) throws org.openbase.jul.exception.InstantiationException, InterruptedException { try { UnitGroupRemote unitGroupRemote = Units.getUnit(unitGroupUnitConfig, false, Units.UNITGROUP); unitGroupRemote.addDataObserver((final Observable<UnitGroupData> source, UnitGroupData data) -> { // some locations do not have units for a given state so this state will not be set in LocationData and should not be updated in openhab if (data.hasColorState()) { openHABRemote.postUpdate(OpenHABCommandFactory.newHSBCommand(data.getColorState().getColor().getHsbColor()).setItem(generateItemId(unitGroupUnitConfig, ServiceType.COLOR_STATE_SERVICE)).build()); } if (data.hasPowerState()) { openHABRemote.postUpdate(OpenHABCommandFactory.newOnOffCommand(data.getPowerState().getValue()).setItem(generateItemId(unitGroupUnitConfig, ServiceType.POWER_STATE_SERVICE)).build()); } }); return unitGroupRemote; } catch (CouldNotPerformException ex) { throw new org.openbase.jul.exception.InstantiationException(LocationRemote.class, ex); } }
private void switchlightsOff() { try { ActionDescriptionType.ActionDescription.Builder actionDescriptionBuilder = getNewActionDescription(ActionAuthorityType.ActionAuthority.getDefaultInstance(), ResourceAllocationType.ResourceAllocation.Initiator.SYSTEM, 1000 * 30, ResourceAllocationType.ResourceAllocation.Policy.FIRST, ResourceAllocationType.ResourceAllocation.Priority.NORMAL, locationRemote, PowerState.newBuilder().setValue(PowerState.State.OFF).build(), UnitType.LIGHT, ServiceTemplateType.ServiceTemplate.ServiceType.POWER_STATE_SERVICE, MultiResourceAllocationStrategy.Strategy.AT_LEAST_ONE); actionRescheduleHelper.startActionRescheduleing(locationRemote.applyAction(actionDescriptionBuilder.build()).get().toBuilder()); } catch (CouldNotPerformException | InterruptedException | ExecutionException ex) { logger.error("Could not switch on Lights.", ex); } }
private void switchlightsOn() { try { ActionDescription.Builder actionDescriptionBuilder = getNewActionDescription(ActionAuthority.getDefaultInstance(), ResourceAllocation.Initiator.SYSTEM, 1000 * 30, ResourceAllocation.Policy.FIRST, ResourceAllocation.Priority.NORMAL, locationRemote, PowerState.newBuilder().setValue(PowerState.State.ON).build(), UnitType.LIGHT, ServiceTemplateType.ServiceTemplate.ServiceType.POWER_STATE_SERVICE, MultiResourceAllocationStrategy.Strategy.AT_LEAST_ONE); actionRescheduleHelper.startActionRescheduleing(locationRemote.applyAction(actionDescriptionBuilder.build()).get().toBuilder()); } catch (CouldNotPerformException | InterruptedException | ExecutionException ex) { logger.error("Could not switch on Lights.", ex); } } }
@Override public PowerState getPowerState(final UnitType unitType) throws NotAvailableException { PowerState.State powerStateValue = PowerState.State.OFF; long timestamp = 0; for (PowerStateOperationService service : getServices(unitType)) { if (!((UnitRemote) service).isDataAvailable()) { continue; } if (service.getPowerState().getValue() == PowerState.State.ON) { powerStateValue = PowerState.State.ON; } timestamp = Math.max(timestamp, service.getPowerState().getTimestamp().getTime()); } return TimestampProcessor.updateTimestamp(timestamp, PowerState.newBuilder().setValue(powerStateValue), TimeUnit.MICROSECONDS, logger).build(); }
default public Future<ActionFuture> setPowerState(final PowerState.State powerState, final UnitType unitType) throws CouldNotPerformException { return setPowerState(PowerState.newBuilder().setValue(powerState).build(), unitType); }
@Override default Future<ActionFuture> setPowerState(final PowerState.State state) throws CouldNotPerformException { return setPowerState(PowerState.newBuilder().setValue(state).build()); }