Skip to content

Commit

Permalink
Minor modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Aug 13, 2024
1 parent eb451fb commit 7b78d79
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
2 changes: 0 additions & 2 deletions Sources/SpeziDevices/HealthMeasurements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ public final class HealthMeasurements: @unchecked Sendable {
) {
device[keyPath: keyPath].$weightMeasurement.onChange { @MainActor [weak self, weak device] measurement in
guard let self, let device, case .connected = device.state else {
// TODO: we now just assume connected for all devices?
return
}
let service = device[keyPath: keyPath]

Check warning on line 161 in Sources/SpeziDevices/HealthMeasurements.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS / Test using xcodebuild or run fastlane

capture of 'keyPath' with non-sendable type 'HealthMeasurements.WeightScaleKeyPath<Device>' (aka 'KeyPath<Device, WeightScaleService>') in a `@Sendable` closure

Check warning on line 161 in Sources/SpeziDevices/HealthMeasurements.swift

View workflow job for this annotation

GitHub Actions / Build and Test iOS / Test using xcodebuild or run fastlane

capture of 'keyPath' with non-sendable type 'HealthMeasurements.WeightScaleKeyPath<Device>' (aka 'KeyPath<Device, WeightScaleService>') in a `@Sendable` closure

Check warning on line 161 in Sources/SpeziDevices/HealthMeasurements.swift

View workflow job for this annotation

GitHub Actions / CodeQL / Test using xcodebuild or run fastlane

capture of 'keyPath' with non-sendable type 'HealthMeasurements.WeightScaleKeyPath<Device>' (aka 'KeyPath<Device, WeightScaleService>') in a `@Sendable` closure
Expand All @@ -180,7 +179,6 @@ public final class HealthMeasurements: @unchecked Sendable {
// make sure to not capture the device
device[keyPath: keyPath].$bloodPressureMeasurement.onChange { @MainActor [weak self, weak device] measurement in
guard let self, let device, case .connected = device.state else {
// TODO: we now just assume connected for all devices?
return
}
let service = device[keyPath: keyPath]

Check warning on line 184 in Sources/SpeziDevices/HealthMeasurements.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS / Test using xcodebuild or run fastlane

capture of 'keyPath' with non-sendable type 'HealthMeasurements.BloodPressureKeyPath<Device>' (aka 'KeyPath<Device, BloodPressureService>') in a `@Sendable` closure

Check warning on line 184 in Sources/SpeziDevices/HealthMeasurements.swift

View workflow job for this annotation

GitHub Actions / Build and Test iOS / Test using xcodebuild or run fastlane

capture of 'keyPath' with non-sendable type 'HealthMeasurements.BloodPressureKeyPath<Device>' (aka 'KeyPath<Device, BloodPressureService>') in a `@Sendable` closure

Check warning on line 184 in Sources/SpeziDevices/HealthMeasurements.swift

View workflow job for this annotation

GitHub Actions / CodeQL / Test using xcodebuild or run fastlane

capture of 'keyPath' with non-sendable type 'HealthMeasurements.BloodPressureKeyPath<Device>' (aka 'KeyPath<Device, BloodPressureService>') in a `@Sendable` closure
Expand Down
24 changes: 16 additions & 8 deletions Sources/SpeziOmron/Devices/OmronBloodPressureCuff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public final class OmronBloodPressureCuff: BluetoothDevice, Identifiable, OmronH
@Dependency(HealthMeasurements.self) private var measurements: HealthMeasurements?
@Dependency(PairedDevices.self) private var pairedDevices: PairedDevices?

@SpeziBluetooth private var didReceiveFirstTimeNotification = false

/// Initialize the device.
public required init() {}

Expand All @@ -76,11 +78,14 @@ public final class OmronBloodPressureCuff: BluetoothDevice, Identifiable, OmronH
}
}

private func handleStateChange(_ state: PeripheralState) async {
@SpeziBluetooth
private func handleStateChange(_ state: PeripheralState) {
logger.debug("\(Self.self) changed state to \(state).")
if case .connected = state,
case .transferMode = manufacturerData?.pairingMode {
time.synchronizeDeviceTime()
switch state {
case .connecting, .connected:
break
case .disconnected, .disconnecting:
didReceiveFirstTimeNotification = false
}
}

Expand All @@ -89,12 +94,15 @@ public final class OmronBloodPressureCuff: BluetoothDevice, Identifiable, OmronH
pairedDevices?.signalDevicePaired(self)
}

@MainActor
private func handleCurrentTimeChange(_ time: CurrentTime) {
@SpeziBluetooth
private func handleCurrentTimeChange(_ time: CurrentTime) async {
logger.debug("Received updated device time for \(self.label) is \(String(describing: time))")
let paired = pairedDevices?.signalDevicePaired(self)

if paired == true {
// for Omron we take that as a signal that device is paired
await pairedDevices?.signalDevicePaired(self)

if !didReceiveFirstTimeNotification {
didReceiveFirstTimeNotification = true
self.time.synchronizeDeviceTime()
}
}
Expand Down
13 changes: 8 additions & 5 deletions Sources/SpeziOmron/Devices/OmronWeightScale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class OmronWeightScale: BluetoothDevice, Identifiable, OmronHealthD
@Dependency(HealthMeasurements.self) private var measurements: HealthMeasurements?
@Dependency(PairedDevices.self) private var pairedDevices: PairedDevices?

private var didReceiveFirstTimeNotification = false
@MainActor private var didReceiveFirstTimeNotification = false

/// Initialize the device.
public required init() {}
Expand All @@ -63,7 +63,8 @@ public final class OmronWeightScale: BluetoothDevice, Identifiable, OmronHealthD
}
}

private func handleStateChange(_ state: PeripheralState) async {
@MainActor
private func handleStateChange(_ state: PeripheralState) {
logger.debug("\(Self.self) changed state to \(state).")
switch state {
case .connecting, .connected:
Expand All @@ -78,10 +79,12 @@ public final class OmronWeightScale: BluetoothDevice, Identifiable, OmronHealthD
// TODO: only update the first time, do we have that web page still open???

Check failure on line 79 in Sources/SpeziOmron/Devices/OmronWeightScale.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Todo Violation: TODOs should be resolved (only update the first time, do...) (todo)
logger.debug("Received updated device time for \(self.label): \(String(describing: time))")

// TODO: filter for notifications happening while being in disconnected state?
// TODO: pairing issue is still there

Check failure on line 82 in Sources/SpeziOmron/Devices/OmronWeightScale.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Todo Violation: TODOs should be resolved (pairing issue is still there) (todo)
// - if Bluetooth entry is removed: two notifications while one is always delivered instantly!
// - if already paired in Bluetooth menu, only one notification while still connecting!

// for Omron we take that as a signal that device is paired // TODO: does this work now for all weight scales?
let didPair = pairedDevices?.signalDevicePaired(self) == true // TODO: do we need to result still?
// for Omron we take that as a signal that device is paired
pairedDevices?.signalDevicePaired(self)

if !didReceiveFirstTimeNotification {
didReceiveFirstTimeNotification = true
Expand Down

0 comments on commit 7b78d79

Please sign in to comment.