Meshtastic-Apple/Meshtastic/Extensions/CoreData/NodeInfoEntityExtension.swift

59 lines
1.2 KiB
Swift
Raw Normal View History

//
// NodeInfoEntityExtension.swift
// Meshtastic
//
// Copyright(c) Garth Vander Houwen 9/3/23.
//
import Foundation
2024-01-16 08:55:23 -08:00
import CoreData
extension NodeInfoEntity {
convenience init(
context: NSManagedObjectContext,
num: Int
) {
self.init(context: context)
self.id = Int64(num)
self.num = Int64(num)
self.user = UserEntity(context: context, num: num)
}
var hasPositions: Bool {
return positions?.count ?? 0 > 0
}
var hasDeviceMetrics: Bool {
let deviceMetrics = telemetries?.filter { ($0 as AnyObject).metricsType == 0 }
return deviceMetrics?.count ?? 0 > 0
}
var hasEnvironmentMetrics: Bool {
let environmentMetrics = telemetries?.filter { ($0 as AnyObject).metricsType == 1 }
return environmentMetrics?.count ?? 0 > 0
}
var hasDetectionSensorMetrics: Bool {
return user?.sensorMessageList.count ?? 0 > 0
}
2023-12-22 08:25:59 -08:00
var hasTraceRoutes: Bool {
return traceRoutes?.count ?? 0 > 0
}
2024-02-25 21:40:25 -08:00
var hasPax: Bool {
return pax?.count ?? 0 > 0
}
2024-02-10 17:43:01 -08:00
var isStoreForwardRouter: Bool {
return storeForwardConfig?.isRouter ?? false
}
2023-09-07 23:38:53 -07:00
var isOnline: Bool {
let fifteenMinutesAgo = Calendar.current.date(byAdding: .minute, value: -15, to: Date())
if lastHeard?.compare(fifteenMinutesAgo!) == .orderedDescending {
return true
}
return false
}
2024-01-16 08:55:23 -08:00
}