@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) -> {
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()) {
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);
}
}