Repository navigation
Report the pod's active time and reservoir when it's deactivated - #36
Conversation
The deactivate command answered with a fixed, empty general status, so the pod reported 0 minutes active and a 0 U reservoir. OmnipodKit turns that time into the pod's stop time, which then became the pod's activation time. Deactivate now stops all delivery, returns an unfinished bolus to the reservoir and leaves the pod inactive. Its response is built from the pod's state, as other commands' responses are. The automatic 80-hour fault now uses SetFault, so a running bolus stops, and records its fault time at 80 hours instead of leaving it at 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ps2
left a comment
There was a problem hiding this comment.
Thanks, Marion. This looks right. I checked it against OmnipodKit's deactivatePod and ran the tests.
- Tests:
go build,go vetandgo test ./...pass at 447a7d7, including both new tests.gofmtis clean on the changed files. - Working pod: OmnipodKit sends
cancelDelivery(.all)first, then 0x1C, and callssetDeliveryStoppedAt(podTime: status.timeActive)on the general status it gets back. The stop time now comes from the real minutes active, and the reservoir from the real level. - Faulted pod: the sim answers 0x1C with a detailed status. OmnipodKit turns that into
.podFault, skipssetDeliveryStoppedAtand keeps the fault time as the stop time. - Deactivated after 80 hours, before any status request:
handleCommandruns beforegetResponse. The pod is made inactive first, then the 80-hour check raises 0x1C with the fault time at 80 hours, so OmnipodKit sees a fault and the stop time is 80 hours. That matches your test plan step 3. The sim exits after a deactivate, so its minutes active don't keep counting afterwards. - History: 129ec46 and 9c6ac56 are as described.
One observation, not blocking: OmnipodKit cancels all delivery before 0x1C on any set-up pod that isn't faulted or suspended, so Loop never deactivates during a bolus. Returning the unfinished bolus to the reservoir in Deactivate() is still correct for any other client, and the test covers it.
Test✅ successful test and Loop (Trio) will now report correct deactivation time when testing with a simulator.
ConfigurationThe Loop next-dev version on my test phone still has the extra print statements from the OmnipodKit 224 test Restart existing rPi using code built from this PR: Modify values using the rPi URL to these:
Disable closed Loop for the app so need to worry about manual boluses.
User initiated Pod Change14:12 Deactivate Pod (user initiated), then pair new pod and carry through to insertion
✅ Xcode debug prints:
Fault initiated Pod Change✅ successful test Using the rPi URL
14:20: Issue a reset fault 0x10
Previous Pod:
Xcode debug prints:
End of time (0x1c) initiated Pod Change✅ successful test 14:26 set reservoir to 15 U; do not bother changing pod active time on rPi - should not matter
Previous Pod:
Xcode debug prints:
Deactivate while Pod reports > 50 unitsshould get remainingUnits of nil
|
The deactivate command (0x1C) answered with a fixed, empty general status, so the pod reported 0 minutes active and a 0 U reservoir. A real pod reports its actual time and reservoir.
OmnipodKit computes the pod's stop time at deactivation from the minutes active the pod reports. With 0 minutes, the stop time became the pod's activation time, and it replaced a correct fault time. The 0 U also became the pod's last reservoir reading. This showed up while testing loopandlearn/OmnipodKit#224 with LoopKit/LoopKit#703, which add the stop time and last reading to the Pod Change record.
Changes
SetFault, so a running bolus stops. It records the fault time at 80 hours. Before, the fault time was left at 0, which OmnipodKit treats as unknown, as for a reset fault.History
Testing
TestDeactivateReportsTheRealTimeAndReservoirchecks the deactivate reply's time, reservoir, delivered insulin, pod progress and delivery bits.TestTheEightyHourFaultHappensAtEightyHourschecks the fault code and its time. These haven't been run locally, because Go isn't installed on the Mac where the change was made. CI runsgo test ./....stopDateat the deactivation time andremainingUnits: nil.remainingUnitsshould be the reservoir level.stopDateshould be 80 hours after activation, withexpired.stopDateshould be the fault time.🤖 Generated with Claude Code