From 44bfab49b29624ecbded0460a9bf72afcb00a2d7 Mon Sep 17 00:00:00 2001 From: James Woglom Date: Thu, 26 Dec 2024 21:13:53 -0500 Subject: [PATCH] failed temp rate test --- .../response/control/SetTempRateResponse.java | 3 +++ .../currentStatus/AlertStatusResponse.java | 4 ++++ .../response/control/SetTempRateResponseTest.java | 14 ++++++++++++++ .../currentStatus/AlertStatusResponseTest.java | 13 ++++++++++++- 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/response/control/SetTempRateResponse.java b/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/response/control/SetTempRateResponse.java index 9efebe08..988fed1b 100644 --- a/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/response/control/SetTempRateResponse.java +++ b/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/response/control/SetTempRateResponse.java @@ -50,6 +50,9 @@ public static byte[] buildCargo(byte[] raw) { } + /** + * @return 0 if successful otherwise unsuccessful + */ public int getStatus() { return status; } diff --git a/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/response/currentStatus/AlertStatusResponse.java b/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/response/currentStatus/AlertStatusResponse.java index ec886d3e..e146ec95 100644 --- a/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/response/currentStatus/AlertStatusResponse.java +++ b/messages/src/main/java/com/jwoglom/pumpx2/pump/messages/response/currentStatus/AlertStatusResponse.java @@ -27,6 +27,10 @@ public AlertStatusResponse(BigInteger intMap) { this.intMap = intMap; } + public AlertStatusResponse(byte[] raw) { + parse(raw); + } + private static byte[] buildCargo(BigInteger byte0uint64) { return Bytes.toUint64(byte0uint64.longValue()); } diff --git a/messages/src/test/java/com/jwoglom/pumpx2/pump/messages/response/control/SetTempRateResponseTest.java b/messages/src/test/java/com/jwoglom/pumpx2/pump/messages/response/control/SetTempRateResponseTest.java index 07c78cba..eb297a2e 100644 --- a/messages/src/test/java/com/jwoglom/pumpx2/pump/messages/response/control/SetTempRateResponseTest.java +++ b/messages/src/test/java/com/jwoglom/pumpx2/pump/messages/response/control/SetTempRateResponseTest.java @@ -3,6 +3,8 @@ import static com.jwoglom.pumpx2.pump.messages.MessageTester.assertHexEquals; import static com.jwoglom.pumpx2.pump.messages.MessageTester.initPumpState; +import static org.junit.Assert.assertEquals; + import com.jwoglom.pumpx2.pump.messages.MessageTester; import com.jwoglom.pumpx2.pump.messages.PacketArrayList; import com.jwoglom.pumpx2.pump.messages.bluetooth.CharacteristicUUID; @@ -40,4 +42,16 @@ public void testSetTempRateResponse_101pct_15min() throws DecoderException { ); assertHexEquals(expected.getCargo(), parsedReq.getCargo()); } + + + @Test + public void testSetTempRateResponse_failed() throws DecoderException { + initPumpState(PacketArrayList.IGNORE_INVALID_HMAC, 0L); + + SetTempRateResponse expected = new SetTempRateResponse( + new byte[]{1,0,0,1} + ); + + assertEquals(1, expected.getStatus()); + } } \ No newline at end of file diff --git a/messages/src/test/java/com/jwoglom/pumpx2/pump/messages/response/currentStatus/AlertStatusResponseTest.java b/messages/src/test/java/com/jwoglom/pumpx2/pump/messages/response/currentStatus/AlertStatusResponseTest.java index cb972ec8..777c75fb 100644 --- a/messages/src/test/java/com/jwoglom/pumpx2/pump/messages/response/currentStatus/AlertStatusResponseTest.java +++ b/messages/src/test/java/com/jwoglom/pumpx2/pump/messages/response/currentStatus/AlertStatusResponseTest.java @@ -1,5 +1,9 @@ package com.jwoglom.pumpx2.pump.messages.response.currentStatus; +import static com.jwoglom.pumpx2.pump.messages.response.currentStatus.AlertStatusResponse.AlertResponseType.CGM_GRAPH_REMOVED; +import static org.junit.Assert.assertEquals; + +import com.google.common.collect.ImmutableSet; import com.jwoglom.pumpx2.pump.messages.MessageTester; import com.jwoglom.pumpx2.pump.messages.bluetooth.CharacteristicUUID; @@ -44,7 +48,6 @@ public void testAlertStatusWithDevicePaired() throws DecoderException { @Test public void testAlertStatusWithIncompleteCartridgeChange() throws DecoderException { - // empty cargo AlertStatusResponse expected = new AlertStatusResponse( AlertStatusResponse.AlertResponseType.INCOMPLETE_CARTRIDGE_CHANGE_ALERT.withBit()); @@ -58,4 +61,12 @@ public void testAlertStatusWithIncompleteCartridgeChange() throws DecoderExcepti MessageTester.assertHexEquals(expected.getCargo(), parsedReq.getCargo()); } + @Test + public void testAlertStatusWithCgmGraphRemoved() { + AlertStatusResponse parsed = new AlertStatusResponse( + new byte[]{0,0,0,2,0,0,0,0} + ); + + assertEquals(ImmutableSet.of(AlertStatusResponse.AlertResponseType.CGM_GRAPH_REMOVED), parsed.getAlerts()); + } }