Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task: Support C5 Firmware #2151 #2164

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public final class RuuviAnalyticsImpl: RuuviAnalytics {
case df4_tags(Int)
// Quantity of tags using data format 5
case df5_tags(Int)
// Quantity of tags using data format C5
case dfC5_tags(Int)
// Background scan enabled or not (true/false)
case backgroundScanEnabled(Bool)
// Background scan interval (seconds)
Expand Down Expand Up @@ -80,6 +82,8 @@ public final class RuuviAnalyticsImpl: RuuviAnalytics {
"use_df4"
case .df5_tags:
"use_df5"
case .dfC5_tags:
"use_dfC5"
case .backgroundScanEnabled:
"background_scan_enabled"
case .backgroundScanInterval:
Expand Down Expand Up @@ -201,6 +205,7 @@ public final class RuuviAnalyticsImpl: RuuviAnalytics {
let .df3_tags(count),
let .df4_tags(count),
let .df5_tags(count),
let .dfC5_tags(count),
let .alertTemperature(count),
let .alertHumidity(count),
let .alertPressure(count),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class CardsViewModel: NSObject {
var id: Observable<String?> = .init()
var luid: Observable<AnyLocalIdentifier?> = .init()
var mac: Observable<AnyMACIdentifier?> = .init()
var serviceUUID: Observable<String?> = .init()
var name: Observable<String?> = .init()
var source: Observable<RuuviTagSensorRecordSource?> = .init()
var temperature: Observable<Temperature?> = .init()
Expand Down Expand Up @@ -82,11 +83,12 @@ class CardsViewModel: NSObject {
if let macId = ruuviTag.macId?.any {
mac.value = macId
}
serviceUUID.value = ruuviTag.serviceUUID
name.value = ruuviTag.name
version.value = ruuviTag.version
isConnectable.value = ruuviTag.isConnectable
isChartAvailable.value = ruuviTag.isConnectable || ruuviTag.isCloud
isAlertAvailable.value = ruuviTag.isCloud || isConnected.value ?? false
isChartAvailable.value = ruuviTag.isConnectable || ruuviTag.isCloud || ruuviTag.serviceUUID != nil
isAlertAvailable.value = ruuviTag.isCloud || isConnected.value ?? false || ruuviTag.serviceUUID != nil
isCloud.value = ruuviTag.isCloud
isOwner.value = ruuviTag.isOwner
canShareTag.value =
Expand All @@ -111,7 +113,7 @@ class CardsViewModel: NSObject {
temperature: record.temperature,
voltage: record.voltage
)
isAlertAvailable.value = isCloud.value ?? false || isConnected.value ?? false
isAlertAvailable.value = isCloud.value ?? false || isConnected.value ?? false || serviceUUID.value != nil
}

func update(with ruuviTag: RuuviTag) {
Expand All @@ -122,8 +124,15 @@ class CardsViewModel: NSObject {
ruuviTag.isConnectable {
isChartAvailable.value = true
}
} else {
if let isChart = isChartAvailable.value,
!isChart,
ruuviTag.serviceUUID != nil {
isChartAvailable.value = true
}
}
isAlertAvailable.value = isCloud.value ?? false || ruuviTag.isConnected
isAlertAvailable.value = isCloud.value ?? false ||
ruuviTag.isConnected || ruuviTag.serviceUUID != nil
temperature.value = ruuviTag.temperature
humidity.value = ruuviTag.humidity
pressure.value = ruuviTag.pressure
Expand All @@ -132,6 +141,7 @@ class CardsViewModel: NSObject {
if let macId = ruuviTag.mac?.mac.any {
mac.value = macId
}
serviceUUID.value = ruuviTag.serviceUUID
date.value = Date()
movementCounter.value = ruuviTag.movementCounter
source.value = ruuviTag.source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ extension CardsLargeImageCell {
switch source {
case .unknown:
dataSourceIconView.image = nil
case .advertisement:
case .advertisement, .bgAdvertisement:
dataSourceIconView.image = RuuviAsset.iconBluetooth.image
case .heartbeat, .log:
dataSourceIconView.image = RuuviAsset.iconBluetoothConnected.image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,10 @@ extension CardsViewController {
alertButton.isHidden = !isAlertAvailable
alertButtonHidden.isUserInteractionEnabled = isAlertAvailable
} else {
alertButton.isHidden = !viewModel.isConnected.value.bound
alertButtonHidden.isUserInteractionEnabled = viewModel.isConnected.value.bound
alertButton.isHidden =
!viewModel.isConnected.value.bound || viewModel.serviceUUID.value == nil
alertButtonHidden.isUserInteractionEnabled =
viewModel.isConnected.value.bound || viewModel.serviceUUID.value != nil
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ extension TagChartsViewController: TagChartsViewInput {
switch record.source {
case .unknown:
dataSourceIconView.image = nil
case .advertisement:
case .advertisement, .bgAdvertisement:
dataSourceIconView.image = RuuviAsset.iconBluetooth.image
case .heartbeat, .log:
dataSourceIconView.image = RuuviAsset.iconBluetoothConnected.image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ extension DashboardPresenter: RuuviNotifierObserver {
.filter { $0.luid.value?.value == uuid || $0.mac.value?.value == uuid }
.forEach { viewModel in
let isFireable = viewModel.isCloud.value ?? false ||
viewModel.isConnected.value ?? false
viewModel.isConnected.value ?? false ||
viewModel.serviceUUID.value != nil
switch alertType {
case .temperature:
let isTriggered = isTriggered && isFireable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class DashboardImageCell: DashboardCell {
switch source {
case .unknown:
dataSourceIconView.image = nil
case .advertisement:
case .advertisement, .bgAdvertisement:
dataSourceIconView.image = RuuviAsset.iconBluetooth.image
case .heartbeat, .log:
dataSourceIconView.image = RuuviAsset.iconBluetoothConnected.image
Expand Down Expand Up @@ -256,7 +256,9 @@ class DashboardImageCell: DashboardCell {
// swiftlint:disable:next function_body_length cyclomatic_complexity
override func restartAlertAnimation(for viewModel: CardsViewModel) {
// Alert
let alertVisible = viewModel.isCloud.value ?? false || viewModel.isConnected.value ?? false
let alertVisible = viewModel.isCloud.value ?? false ||
viewModel.isConnected.value ?? false ||
viewModel.serviceUUID.value != nil

let mutedTills = [
viewModel.temperatureAlertMutedTill.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class DashboardPlainCell: DashboardCell {
switch source {
case .unknown:
dataSourceIconView.image = nil
case .advertisement:
case .advertisement, .bgAdvertisement:
dataSourceIconView.image = RuuviAsset.iconBluetooth.image
case .heartbeat, .log:
dataSourceIconView.image = RuuviAsset.iconBluetoothConnected.image
Expand Down Expand Up @@ -227,7 +227,8 @@ class DashboardPlainCell: DashboardCell {
override func restartAlertAnimation(for viewModel: CardsViewModel) {
// Alert
let alertVisible = viewModel.isCloud.value ?? false ||
viewModel.isConnected.value ?? false
viewModel.isConnected.value ?? false ||
viewModel.serviceUUID.value != nil

let mutedTills = [
viewModel.temperatureAlertMutedTill.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,20 +512,23 @@ extension TagSettingsPresenter {
bind(viewModel.isConnected) { [weak isCloudAlertsAvailable] observer, isConnected in
let isCl = isCloudAlertsAvailable?.value ?? false
let isCo = isConnected ?? false
observer.viewModel.isAlertsEnabled.value = isCl || isCo
observer.viewModel.isAlertsEnabled.value = isCl || isCo || observer.ruuviTag.serviceUUID != nil
}

let isConnected = viewModel.isConnected
bind(viewModel.isCloudAlertsAvailable) { [weak isConnected] observer, isCloudAlertsAvailable in
let isCl = isCloudAlertsAvailable ?? false
let isCo = isConnected?.value ?? false
observer.viewModel.isAlertsEnabled.value = isCl || isCo
observer.viewModel.isAlertsEnabled.value = isCl || isCo || observer.ruuviTag.serviceUUID != nil
self.processAlerts()
}
}

/// Sets the view model properties related to the associated RuuviTag
// Sets the view model properties related to the associated RuuviTag
// swiftlint:disable:next function_body_length
private func syncTag() {
viewModel.serviceUUID.value = ruuviTag.serviceUUID

ruuviSensorPropertiesService.getImage(for: ruuviTag)
.on(success: { [weak self] image in
self?.viewModel.background.value = image
Expand Down Expand Up @@ -895,13 +898,13 @@ extension TagSettingsPresenter {
return
}
advertisementToken = foreground.observe(self, uuid: luid.value, closure: { [weak self] _, device in
if let tag = device.ruuvi?.tag {
if let tag = device.ruuvi?.tag, tag.luid?.value == luid.value {
self?.handleMeasurementPoint(tag: tag, luid: luid, source: .advertisement)
}
})

heartbeatToken = background.observe(self, uuid: luid.value, closure: { [weak self] _, device in
if let tag = device.ruuvi?.tag {
if let tag = device.ruuvi?.tag, tag.luid?.value == luid.value {
self?.handleMeasurementPoint(tag: tag, luid: luid, source: .heartbeat)
}
})
Expand Down Expand Up @@ -933,6 +936,7 @@ extension TagSettingsPresenter {
}
}

// swiftlint:disable:next function_body_length
private func sync(
device: RuuviTag,
luid _: LocalIdentifier,
Expand All @@ -944,6 +948,7 @@ extension TagSettingsPresenter {
source: source,
macId: device.mac?.mac,
rssi: device.rssi,
version: device.version,
temperature: device.temperature,
humidity: device.humidity,
pressure: device.pressure,
Expand Down Expand Up @@ -1332,7 +1337,9 @@ extension TagSettingsPresenter: RuuviNotifierObserver {
for uuid: String
) {
if ruuviTag.luid?.value == uuid || ruuviTag.macId?.value == uuid {
let isFireable = ruuviTag.isCloud || viewModel.isConnected.value ?? false
let isFireable = ruuviTag.isCloud ||
viewModel.isConnected.value ?? false ||
viewModel.serviceUUID.value != nil
switch alertType {
case .temperature:
let isTriggered = isTriggered && isFireable && (viewModel.isAlertsEnabled.value ?? false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ struct TagSettingsViewModel {
let name: Observable<String?> = .init()
let uuid: Observable<String?> = .init()
let mac: Observable<String?> = .init()
var serviceUUID: Observable<String?> = .init()
let rssi: Observable<Int?> = .init()
let humidity: Observable<Humidity?> = .init()
let temperature: Observable<Temperature?> = .init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,8 @@ extension TagSettingsViewController {

private func alertsAvailable() -> Bool {
(viewModel?.isCloudAlertsAvailable.value ?? false ||
viewModel?.isConnected.value ?? false)
viewModel?.isConnected.value ?? false ||
viewModel?.serviceUUID.value != nil)
}

private func reloadAlertSectionHeaders() {
Expand Down Expand Up @@ -3038,8 +3039,9 @@ extension TagSettingsViewController {

// Data format
if let moreInfoDataFormatCell {
moreInfoDataFormatCell.bind(viewModel.version) { cell, version in
cell.configure(value: version.stringValue)
moreInfoDataFormatCell.bind(viewModel.version) { [weak self] cell, version in
guard let sSelf = self else { return }
cell.configure(value: sSelf.formattedVersion(value: version))
}
}

Expand Down Expand Up @@ -3170,7 +3172,7 @@ extension TagSettingsViewController {
createdCell: { [weak self] in
self?.moreInfoDataFormatCell?.configure(
title: RuuviLocalization.TagSettings.DataFormatTitleLabel.text,
value: self?.viewModel?.version.value?.stringValue
value: self?.formattedVersion(value: self?.viewModel?.version.value)
)
self?.moreInfoDataFormatCell?.selectionStyle = .none
return self?.moreInfoDataFormatCell ?? UITableViewCell()
Expand Down Expand Up @@ -3319,7 +3321,7 @@ extension TagSettingsViewController {
if let source {
var sourceString = emptyString
switch source {
case .advertisement:
case .advertisement, .bgAdvertisement:
sourceString = RuuviLocalization.TagSettings.DataSource.Advertisement.title
case .heartbeat:
sourceString = RuuviLocalization.TagSettings.DataSource.Heartbeat.title
Expand Down Expand Up @@ -3370,6 +3372,14 @@ extension TagSettingsViewController {
RuuviLocalization.na
}
}

private func formattedVersion(value: Int?) -> String {
if value == 197 {
return "C5"
} else {
return value.stringValue
}
}
}

// MARK: - FIRMWARE SECTION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extension RuuviTagSensorRecordStruct {
source: .ruuviNetwork,
macId: nil,
rssi: nil,
version: 5,
temperature: Temperature(69.50),
humidity: nil,
pressure: nil,
Expand Down
2 changes: 1 addition & 1 deletion Modules/RuuviDiscover/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let package = Package(
.package(path: "../../Packages/RuuviService"),
.package(path: "../../Common/RuuviPresenters"),
.package(path: "../../Common/RuuviLocalization"),
.package(url: "https://github.com/ruuvi/BTKit", .upToNextMinor(from: "0.4.3")),
.package(url: "https://github.com/ruuvi/BTKit", branch: "master"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion Packages/RuuviCloud/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/kean/Future", .exact("1.3.0")),
.package(url: "https://github.com/ruuvi/BTKit", .upToNextMinor(from: "0.4.3")),
.package(url: "https://github.com/ruuvi/BTKit", branch: "master"),
.package(path: "../RuuviOntology"),
.package(path: "../RuuviUser"),
.package(path: "../RuuviPool"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,8 @@ extension RuuviCloudApiSensor: CloudSensor {
public var id: String {
sensorId
}

public var serviceUUID: String? {
nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ public final class RuuviCloudPure: RuuviCloud {
RuuviCloudSensorDense(
sensor: CloudSensorStruct(
id: sensor.sensor,
serviceUUID: nil,
name: sensor.name,
isClaimed: true,
isOwner: sensor.owner == self?.user.email,
Expand Down Expand Up @@ -1326,6 +1327,7 @@ public final class RuuviCloudPure: RuuviCloud {
source: .ruuviNetwork,
macId: macId,
rssi: rssi,
version: tag.version,
temperature: tag.temperature,
humidity: tag.humidity,
pressure: tag.pressure,
Expand Down Expand Up @@ -1365,6 +1367,7 @@ public final class RuuviCloudPure: RuuviCloud {
source: .ruuviNetwork,
macId: macId,
rssi: record.rssi,
version: tag.version,
temperature: tag.temperature,
humidity: tag.humidity,
pressure: tag.pressure,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,38 @@ extension SQLiteGRDBDatabase {
migrator.registerMigration("Create RuuviCloudSensorSubscription table") { db in
try RuuviCloudSensorSubscriptionSQLite.createTable(in: db)
}
// v14
migrator.registerMigration("Create RuuviTagSQLite serviceUUID column") { db in
guard try db.columns(in: RuuviTagSQLite.databaseTableName)
.contains(where: { $0.name == RuuviTagSQLite.serviceUUIDColumn.name }) == false
else {
return
}
try db.alter(table: RuuviTagSQLite.databaseTableName, body: { t in
t.add(column: RuuviTagSQLite.serviceUUIDColumn.name, .text)
})
}
// v15
migrator.registerMigration("Create RuuviTagDataSQLite version column") { db in
guard try db.columns(in: RuuviTagDataSQLite.databaseTableName)
.contains(where: { $0.name == RuuviTagDataSQLite.versionColumn.name }) == false
else {
return
}
try db.alter(table: RuuviTagDataSQLite.databaseTableName, body: { t in
t.add(column: RuuviTagDataSQLite.versionColumn.name, .integer)
})
}
migrator.registerMigration("Create RuuviTagLatestDataSQLite version column") { db in
guard try db.columns(in: RuuviTagLatestDataSQLite.databaseTableName)
.contains(where: { $0.name == RuuviTagLatestDataSQLite.versionColumn.name }) == false
else {
return
}
try db.alter(table: RuuviTagLatestDataSQLite.databaseTableName, body: { t in
t.add(column: RuuviTagLatestDataSQLite.versionColumn.name, .integer)
})
}

try migrator.migrate(dbPool)
}
Expand Down
Loading
Loading