TempTargetEndCondition.swift 676 B

12345678910111213141516171819202122
  1. // LoopFollow
  2. // TempTargetEndCondition.swift
  3. import Foundation
  4. /// Fires once when the active temp target ends.
  5. struct TempTargetEndCondition: AlarmCondition {
  6. static let type: AlarmType = .tempTargetEnd
  7. init() {}
  8. func evaluate(alarm _: Alarm, data: AlarmData, now: Date) -> Bool {
  9. guard let endTS = data.latestTempTargetEnd, endTS > 0 else { return false }
  10. guard now.timeIntervalSince1970 - endTS <= 15 * 60 else { return false }
  11. let last = Storage.shared.lastTempTargetEndNotified.value ?? 0
  12. guard endTS > last else { return false }
  13. Storage.shared.lastTempTargetEndNotified.value = endTS
  14. return true
  15. }
  16. }