feat: Working on async integrations.

This commit is contained in:
2024-11-08 17:14:22 -05:00
parent f40c4ef859
commit adc7fc1295
14 changed files with 289 additions and 303 deletions

View File

@@ -1,36 +1,38 @@
import CoreUnitTypes
// TODO: Remove
/// Represents the different modes that the controller can be in.
public enum Mode: Equatable {
/// Allows controller to run in humidify or dehumidify mode.
case auto
/// Only handle humidify mode.
case humidifyOnly(HumidifyMode)
/// Only handle dehumidify mode.
case dehumidifyOnly(DehumidifyMode)
/// Don't control humidify or dehumidify modes.
case off
/// Represents the control modes for the humidify control state.
public enum HumidifyMode: Equatable {
/// Control humidifying based off dew-point.
case dewPoint(Temperature)
/// Control humidifying based off relative humidity.
case relativeHumidity(RelativeHumidity)
}
/// Represents the control modes for the dehumidify control state.
public enum DehumidifyMode: Equatable {
/// Control dehumidifying based off dew-point.
case dewPoint(high: Temperature, low: Temperature)
/// Control humidifying based off relative humidity.
case relativeHumidity(high: RelativeHumidity, low: RelativeHumidity)
}

View File

@@ -1,6 +1,7 @@
import Foundation
import Psychrometrics
// TODO: Remove
// TODO: Make this a struct, then create a Store class that holds the state??
public final class State {
@@ -50,9 +51,9 @@ public final class State {
}
}
extension State.Sensors {
public extension State.Sensors {
public struct TemperatureHumiditySensor<Location>: Equatable {
struct TemperatureHumiditySensor<Location>: Equatable {
@TrackedChanges
public var temperature: Temperature?
@@ -97,8 +98,9 @@ extension State.Sensors {
}
// MARK: - Temperature / Humidity Sensor Location Namespaces
public enum MixedAir { }
public enum PostCoil { }
public enum Return { }
public enum Supply { }
enum MixedAir {}
enum PostCoil {}
enum Return {}
enum Supply {}
}

View File

@@ -75,6 +75,8 @@ public struct TemperatureAndHumiditySensor: Equatable, Hashable, Identifiable {
}
/// Check whether any of the sensor values have changed and need processed.
///
/// - Note: Setting a value will set to both the temperature and humidity properties.
public var needsProcessed: Bool {
get { $temperature.needsProcessed || $humidity.needsProcessed }
set {
@@ -85,9 +87,9 @@ public struct TemperatureAndHumiditySensor: Equatable, Hashable, Identifiable {
/// Represents the different locations of a temperature and humidity sensor, which can
/// be used to derive the topic to both listen and publish new values to.
public enum Location: String, Equatable, Hashable {
case mixedAir = "mixed-air"
case postCoil = "post-coil"
public enum Location: String, CaseIterable, Equatable, Hashable {
case mixedAir = "mixed_air"
case postCoil = "post_coil"
case `return`
case supply
}
@@ -95,23 +97,41 @@ public struct TemperatureAndHumiditySensor: Equatable, Hashable, Identifiable {
/// Represents the MQTT topics to listen for updated sensor values on.
public struct Topics: Equatable, Hashable {
/// The temperature topic of the sensor.
public let temperature: String
/// The dew-point temperature topic for the sensor.
public let dewPoint: String
/// The enthalpy topic for the sensor.
public let enthalpy: String
/// The humidity topic of the sensor.
public let humidity: String
/// The temperature topic of the sensor.
public let temperature: String
public init(
temperature: String,
humidity: String
dewPoint: String,
enthalpy: String,
humidity: String,
temperature: String
) {
self.temperature = temperature
self.dewPoint = dewPoint
self.enthalpy = enthalpy
self.humidity = humidity
self.temperature = temperature
}
init(location: TemperatureAndHumiditySensor.Location) {
self.temperature = "sensors/\(location.rawValue)/temperature"
self.humidity = "sensors/\(location.rawValue)/humidity"
public init(topicPrefix: String? = "frankensystem", location: TemperatureAndHumiditySensor.Location) {
var prefix = topicPrefix ?? ""
if prefix.reversed().starts(with: "/") {
prefix = "\(prefix.dropLast())"
}
self.init(
dewPoint: "\(prefix)/sensors/\(location.rawValue)_dew_point/state",
enthalpy: "\(prefix)/sensors/\(location.rawValue)_enthalpy/state",
humidity: "\(prefix)/sensors/\(location.rawValue)_humidity/state",
temperature: "\(prefix)/sensors/\(location.rawValue)_temperature/state"
)
}
}
}

View File

@@ -1,3 +1,5 @@
// TODO: Remove
/// A container for all the different MQTT topics that are needed by the application.
public struct Topics: Codable, Equatable {
/// The command topics the application can publish to.

View File

@@ -52,7 +52,7 @@ public struct TrackedChanges<Value> {
case needsProcessed
}
/// Check whether the value needs processed.
/// Whether the value needs processed.
public var needsProcessed: Bool {
get { tracking == .needsProcessed }
set {