Allow deletion of measurements
This commit is contained in:
@@ -6,6 +6,13 @@ enum DeviceInfoError: Error {
|
||||
|
||||
extension Data {
|
||||
|
||||
mutating func getByte() throws -> UInt8 {
|
||||
guard count >= 1 else {
|
||||
throw DeviceInfoError.missingData
|
||||
}
|
||||
return removeFirst()
|
||||
}
|
||||
|
||||
mutating func decodeUInt16() throws -> UInt16 {
|
||||
guard count >= 2 else {
|
||||
throw DeviceInfoError.missingData
|
||||
@@ -29,15 +36,4 @@ extension Data {
|
||||
let byte3 = removeFirst()
|
||||
return (Int(byte3) << 24) | (Int(byte2) << 16) | (Int(byte1) << 8) | Int(byte0)
|
||||
}
|
||||
|
||||
mutating func decodeSensor() throws -> TemperatureSensor? {
|
||||
guard count >= 11 else {
|
||||
throw DeviceInfoError.missingData
|
||||
}
|
||||
let address = Array(self[startIndex..<startIndex+8])
|
||||
removeFirst(8)
|
||||
let temperatureByte = removeFirst()
|
||||
let time = try decodeUInt16()
|
||||
return .init(address: address, valueByte: temperatureByte, secondsAgo: time)
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,32 @@ extension Date {
|
||||
self.init(timeIntervalSince1970: TimeInterval(seconds))
|
||||
}
|
||||
|
||||
var shortTimePassedText: String {
|
||||
let secs = secondsToNow
|
||||
guard secs > 1 else {
|
||||
return "Now"
|
||||
}
|
||||
guard secs >= 60 else {
|
||||
return "\(secs) s ago"
|
||||
}
|
||||
let minutes = secs / 60
|
||||
guard minutes >= 60 else {
|
||||
return "\(minutes) min ago"
|
||||
}
|
||||
let hours = minutes / 60
|
||||
guard hours > 1 else {
|
||||
return "1 hour ago"
|
||||
}
|
||||
guard hours >= 60 else {
|
||||
return "\(hours) hours ago"
|
||||
}
|
||||
let days = hours / 24
|
||||
guard days > 1 else {
|
||||
return "1 day ago"
|
||||
}
|
||||
return "\(days) days ago"
|
||||
}
|
||||
|
||||
var timePassedText: String {
|
||||
let secs = secondsToNow
|
||||
guard secs > 1 else {
|
||||
|
Reference in New Issue
Block a user