Skip to content

Commit

Permalink
Merge pull request #285 from kskandis/home-view-status-on-pump-deacti…
Browse files Browse the repository at this point in the history
…vated

add observer on pump deactivated to initialize pump status
  • Loading branch information
bjornoleh authored Jun 8, 2024
2 parents 2ec9fb1 + 3201d26 commit 9654d70
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
7 changes: 7 additions & 0 deletions FreeAPS/Sources/APS/DeviceDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ extension BaseDeviceDataManager: PumpManagerDelegate {
func pumpManagerWillDeactivate(_: PumpManager) {
dispatchPrecondition(condition: .onQueue(processQueue))
pumpManager = nil
broadcaster.notify(PumpDeactivatedObserver.self, on: processQueue) {
$0.pumpDeactivatedDidChange()
}
}

func pumpManager(_: PumpManager, didUpdatePumpRecordsBasalProfileStartEvents _: Bool) {}
Expand Down Expand Up @@ -667,3 +670,7 @@ protocol PumpReservoirObserver {
protocol PumpBatteryObserver {
func pumpBatteryDidChange(_ battery: Battery)
}

protocol PumpDeactivatedObserver {
func pumpDeactivatedDidChange()
}
25 changes: 16 additions & 9 deletions FreeAPS/Sources/Modules/Home/HomeStateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ extension Home {
broadcaster.register(EnactedSuggestionObserver.self, observer: self)
broadcaster.register(PumpBatteryObserver.self, observer: self)
broadcaster.register(PumpReservoirObserver.self, observer: self)
broadcaster.register(PumpDeactivatedObserver.self, observer: self)

animatedBackground = settingsManager.settings.animatedBackground

Expand Down Expand Up @@ -169,7 +170,7 @@ extension Home {
} else {
self.setupBattery()
self.setupReservoir()
self.displaypumpStatusHighlightMessage()
self.displayPumpStatusHighlightMessage()
}
}
.store(in: &lifetime)
Expand Down Expand Up @@ -352,13 +353,14 @@ extension Home {

/// Display the eventual status message provided by the manager of the pump
/// Only display if state is warning or critical message else return nil
private func displaypumpStatusHighlightMessage() {
private func displayPumpStatusHighlightMessage(_ didDeactivate: Bool = false) {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
if let statusHL = self.provider.deviceManager.pumpManager?.pumpStatusHighlight,
statusHL.state == .warning || statusHL.state == .critical
if let statusHighlight = self.provider.deviceManager.pumpManager?.pumpStatusHighlight,
statusHighlight.state == .warning || statusHighlight.state == .critical, !didDeactivate
{
pumpStatusHighlightMessage = (statusHL.state == .warning ? "⚠️\n" : "‼️\n") + statusHL.localizedMessage
pumpStatusHighlightMessage = (statusHighlight.state == .warning ? "⚠️\n" : "‼️\n") + statusHighlight
.localizedMessage
} else {
pumpStatusHighlightMessage = nil
}
Expand Down Expand Up @@ -395,7 +397,8 @@ extension Home.StateModel:
CarbsObserver,
EnactedSuggestionObserver,
PumpBatteryObserver,
PumpReservoirObserver
PumpReservoirObserver,
PumpDeactivatedObserver
{
func glucoseDidUpdate(_: [BloodGlucose]) {
setupGlucose()
Expand Down Expand Up @@ -429,7 +432,7 @@ extension Home.StateModel:
setupBasals()
setupBoluses()
setupSuspensions()
displaypumpStatusHighlightMessage()
displayPumpStatusHighlightMessage()
}

func pumpSettingsDidChange(_: PumpSettings) {
Expand All @@ -455,12 +458,16 @@ extension Home.StateModel:

func pumpBatteryDidChange(_: Battery) {
setupBattery()
displaypumpStatusHighlightMessage()
displayPumpStatusHighlightMessage()
}

func pumpReservoirDidChange(_: Decimal) {
setupReservoir()
displaypumpStatusHighlightMessage()
displayPumpStatusHighlightMessage()
}

func pumpDeactivatedDidChange() {
displayPumpStatusHighlightMessage(true)
}
}

Expand Down

0 comments on commit 9654d70

Please sign in to comment.