Renames every type and identifier we built for the solar charge controller bridge from generic "Solar" naming to the product name VotronicSolarESP: VanAlignSolarProtocol -> VotronicSolarESPProtocol, SolarSession -> VotronicSolarESPSession, SolarState -> VotronicSolarESPState, plus the dependent properties, parameters, and user-facing discovery/empty-state strings. Purely a Swift-side rename - the underlying BLE service/characteristic UUIDs are untouched, so it has no effect on communicating with the actual firmware. DeviceRole.solar's case name, and DemoData's device instance variables, are left as-is since they describe the role/demo device rather than this specific integration code. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
49 lines
1.8 KiB
Swift
49 lines
1.8 KiB
Swift
import Foundation
|
|
|
|
/// Zustand des Solarladereglers.
|
|
struct VotronicSolarESPState: Equatable, Codable, Sendable {
|
|
var batteryVoltage: Double?
|
|
var pvVoltage: Double?
|
|
var pvCurrent: Double?
|
|
var pvPower: Double?
|
|
var controllerTemperature: Double?
|
|
|
|
var isBatteryCharging: Bool?
|
|
var isBatteryDischarging: Bool?
|
|
var isControllerActive: Bool?
|
|
var isCurrentLimited: Bool?
|
|
|
|
var hasReading: Bool {
|
|
batteryVoltage != nil || pvVoltage != nil || pvCurrent != nil || pvPower != nil
|
|
}
|
|
|
|
/// Kurzer Klartext, wie bei den übrigen Geräten als "Zustand" angezeigt.
|
|
var stateText: String? {
|
|
guard isControllerActive != nil else { return nil }
|
|
if isBatteryCharging == true { return "Lädt" }
|
|
if isControllerActive == true { return "Aktiv" }
|
|
return "Inaktiv"
|
|
}
|
|
|
|
func snapshot(deviceID: UUID, rssi: Int?) -> DeviceSnapshot {
|
|
var snapshot = DeviceSnapshot(deviceID: deviceID, timestamp: Date(), rssi: rssi)
|
|
snapshot.metrics = [
|
|
Metric("pv_power", "Solarleistung", pvPower, unit: "W", precision: 0, primary: true),
|
|
Metric("pv_voltage", "PV-Spannung", pvVoltage, unit: "V", precision: 1),
|
|
Metric("pv_current", "PV-Strom", pvCurrent, unit: "A", precision: 1),
|
|
Metric("battery_voltage", "Batteriespannung", batteryVoltage, unit: "V", precision: 2),
|
|
]
|
|
if let controllerTemperature {
|
|
snapshot.metrics.append(
|
|
Metric("controller_temperature", "Reglertemperatur", controllerTemperature,
|
|
unit: "°C", precision: 0)
|
|
)
|
|
}
|
|
snapshot.state = stateText
|
|
if isCurrentLimited == true {
|
|
snapshot.offReasons = ["PV-Strombegrenzung aktiv"]
|
|
}
|
|
return snapshot
|
|
}
|
|
}
|