@Override
	public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) {
		super.onDataReceived(device, data);

		if (data.size() < 5) {
			onInvalidDataReceived(device, data);
			return;
		}

		int offset = 0;
		final int flags = data.getIntValue(Data.FORMAT_UINT8, offset);
		final int unit = (flags & 0x01) == UNIT_C ? UNIT_C : UNIT_F;
		final boolean timestampPresent = (flags & 0x02) != 0;
		final boolean temperatureTypePresent = (flags & 0x04) != 0;
		offset += 1;

		if (data.size() < 5 + (timestampPresent ? 7 : 0) + (temperatureTypePresent ? 1 : 0)) {
			onInvalidDataReceived(device, data);
			return;
		}

		final float temperature = data.getFloatValue(Data.FORMAT_FLOAT, 1);
		offset += 4;

		Calendar calendar = null;
		if (timestampPresent) {
			calendar = DateTimeDataCallback.readDateTime(data, offset);
			offset += 7;
		}

		Integer type = null;
		if (temperatureTypePresent) {
			type = data.getIntValue(Data.FORMAT_UINT8, offset);
			// offset += 1;
		}

		onTemperatureMeasurementReceived(device, temperature, unit, calendar, type);
	}
@Test
	public void onInvalidDataReceived() {
		final ProfileReadResponse response = new TemperatureMeasurementDataCallback() {
			@Override
			public void onTemperatureMeasurementReceived(@NonNull final BluetoothDevice device,
														 final float temperature, final int unit,
														 @Nullable final Calendar calendar,
														 @Nullable final Integer type) {
				called = true;
			}
		};

		final Data data = new Data(new byte[] { 0x06, (byte) 0xB0, 0x0E, 0x00, (byte) 0xFE, (byte) 0xDC, 0x07, 0x0C, 0x05, 0x0B, 0x32, 0x1B });
		called = false;
		response.onDataReceived(null, data);
		assertFalse(called);
		assertFalse(response.isValid());
	}