fix: adjusted chart value in the Sensors popup to the local temperature (C/F) (#1730)

This commit is contained in:
Serhiy Mytrovtsiy
2023-12-19 14:09:27 +01:00
parent dca3c03acd
commit 709f7bfa32
2 changed files with 63 additions and 61 deletions

View File

@@ -330,7 +330,7 @@ internal class SensorView: NSStackView {
}
public func addHistoryPoint(_ sensor: Sensor_p) {
self.chartView.update(sensor.value)
self.chartView.update(sensor.localValue)
}
private func open() {

View File

@@ -44,6 +44,7 @@ public protocol Sensor_p {
var isComputed: Bool { get }
var average: Bool { get }
var localValue: Double { get }
var unit: String { get }
var formattedValue: String { get }
var formattedMiniValue: String { get }
@@ -136,75 +137,73 @@ public struct Sensor: Sensor_p, Codable {
public var average: Bool = false
public var unit: String {
get {
switch self.type {
case .temperature:
return UnitTemperature.current.symbol
case .voltage:
return "V"
case .power:
return "W"
case .energy:
return "Wh"
case .current:
return "A"
case .fan:
return "RPM"
}
switch self.type {
case .temperature:
return UnitTemperature.current.symbol
case .voltage:
return "V"
case .power:
return "W"
case .energy:
return "Wh"
case .current:
return "A"
case .fan:
return "RPM"
}
}
public var formattedValue: String {
get {
switch self.type {
case .temperature:
return temperature(value)
case .voltage:
let val = value >= 100 ? "\(Int(value))" : String(format: "%.3f", value)
return "\(val)\(unit)"
case .power, .energy:
let val = value >= 100 ? "\(Int(value))" : String(format: "%.2f", value)
return "\(val)\(unit)"
case .current:
let val = value >= 100 ? "\(Int(value))" : String(format: "%.2f", value)
return "\(val)\(unit)"
case .fan:
return "\(Int(value)) \(unit)"
}
switch self.type {
case .temperature:
return temperature(value)
case .voltage:
let val = value >= 100 ? "\(Int(value))" : String(format: "%.3f", value)
return "\(val)\(unit)"
case .power, .energy:
let val = value >= 100 ? "\(Int(value))" : String(format: "%.2f", value)
return "\(val)\(unit)"
case .current:
let val = value >= 100 ? "\(Int(value))" : String(format: "%.2f", value)
return "\(val)\(unit)"
case .fan:
return "\(Int(value)) \(unit)"
}
}
public var formattedPopupValue: String {
get {
switch self.type {
case .temperature:
return temperature(value, fractionDigits: 1)
case .voltage:
let val = value >= 100 ? "\(Int(value))" : String(format: "%.3f", value)
return "\(val)\(unit)"
case .power, .energy:
let val = value >= 100 ? "\(Int(value))" : String(format: "%.2f", value)
return "\(val)\(unit)"
case .current:
let val = value >= 100 ? "\(Int(value))" : String(format: "%.2f", value)
return "\(val)\(unit)"
case .fan:
return "\(Int(value)) \(unit)"
}
switch self.type {
case .temperature:
return temperature(value, fractionDigits: 1)
case .voltage:
let val = value >= 100 ? "\(Int(value))" : String(format: "%.3f", value)
return "\(val)\(unit)"
case .power, .energy:
let val = value >= 100 ? "\(Int(value))" : String(format: "%.2f", value)
return "\(val)\(unit)"
case .current:
let val = value >= 100 ? "\(Int(value))" : String(format: "%.2f", value)
return "\(val)\(unit)"
case .fan:
return "\(Int(value)) \(unit)"
}
}
public var formattedMiniValue: String {
get {
switch self.type {
case .temperature:
return temperature(value).replacingOccurrences(of: "C", with: "").replacingOccurrences(of: "F", with: "")
case .voltage, .power, .energy, .current:
let val = value >= 9.95 ? "\(Int(round(value)))" : String(format: "%.1f", value)
return "\(val)\(unit)"
case .fan:
return "\(Int(value))"
}
switch self.type {
case .temperature:
return temperature(value).replacingOccurrences(of: "C", with: "").replacingOccurrences(of: "F", with: "")
case .voltage, .power, .energy, .current:
let val = value >= 9.95 ? "\(Int(round(value)))" : String(format: "%.1f", value)
return "\(val)\(unit)"
case .fan:
return "\(Int(value))"
}
}
public var localValue: Double {
if self.type == .temperature {
return Double(self.formattedMiniValue.digits) ?? self.value
}
return self.value
}
public var state: Bool {
Store.shared.bool(key: "sensor_\(self.key)", defaultValue: false)
@@ -254,13 +253,16 @@ public struct Fan: Sensor_p, Codable {
public var unit: String = "RPM"
public var formattedValue: String {
"\(Int(value)) RPM"
"\(Int(self.value)) RPM"
}
public var formattedMiniValue: String {
"\(Int(value))"
"\(Int(self.value))"
}
public var formattedPopupValue: String {
"\(Int(value)) RPM"
"\(Int(self.value)) RPM"
}
public var localValue: Double {
return self.value
}
public var state: Bool {