Skip to content

Commit

Permalink
task: Update DB and DataModel for E0_F0 fw #2176 (#2191)
Browse files Browse the repository at this point in the history
  • Loading branch information
priyonto authored Nov 23, 2024
1 parent 2565a33 commit 48765ff
Show file tree
Hide file tree
Showing 13 changed files with 514 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ class CardsViewModel: NSObject {
var rssi: Observable<Int?> = .init()
var version: Observable<Int?> = .init()
var voltage: Observable<Voltage?> = .init()
var pm1: Observable<Double?> = .init()
var pm2_5: Observable<Double?> = .init()
var pm4: Observable<Double?> = .init()
var pm10: Observable<Double?> = .init()
var co2: Observable<Double?> = .init()
var voc: Observable<Double?> = .init()
var nox: Observable<Double?> = .init()
var luminance: Observable<Double?> = .init()
var dbaAvg: Observable<Double?> = .init()
var dbaPeak: Observable<Double?> = .init()
let batteryNeedsReplacement: Observable<Bool?> = .init()
var background: Observable<UIImage?> = .init()
var date: Observable<Date?> = .init()
Expand Down Expand Up @@ -106,6 +116,16 @@ class CardsViewModel: NSObject {
date.value = record.date
rssi.value = record.rssi
movementCounter.value = record.movementCounter
pm1.value = record.pm1
pm2_5.value = record.pm2_5
pm4.value = record.pm4
pm10.value = record.pm10
co2.value = record.co2
voc.value = record.voc
nox.value = record.nox
luminance.value = record.luminance
dbaAvg.value = record.dbaAvg
dbaPeak.value = record.dbaPeak
source.value = record.source
batteryNeedsReplacement.value =
batteryStatusProvider
Expand Down Expand Up @@ -144,6 +164,16 @@ class CardsViewModel: NSObject {
serviceUUID.value = ruuviTag.serviceUUID
date.value = Date()
movementCounter.value = ruuviTag.movementCounter
pm1.value = ruuviTag.pm1
pm2_5.value = ruuviTag.pm2_5
pm4.value = ruuviTag.pm4
pm10.value = ruuviTag.pm10
co2.value = ruuviTag.co2
voc.value = ruuviTag.voc
nox.value = ruuviTag.nox
luminance.value = ruuviTag.luminance
dbaAvg.value = ruuviTag.dbaAvg
dbaPeak.value = ruuviTag.dbaPeak
source.value = ruuviTag.source
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,16 @@ extension TagSettingsPresenter {
movementCounter: device.movementCounter,
measurementSequenceNumber: device.measurementSequenceNumber,
txPower: device.txPower,
pm1: device.pm1,
pm2_5: device.pm2_5,
pm4: device.pm4,
pm10: device.pm10,
co2: device.co2,
voc: device.voc,
nox: device.nox,
luminance: device.luminance,
dbaAvg: device.dbaAvg,
dbaPeak: device.dbaPeak,
temperatureOffset: sensorSettings?.temperatureOffset ?? 0.0,
humidityOffset: sensorSettings?.humidityOffset ?? 0.0,
pressureOffset: sensorSettings?.pressureOffset ?? 0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ struct TagSettingsViewModel {
let movementCounter: Observable<Int?> = .init()
let measurementSequenceNumber: Observable<Int?> = .init()
let txPower: Observable<Int?> = .init()
let pm1: Observable<Double?> = .init()
let pm2_5: Observable<Double?> = .init()
let pm4: Observable<Double?> = .init()
let pm10: Observable<Double?> = .init()
let co2: Observable<Double?> = .init()
let voc: Observable<Double?> = .init()
let nox: Observable<Double?> = .init()
let luminance: Observable<Double?> = .init()
let dbaAvg: Observable<Double?> = .init()
let dbaPeak: Observable<Double?> = .init()
let isConnectable: Observable<Bool?> = .init()
let isConnected: Observable<Bool?> = .init()
let isNetworkConnected: Observable<Bool?> = .init()
Expand Down Expand Up @@ -116,6 +126,16 @@ struct TagSettingsViewModel {
movementCounter.value = record.movementCounter
measurementSequenceNumber.value = record.measurementSequenceNumber
txPower.value = record.txPower
pm1.value = record.pm1
pm2_5.value = record.pm2_5
pm4.value = record.pm4
pm10.value = record.pm10
co2.value = record.co2
voc.value = record.voc
nox.value = record.nox
luminance.value = record.luminance
dbaAvg.value = record.dbaAvg
dbaPeak.value = record.dbaPeak
source.value = record.source
let batteryStatusProvider = RuuviTagBatteryStatusProvider()
batteryNeedsReplacement.value = batteryStatusProvider.batteryNeedsReplacement(
Expand Down Expand Up @@ -145,6 +165,7 @@ struct TagSettingsViewModel {

isSignalAlertOn.value = false
signalLowerBound.value = -105
signalLowerBound.value = -105
signalUpperBound.value = 0
signalAlertDescription.value = nil

Expand All @@ -155,5 +176,16 @@ struct TagSettingsViewModel {
movementAlertDescription.value = nil

latestMeasurement.value = nil

pm1.value = nil
pm2_5.value = nil
pm4.value = nil
pm10.value = nil
co2.value = nil
voc.value = nil
nox.value = nil
luminance.value = nil
dbaAvg.value = nil
dbaPeak.value = nil
}
}
10 changes: 10 additions & 0 deletions Apps/RuuviStation/Widgets/Sources/Model/Model+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ extension RuuviTagSensorRecordStruct {
movementCounter: nil,
measurementSequenceNumber: nil,
txPower: nil,
pm1: nil,
pm2_5: nil,
pm4: nil,
pm10: nil,
co2: nil,
voc: nil,
nox: nil,
luminance: nil,
dbaAvg: nil,
dbaPeak: nil,
temperatureOffset: 0,
humidityOffset: 0,
pressureOffset: 0
Expand Down
20 changes: 20 additions & 0 deletions Packages/RuuviCloud/Sources/RuuviCloudPure/RuuviCloudPure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,16 @@ public final class RuuviCloudPure: RuuviCloud {
movementCounter: tag.movementCounter,
measurementSequenceNumber: tag.measurementSequenceNumber,
txPower: tag.txPower,
pm1: tag.pm1,
pm2_5: tag.pm2_5,
pm4: tag.pm4,
pm10: tag.pm10,
co2: tag.co2,
voc: tag.voc,
nox: tag.nox,
luminance: tag.luminance,
dbaAvg: tag.dbaAvg,
dbaPeak: tag.dbaPeak,
temperatureOffset: 0.0,
humidityOffset: 0.0,
pressureOffset: 0.0
Expand Down Expand Up @@ -1376,6 +1386,16 @@ public final class RuuviCloudPure: RuuviCloud {
movementCounter: tag.movementCounter,
measurementSequenceNumber: tag.measurementSequenceNumber,
txPower: tag.txPower,
pm1: tag.pm1,
pm2_5: tag.pm2_5,
pm4: tag.pm4,
pm10: tag.pm10,
co2: tag.co2,
voc: tag.voc,
nox: tag.nox,
luminance: tag.luminance,
dbaAvg: tag.dbaAvg,
dbaPeak: tag.dbaPeak,
temperatureOffset: 0.0,
humidityOffset: 0.0,
pressureOffset: 0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,43 @@ extension SQLiteGRDBDatabase {
})
}

// v16
migrator.registerMigration("Add new columns to RuuviTagDataSQLite and RuuviTagLatestDataSQLite") { db in
// For RuuviTagDataSQLite
if try db.columns(in: RuuviTagDataSQLite.databaseTableName)
.contains(where: { $0.name == RuuviTagDataSQLite.pm1Column.name }) == false {
try db.alter(table: RuuviTagDataSQLite.databaseTableName, body: { t in
t.add(column: RuuviTagDataSQLite.pm1Column.name, .double)
t.add(column: RuuviTagDataSQLite.pm2_5Column.name, .double)
t.add(column: RuuviTagDataSQLite.pm4Column.name, .double)
t.add(column: RuuviTagDataSQLite.pm10Column.name, .double)
t.add(column: RuuviTagDataSQLite.co2Column.name, .double)
t.add(column: RuuviTagDataSQLite.vocColumn.name, .double)
t.add(column: RuuviTagDataSQLite.noxColumn.name, .double)
t.add(column: RuuviTagDataSQLite.luminanceColumn.name, .double)
t.add(column: RuuviTagDataSQLite.dbaAvgColumn.name, .double)
t.add(column: RuuviTagDataSQLite.dbaPeakColumn.name, .double)
})
}

// For RuuviTagLatestDataSQLite
if try db.columns(in: RuuviTagLatestDataSQLite.databaseTableName)
.contains(where: { $0.name == RuuviTagLatestDataSQLite.pm1Column.name }) == false {
try db.alter(table: RuuviTagLatestDataSQLite.databaseTableName, body: { t in
t.add(column: RuuviTagLatestDataSQLite.pm1Column.name, .double)
t.add(column: RuuviTagLatestDataSQLite.pm2_5Column.name, .double)
t.add(column: RuuviTagLatestDataSQLite.pm4Column.name, .double)
t.add(column: RuuviTagLatestDataSQLite.pm10Column.name, .double)
t.add(column: RuuviTagLatestDataSQLite.co2Column.name, .double)
t.add(column: RuuviTagLatestDataSQLite.vocColumn.name, .double)
t.add(column: RuuviTagLatestDataSQLite.noxColumn.name, .double)
t.add(column: RuuviTagLatestDataSQLite.luminanceColumn.name, .double)
t.add(column: RuuviTagLatestDataSQLite.dbaAvgColumn.name, .double)
t.add(column: RuuviTagLatestDataSQLite.dbaPeakColumn.name, .double)
})
}
}

try migrator.migrate(dbPool)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,46 @@ extension RuuviTag: RuuviTagSensorRecord {
return Voltage(value: voltage, unit: .volts)
}

public var pm1: Double? {
pMatter1_0
}

public var pm2_5: Double? {
pMatter2_5
}

public var pm4: Double? {
pMatter4
}

public var pm10: Double? {
pMatter10
}

public var co2: Double? {
carbonDioxide
}

public var voc: Double? {
volatileOrganicCompound
}

public var nox: Double? {
nitrogenOxide
}

public var luminance: Double? {
luminanceValue
}

public var dbaAvg: Double? {
decibelAverage
}

public var dbaPeak: Double? {
decibelPeak
}

public var temperatureOffset: Double { 0.0 }
public var humidityOffset: Double { 0.0 }
public var pressureOffset: Double { 0.0 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ extension RuuviTagEnvLogFull {
movementCounter: nil,
measurementSequenceNumber: nil,
txPower: nil,
// TODO: Add support for log (E0_F0 FW)
pm1: nil,
pm2_5: nil,
pm4: nil,
pm10: nil,
co2: nil,
voc: nil,
nox: nil,
luminance: nil,
dbaAvg: nil,
dbaPeak: nil,
temperatureOffset: 0.0,
humidityOffset: 0.0,
pressureOffset: 0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,46 @@ extension AnyCloudSensorDense: RuuviTagSensorRecord {
record.txPower
}

public var pm1: Double? {
record.pm1
}

public var pm2_5: Double? {
record.pm2_5
}

public var pm4: Double? {
record.pm4
}

public var pm10: Double? {
record.pm10
}

public var co2: Double? {
record.co2
}

public var voc: Double? {
record.voc
}

public var nox: Double? {
record.nox
}

public var luminance: Double? {
record.luminance
}

public var dbaAvg: Double? {
record.dbaAvg
}

public var dbaPeak: Double? {
record.dbaPeak
}

public var temperatureOffset: Double {
record.temperatureOffset
}
Expand Down
Loading

0 comments on commit 48765ff

Please sign in to comment.