Skip to content

Commit

Permalink
VIT-8034: Add EightSleep iOS app to sleep data source allowlist
Browse files Browse the repository at this point in the history
  • Loading branch information
andersio committed Dec 19, 2024
1 parent 26c4a82 commit c8857f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Sources/VitalHealthKit/HealthKit/HealthKitReads.swift
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ func handleSleep(

/// The goal of this filter is to remove sleep data generated by 3rd party apps that only do analyses.
/// Apps like Pillow and SleepWatch are great, but we are only interested in data generated by devices (e.g. Apple Watch, Oura)
let admittedSamples = filter(samples: payload.sample, by: DataSource.allCases)
let admittedSamples = filter(samples: payload.sample, by: SleepDataSource.allCases)

/// Group the sleeps by source bundle before we try to stitch them into sleep sessions.
let samplesBySourceBundle = Dictionary(
Expand Down Expand Up @@ -1866,7 +1866,7 @@ private func filterForWatch(samples: [HKSample]) -> [HKSample] {
return samples.filter { sample in
let bundleIdentifier = sample.sourceRevision.source.bundleIdentifier

if bundleIdentifier.contains(DataSource.appleHealthKit.rawValue) {
if bundleIdentifier.contains(SleepDataSource.appleHealthKit.rawValue) {

/// Data generated from a watch can look like this `Optional("Watch4,4")`
if let productType = sample.sourceRevision.productType {
Expand All @@ -1884,7 +1884,7 @@ private func filterForWatch(samples: [HKSample]) -> [HKSample] {
}
}

private func filter(samples: some Sequence<HKSample>, by dataSources: [DataSource]) -> [HKSample] {
private func filter(samples: some Sequence<HKSample>, by dataSources: [SleepDataSource]) -> [HKSample] {

return samples.filter { sample in
let identifier = sample.sourceRevision.source.bundleIdentifier
Expand Down
3 changes: 2 additions & 1 deletion Sources/VitalHealthKit/HealthKit/Models/DataSource.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
enum DataSource: String, CaseIterable {
enum SleepDataSource: String, CaseIterable {
case appleHealthKit = "com.apple.health"
case oura = "com.ouraring.oura"
case withings = "com.withings.wiScaleNG"
Expand All @@ -12,4 +12,5 @@ enum DataSource: String, CaseIterable {
case muse = "com.interaxon.muse"
case biostrap = "com.biostrap.Biostrap"
case cardiomood = "com.corsanohealth.cardiomood"
case eightsleep = "com.eightsleep.Eight"
}

0 comments on commit c8857f0

Please sign in to comment.