COBCondition.swift 661 B

123456789101112131415161718192021222324252627
  1. // LoopFollow
  2. // COBCondition.swift
  3. import Foundation
  4. struct COBCondition: AlarmCondition {
  5. static let type: AlarmType = .cob
  6. init() {}
  7. func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
  8. guard let threshold = alarm.threshold, threshold > 0 else { return false }
  9. guard let cob = data.COB, cob >= threshold else {
  10. Storage.shared.lastCOBNotified.value = nil
  11. return false
  12. }
  13. if let last = Storage.shared.lastCOBNotified.value,
  14. !(cob > last)
  15. {
  16. return false
  17. }
  18. Storage.shared.lastCOBNotified.value = cob
  19. return true
  20. }
  21. }