Skip to content

WIP: CareLevo driver - #4742

Open
MilosKozak wants to merge 72 commits into
devfrom
carelevo
Open

WIP: CareLevo driver#4742
MilosKozak wants to merge 72 commits into
devfrom
carelevo

Conversation

@MilosKozak

Copy link
Copy Markdown
Contributor

No description provided.

@codecov

codecov Bot commented Apr 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.47331% with 1056 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.49%. Comparing base (ca3176a) to head (6e207c1).
⚠️ Report is 3 commits behind head on dev.

Files with missing lines Patch % Lines
...aaps/pump/carelevo/ble/CarelevoBleTransportImpl.kt 14.19% 131 Missing and 2 partials ⚠️
...ps/pump/carelevo/compose/CarelevoOverviewScreen.kt 55.02% 87 Missing and 7 partials ⚠️
...ps/pump/carelevo/compose/CarelevoComposeContent.kt 7.14% 91 Missing ⚠️
...otlin/app/aaps/pump/carelevo/CarelevoPumpPlugin.kt 81.93% 53 Missing and 16 partials ⚠️
...p/carelevo/coordinator/CarelevoBolusCoordinator.kt 79.61% 43 Missing and 20 partials ⚠️
...aps/pump/carelevo/emulator/CarelevoPumpEmulator.kt 79.02% 19 Missing and 41 partials ⚠️
...lin/app/aaps/pump/carelevo/common/CarelevoPatch.kt 85.01% 38 Missing and 14 partials ⚠️
...se/patchflow/CarelevoPatchFlowStep03SafetyCheck.kt 77.18% 37 Missing and 10 partials ⚠️
...n/app/aaps/pump/carelevo/ble/CarelevoBleSession.kt 82.15% 24 Missing and 14 partials ⚠️
...pump/carelevo/common/CarelevoAlarmActionHandler.kt 73.94% 24 Missing and 7 partials ⚠️
... and 64 more
Additional details and impacted files
@@             Coverage Diff              @@
##                dev    #4742      +/-   ##
============================================
+ Coverage     53.61%   55.49%   +1.88%     
- Complexity    18763    20496    +1733     
============================================
  Files          3371     3535     +164     
  Lines        195765   205531    +9766     
  Branches      23008    24191    +1183     
============================================
+ Hits         104950   114059    +9109     
- Misses        83277    83553     +276     
- Partials       7538     7919     +381     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
3 Security Hotspots
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Comment thread pump/carelevo/src/main/AndroidManifest.xml Fixed
Comment thread pump/carelevo/src/main/AndroidManifest.xml Fixed
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)
C Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Kisu-Choi and others added 10 commits August 5, 2026 15:29
Match key for upsertAlarm changes from exact (alarmType, cause) to
cause.canonicalKey() only, so WARNING/ALERT/NOTICE tiers of the same
underlying condition merge into one record instead of appending
duplicates, keeping the higher-priority occurrence.
On BLE reconnect, poll the patch's active-alarm snapshot tiers
(CRITICAL/ADVISORY/NOTIFICATION via command 0x43) and reconcile them
against the locally persisted alarm set. This is a level-triggered
poll — unlike the push-alarm path it reports current state each time
rather than edges — so the app diffs against a persisted 'previously
seen' baseline (via cause) to raise newly-active alarms and clear
resolved ones without resurrecting anything the user already
acknowledged.

readActiveAlarmSnapshots is internally bounded: on timeout it returns
an empty list rather than throwing, so an older patch that never
answers this (newer-firmware-only) command cannot tear down the held
BLE link or disrupt whatever the queue runs next.
…stom dialog

Escalate a critical alarm through both the shared AAPS full-screen
alarm (uiInteraction.runAlarm) and the persistent notification card,
mirroring EOPatch's AlarmManager.showNotification dual-escalation
pattern. handleAlarms now posts the top notification for every alarm
set (not only non-critical ones), and its 'confirm' action clears the
same alarm via AlarmEvent.ClearAlarm regardless of which surface rang.

This replaces the previous mutually-exclusive design (custom in-app
CarelevoAlarmScreen showing the full-screen alarm only while mounted,
global runAlarm only otherwise, gated by alarmHostActive) — that
mount-timing race had previously caused a real double-dialog bug.
Dropping the custom dialog removes one of the two competing
full-screen mechanisms instead of trying to perfectly synchronize
them.

Dead code cleanup that falls out of this: CarelevoAlarmScreen and its
tests, alarmHostActive, CarelevoAlarmHost's buildAlarmUiModel/
buildDescArgsFor helpers, and the now-unused AlarmEvent.Mute/
Mute5min/StartAlarm variants. CarelevoAlarmViewModel is now a thin
pass-through of CarelevoAlarmActionHandler's UI-request stream.
PREF_KEY_LAST_SNAPSHOT_ALARM_CAUSES tracks which alarm causes the last
active-alarm snapshot reported, globally rather than per patch
address. Left untouched on discard, it kept marking a cause the
*previous* (now-abandoned) patch already reported as 'already seen',
so a freshly re-paired patch reporting that same cause for the first
time was silently suppressed by applyActiveAlarmSnapshots's
edge-triggered reconciliation.

flushPatchInformation() now clears this baseline alongside the
cached patch/infusion info it already resets on discard.
…arm mute

showTopNotification posted critical alarms at NotificationLevel.URGENT
with soundRes set — NotificationManagerImpl's own alarm/sound tier.
The shared full-screen alarm's OK button (UiInteraction.stopAlarm ->
muteAllAlarms) silences every URGENT+sound notification app-wide on
confirm, which wiped the CareLevo card off the screen without the
underlying alarm ever being acknowledged or cleared — an unhandled
critical alarm could end up invisible with no reliable way back
short of backgrounding and re-foregrounding the whole app.

Post critical alarms at IMPORTANT with no sound instead, matching
eopatch's AlarmManager.showNotification pattern: sound/full-screen
escalation stays runAlarm's job alone, so the card itself falls
outside muteAllAlarms's filter and survives that confirm until the
user genuinely clears the alarm through it.
- CarelevoEmulatorBleTransport: emit a real RSSI on scan results
  (EMULATED_RSSI=-30) instead of leaving it at Int.MIN_VALUE, which was
  silently failing CarelevoPatchConnectViewModel's RSSI filter.
- CarelevoPumpEmulator: implement the 0x43 active-alarm-snapshot
  responder (critical/advisory/notification tiers) and wire alarmClear()
  to actually clear the matching tier's flag instead of no-op'ing.
- CarelevoPumpState: track per-tier alarm flags (critical/advisory/
  notification) instead of a single shared set.
- Config/CarelevoModules: four new debug-only ExternalOptions marker
  files (emulate_carelevo_low_battery[_alert], _occlusion,
  _invalid_temperature) that seed the emulator's alarm flags on launch,
  so each alarm scenario can be reproduced on demand without real
  hardware.
- Emulator tests updated to cover the new snapshot/clear behavior.
@sonarqubecloud

sonarqubecloud Bot commented Sep 8, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Security Rating on New Code (required ≥ A)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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.

3 participants