Skip to content

Report the pod's active time and reservoir when it's deactivated - #36

Merged
ps2 merged 1 commit into
mainfrom
update/deactivate-handler
Nov 24, 2026
Merged

ps2 merged 1 commit into
mainfrom
update/deactivate-handler

Conversation

@marionbarker

Copy link
Copy Markdown

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

  • Deactivate: The command stops all delivery, returns an unfinished bolus to the reservoir, and leaves the pod inactive (pod progress 15). Its response is built from the pod's state, so it reports the real minutes active and reservoir. A faulted pod answers with a detailed status, as it does for any other command, and OmnipodKit keeps the stop time from the fault.
  • 80-hour fault: The automatic 0x1C fault now uses 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

  • 129ec46 (2025-05-26) replaced an earlier fixed deactivate reply, which decoded to about 60.5 hours and 37.75 U, with the empty general status.
  • 9c6ac56 (2026-09-07) added the automatic 80-hour fault without a fault time.

Testing

  • Unit tests: Two tests are added. TestDeactivateReportsTheRealTimeAndReservoir checks the deactivate reply's time, reservoir, delivered insulin, pod progress and delivery bits. TestTheEightyHourFaultHappensAtEightyHours checks 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 runs go test ./....
  • With Loop: Not tested yet. These checks are planned with Loop next-dev plus OmnipodKit#224:
    1. Pair a pod, wait a few minutes, then deactivate it. The next Pod Change should have stopDate at the deactivation time and remainingUnits: nil.
    2. Set the reservoir below 50 U, then deactivate. remainingUnits should be the reservoir level.
    3. Let a pod reach 80 hours, then deactivate. stopDate should be 80 hours after activation, with expired.
    4. Set a fault from the control panel, then deactivate. stopDate should be the fault time.

🤖 Generated with Claude Code

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 ps2 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Marion. This looks right. I checked it against OmnipodKit's deactivatePod and ran the tests.

  • Tests: go build, go vet and go test ./... pass at 447a7d7, including both new tests. gofmt is clean on the changed files.
  • Working pod: OmnipodKit sends cancelDelivery(.all) first, then 0x1C, and calls setDeliveryStoppedAt(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, skips setDeliveryStoppedAt and keeps the fault time as the stop time.
  • Deactivated after 80 hours, before any status request: handleCommand runs before getResponse. 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.

@marionbarker

Copy link
Copy Markdown
Author

Test

✅ successful test and Loop (Trio) will now report correct deactivation time when testing with a simulator.

  • pod code is not a perfect simulator - but this is a big improvement
  • the pod reported units remaining when available is reported through the new PreviousComponent feature added with LoopKIt 703 and OmnipodKit 224, indicating this will work for a real pod.

Configuration

The 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:

  • Pod age is 50.93 hours
  • Pod reservoir is 31.5 U

Disable closed Loop for the app so need to worry about manual boluses.

  • Issue manual bolus of 0.5 U
    • Pod reservoir is 31.0 U

User initiated Pod Change

14:12 Deactivate Pod (user initiated), then pair new pod and carry through to insertion
✅ The Previous Pod report now indicates deactivation happened at 14:12 (local)

  • The issue this PR was created to fix is that using the simulator without this PR, deactivation was reported at 1 minute before the pod was activated

✅ Xcode debug prints:

  • PreviousComponent:
    • stopDate: Optional(2026-11-24 22:12:04 +0000),
    • remainingUnits: Optional(31.0),
    • reason: LoopKit.ComponentReplacement.Reason.userInitiated))
    • ✅ both stopDate and remainingUnits are now expected values using this version of rPi code

Fault initiated Pod Change

✅ successful test

Using the rPi URL

  • modify active time to 30 hours
  • modify reservoir to 20 U

14:20: Issue a reset fault 0x10

  • Deactivate and pair/prime/insert new
    • examine Previous Pod information in Loop
    • read the PreviousComponent information from Xcode

Previous Pod:

  • activated 14:13 (local, UTC -8)
  • deactivated 14:20
  • pod fault 016 (0x10)

Xcode debug prints:

  • stopDate: Optional(2026-11-24 22:20:56 +0000),
  • remainingUnits: Optional(20.0),
  • reason: LoopKit.ComponentReplacement.Reason.fault(code: Optional("0x10"))

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
14:28 trigger 0x1c Exceeded maximum Pod life of 80 hours

  • Deactivate and pair/prime/insert new
    • examine Previous Pod information in Loop
    • read the PreviousComponent information from Xcode

Previous Pod:

  • activated 14:21 (local, UTC -8)
  • deactivated 14:28
  • pod life = 0.13 hours (not affected by what the rPi might indicate)
  • pod fault 028 (0x1c)

Xcode debug prints:

  • stopDate: Optional(2026-11-24 22:28:57 +0000),
  • remainingUnits: Optional(15.0),
  • reason: LoopKit.ComponentReplacement.Reason.expired))

Deactivate while Pod reports > 50 units

should get remainingUnits of nil

  • 14:41 Deactivate while reservoir shows as 50+ and pair/prime/insert new
  • ✅ examine the Xcode debug print statements:
    • stopDate: Optional(2026-11-24 22:40:37 +0000),
    • remainingUnits: nil,
    • reason: LoopKit.ComponentReplacement.Reason.userInitiated)

@ps2
ps2 merged commit fe49b1c into main Nov 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants