Skip to content

Commit

Permalink
fix: adjusted chart value in the Sensors popup to the local temperatu…
Browse files Browse the repository at this point in the history
…re (C/F) (#1730)
  • Loading branch information
exelban committed Dec 19, 2023
1 parent dca3c03 commit 709f7bf
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Modules/Sensors/popup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
122 changes: 62 additions & 60 deletions Modules/Sensors/values.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 709f7bf

Please sign in to comment.