Allow deletion of measurements
This commit is contained in:
@@ -55,6 +55,10 @@ final class TemperatureDataTransfer {
|
||||
}
|
||||
|
||||
func add(data: Data, offset: Int, count: Int) {
|
||||
guard currentByteIndex == offset else {
|
||||
print("Discarding \(data.count) bytes at offset \(offset), expected \(currentByteIndex)")
|
||||
return
|
||||
}
|
||||
dataBuffer.append(data)
|
||||
currentByteIndex += data.count
|
||||
processBytes()
|
||||
|
@@ -28,7 +28,7 @@ struct TemperatureSensor {
|
||||
}
|
||||
|
||||
var updateText: String {
|
||||
date.timePassedText
|
||||
date.shortTimePassedText
|
||||
}
|
||||
|
||||
static func temperatureIcon(_ temp: Double?) -> SFSymbol {
|
||||
@@ -60,3 +60,17 @@ extension TemperatureSensor {
|
||||
self.date = Date().addingTimeInterval(-TimeInterval(secondsAgo))
|
||||
}
|
||||
}
|
||||
|
||||
extension Data {
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@@ -49,7 +49,7 @@ enum TemperatureValue {
|
||||
case .invalidMeasurement:
|
||||
return "Invalid"
|
||||
case .value(let value):
|
||||
return String(format:" %.1f°C", value)
|
||||
return String(format:"%.1f°C", value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user