public Future executeCommand(final String itemName, final OpenhabCommandType.OpenhabCommand.Builder command) throws CouldNotPerformException { if (command == null) { throw new CouldNotPerformException("Skip sending empty command!", new NullPointerException("Argument command is null!")); } if (openHABRemote == null) { throw new CouldNotPerformException("Skip sending command, binding not ready!", new NullPointerException("Argument rsbBinding is null!")); } logger.debug("Execute command: Setting item [" + this.itemName + "] to [" + command.getType().toString() + "]"); return openHABRemote.postCommand(command.setItem(itemName).build()); }
@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 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); } }
@Override public AppRemote newInstance(final UnitConfig config) throws org.openbase.jul.exception.InstantiationException, InterruptedException { try { AppRemote appRemote = Units.getUnit(config, false, Units.APP); appRemote.addDataObserver((final Observable<AppData> source, AppData data) -> { openHABRemote.postUpdate(OpenHABCommandFactory.newOnOffCommand(data.getActivationState()).setItem(generateItemId(config)).build()); }); return appRemote; } catch (CouldNotPerformException ex) { throw new org.openbase.jul.exception.InstantiationException(AppRemote.class, ex); } }
@Override public SceneRemote newInstance(final UnitConfig config) throws org.openbase.jul.exception.InstantiationException, InterruptedException { try { SceneRemote sceneRemote = Units.getUnit(config, false, Units.SCENE); sceneRemote.addDataObserver((final Observable<SceneData> source, SceneData data) -> { openHABRemote.postUpdate(OpenHABCommandFactory.newOnOffCommand(data.getActivationState()).setItem(generateItemId(config)).build()); }); return sceneRemote; } catch (CouldNotPerformException ex) { throw new org.openbase.jul.exception.InstantiationException(SceneRemote.class, ex); } }