TempTargetEndCondition.swift 713 B

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