public static TamperState transform(final double state) throws CouldNotTransformException { if (state == 0) { return TamperState.newBuilder().setValue(TamperState.State.NO_TAMPER).build(); } else if (state > 0) { //TODO:mpohling/thuxohl adjust the tamper state to also reflect the intensity of the alarm! return TamperState.newBuilder().setValue(TamperState.State.TAMPER).build(); } else { throw new CouldNotTransformException("Could not transform " + Double.class.getName() + "! " + Double.class.getSimpleName() + "[" + state + "] is unknown!"); } }
@Override public TamperState getTamperState(final UnitType unitType) throws NotAvailableException { TamperState.State tamperValue = TamperState.State.NO_TAMPER; long lastDetection = 0; long timestamp = 0; for (TamperStateProviderService service : getServices(unitType)) { if (!((UnitRemote) service).isDataAvailable()) { continue; } TamperState tamperState = service.getTamperState(); if (tamperState.getValue() == TamperState.State.TAMPER) { tamperValue = TamperState.State.TAMPER; } if (tamperState.getLastDetection().getTime() > lastDetection) { lastDetection = tamperState.getLastDetection().getTime(); } timestamp = Math.max(timestamp, tamperState.getTimestamp().getTime()); } return TimestampProcessor.updateTimestamp(timestamp, TamperState.newBuilder().setValue(tamperValue).setLastDetection(Timestamp.newBuilder().setTime(lastDetection)), TimeUnit.MICROSECONDS, logger).build(); } }