Skip to content

feat: Add Afrezza (Technosphere) inhaled insulin support#4877

Open
CAPTCG wants to merge 12 commits into
nightscout:devfrom
CAPTCG:feat_afrezza_clean
Open

feat: Add Afrezza (Technosphere) inhaled insulin support#4877
CAPTCG wants to merge 12 commits into
nightscout:devfrom
CAPTCG:feat_afrezza_clean

Conversation

@CAPTCG

@CAPTCG CAPTCG commented Jun 2, 2026

Copy link
Copy Markdown

Adds per-bolus IOB tracking for Afrezza inhaled insulin with correct pharmacokinetic curve (peak 40min, DIA 2.5h).

What's included:

  • InsulinType.OREF_INHALED_AFREZZA with inhaled DIA limits (1.5–4h)
  • One-tap Afrezza dialog with 4U/8U/12U cartridge buttons
  • Wear OS Actions tile for logging Afrezza from the watch
  • Navigation, quick-launch, and Treatment Bottom Sheet integration
  • Sources.AfrezzaDialog for treatment history tracking
  • 179-line IOB curve validation test suite

Design decisions:

  • Afrezza boluses are logged directly via PersistenceLayer, bypassing the pump command queue (inhaled, not pump-delivered)
  • ICfg lookup matches by Afrezza peak time, consistent with the existing per-bolus insulin architecture
  • No changes to existing insulin types or pump logic

Tested on phone + Wear OS watch with signed release builds.

Afrezza Feature added 9 commits June 2, 2026 18:34
Add string resources for Afrezza (Technosphere) inhaled insulin support:
- core/interfaces: insulin type label and description
- core/ui: navigation label and treatment description
- ui: Afrezza quick-log dialog strings
- Add OREF_INHALED_AFREZZA enum entry (peak=40min, DIA=2.5h, value=6)
- Add isInhaled property to InsulinType for delivery route identification
- Add MIN_DIA_INHALED/MAX_DIA_INHALED to HardLimits (1.5h-4.0h range)
- Add minDiaInhaled()/maxDiaInhaled() to HardLimits interface, impl, and test mock

Afrezza (Technosphere) pharmacokinetics: onset ~12min, peak ~40min,
clinical duration 1.5-3h depending on cartridge size (4U/8U/12U).
Conservative DIA of 2.5h covers the majority of insulin activity.
- Add OREF_INHALED_AFREZZA to insulinTemplateList() in InsulinImpl
- Update InsulinManagementViewModel to use inhaled DIA limits (1.5-4.0h)
  when the editor template is an inhaled insulin type
- Make diaRange() template-aware so the UI slider shows correct bounds
- Subcutaneous insulin DIA limits (5.0-9.0h) remain unchanged
Comprehensive test suite validating the oref bilinear model at Afrezza's
short DIA (2.5h) and early peak (40min):

- IOB starts near 1.0 at t=0 and reaches 0 at t=DIA
- No NaN or negative values across entire curve
- Peak activity occurs near configured peak time (40min)
- Monotonic IOB decrease after peak
- Afrezza IOB decays faster than Fiasp (comparative)
- Dose scaling correct for cartridge sizes (4U/8U/12U)
- Combined Afrezza+Fiasp IOB sums correctly, with Afrezza
  dropping to zero while Fiasp remains active
New Compose bottom sheet dialog with three large cartridge-size buttons
(4U, 8U, 12U) for rapid Afrezza dose logging:

- AfrezzaDialogScreen: Bottom sheet with cartridge selection UI
- AfrezzaDialogViewModel: Resolves Afrezza ICfg from InsulinManager,
  creates record-only bolus with correct per-bolus ICfg
- AfrezzaDialogUiState: Minimal state for cartridge selection flow

User flow: tap cartridge -> confirm -> done (2 taps total).
Bolus is created as record-only with Afrezza ICfg, ensuring the
IOB calculator uses the correct short-DIA curve.
- Add ElementType.AFREZZA with TREATMENT category and BOLUS protection
- Map Afrezza icon (IcBolus), color (insulin), label, and description
- Afrezza appears in global search and treatment action sheets
- Add AppRoute.AfrezzaDialog route definition
- Register AfrezzaDialogScreen composable in AppNavGraph
- Add ElementType.AFREZZA -> AfrezzaDialog navigation handler
- Add QuickLaunchAction.Afrezza static action and to staticActions list
- Users can add Afrezza to their quick-launch bar via configuration
- Add showAfrezza to TreatmentUiState
- Inject InsulinManager into TreatmentViewModel to detect configured
  inhaled insulin — Afrezza button appears automatically when an
  inhaled insulin type exists in the user's insulin list
- Thread showAfrezza through TreatmentBottomSheet -> TreatmentSelectionContent
- Afrezza item appears between Insulin and Carbs in the treatment sheet
- Include showAfrezza in Preview composable
- No user preference toggle needed — presence is driven by insulin config
- Add AfrezzaDialog to Sources enum (core/data)
- Add AfrezzaDialog to UserEntry.Sources DB enum (database/impl)
- Add bidirectional mapping in SourcesExtension (database/persistence)
- Add icon and color mappings in UserEntryPresentationHelperImpl
- Afrezza doses are now distinguishable from pump boluses in
  treatment history and UserEntry logs
@CAPTCG

CAPTCG commented Jun 2, 2026

Copy link
Copy Markdown
Author

The CircleCI failures are due to "Forked PRs not allowed to run on OSS projects" — not a code issue. SonarCloud passed with no new alerts and Quality Gate passed. Happy to address any changes needed after review.

@CAPTCG CAPTCG force-pushed the feat_afrezza_clean branch from 8a31f2e to 021f73e Compare June 2, 2026 22:57
- Add AfrezzaActivity with cartridge dose selection (4U, 8U, 12U)
  and confirmation screen for Wear OS
- Add ActionAfrezzaPreCheck and ActionAfrezzaConfirmed events to
  EventData sealed class for watch-phone communication
- Register Afrezza as selectable action in ActionSource tile config
- Add phone-side handler in DataHandlerMobile that logs Afrezza bolus
  directly via PersistenceLayer (bypasses pump queue for inhaled insulin)
- Inject InsulinManager to look up Afrezza ICfg by peak time
- Add ic_afrezza.xml inhaler icon drawable for wear tile
- Add wear string resources and AndroidManifest activity registration
- Add afrezza_not_configured error string to core/ui
@CAPTCG CAPTCG force-pushed the feat_afrezza_clean branch from 021f73e to 3bd06ef Compare June 2, 2026 22:58
@CAPTCG

CAPTCG commented Jun 5, 2026

Copy link
Copy Markdown
Author

@CAPTCG

CAPTCG commented Jun 7, 2026

Copy link
Copy Markdown
Author

@MilosKozak @Philoul
This plugin has been a huge step in improving my post-mealtime glucose control. The new bolus IOB tracking for Afrezza inhaled insulin with correct pharmacokinetic curve (peak 40min, DIA 2.5h) combined directly into AAPS V4 with the previous Fiasp IOB tracking, has been keeping my post meal blood glucose in tighter range than when I was using Fiasp alone.

This plugin should be merged into the dev branch as soon as possible. Please consider the overall control benefits for AAPS users that can access Afrezza Inhaled insulin. It is a remarkable improvement.

Report for Affrezza plugin.pdf

@CAPTCG

CAPTCG commented Jun 9, 2026

Copy link
Copy Markdown
Author

@Philoul Thanks for the review you started. I can update the PR without force pushing. No worries with that.
Pertaining to the build errors, I assume you applied my PR against a fresh dev pull? Every day the new commits to the dev branch seem to cause the build errors. I can resolve those at the current dev head however, how should I avoid the issue moving forward?

@Philoul

Philoul commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

I can update the PR without force pushing. No worries with that.

Thx 👍

I first tried to build your branch with latest dev updates, then without.

  • same results and not a surprised, bugs are within shared updated files

@Philoul

Philoul commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Every day the new commits to the dev branch seem to cause the build errors. I can resolve those at the current dev head however, how should I avoid the issue moving forward?

Welcome to open source development, it's our daily work because you are not alone (and git is here to help us...)

Some tips

  • the less you modify files, the more you limit risks to generate conflicts or regressions
  • the smallest your PR is, the easiest it can be merged
  • always build and check your local branch still work before each commit (within emulator or physical development phone).
  • you don't need to update every days your working branch, but it's important to check regularly within your opened PR that you don't have new conflicts due to dev branch updates. If yes then you have to merge dev branch within your working branch to fix conflicts on your side, and then push again the updated branch.
  • be patient if the idea is good and improve the overall management of diabetes for lots of users, is robust, sustainable and we'll designed, then it will be merged, but it can take time (

One example within UserEntryPresentationHelperImpl.kt file, you really need to add maximum 2 or 3 lines, but you modified dozen and dozen of lines 🥴.

You included Afrezza and Wear within the same PR...

  • it's much better to do it seperatly: one smaller PR for Afrezza
  • then only after everything has been fixed and when the opened PR has been merged, you can propose a second simple PR only to update WearOS

The bigger your PR are, the more you increase risks to have roadblocks, regressions, side effects...

CAPTCG added 2 commits June 9, 2026 16:38
…UserEntry diff

- Fix merge conflict markers and duplicate MAX_DIA in HardLimits.kt
- Fix unused lambda parameter (message -> _) in AppNavGraph.kt
- Reset UserEntryPresentationHelperImpl.kt to dev, re-add only 2 Afrezza lines
- Remove Wear OS changes (AfrezzaActivity, EventData, DataHandlerMobile, etc.)
- Merge latest dev to resolve all conflicts
@CAPTCG

CAPTCG commented Jun 9, 2026

Copy link
Copy Markdown
Author

@Philoul Thanks for the detailed review and tips — really helpful.

Changes in this update:

  • Merged latest dev, resolved all merge conflicts (HardLimits.kt duplicate MAX_DIA + conflict markers)
  • Fixed unused lambda parameter (message_) in AppNavGraph.kt
  • Reset UserEntryPresentationHelperImpl.kt to dev — now only 2 added lines (icon + color for AfrezzaDialog)
  • Removed all Wear OS changes (AfrezzaActivity, EventData, DataHandlerMobile, ic_afrezza.xml, etc.) — will submit as a separate PR after this one merges
  • Clean build passes on current dev head, Afrezza IOB test suite passes

SonarCloud when-branch warnings (icon/label/description in ElementTypeStyle.kt) are pre-existing — dev already has 48 branches in those blocks before this PR. AFREZZA adds +1 each.

@sonarqubecloud

sonarqubecloud Bot commented Jun 9, 2026

Copy link
Copy Markdown

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