Working on state and topics.
This commit is contained in:
@@ -3,26 +3,70 @@ import CoreUnitTypes
|
|||||||
|
|
||||||
public struct State: Equatable {
|
public struct State: Equatable {
|
||||||
|
|
||||||
@TrackedChanges
|
public var sensors: Sensors
|
||||||
public var temperature: Temperature?
|
|
||||||
|
|
||||||
@TrackedChanges
|
public init(sensors: Sensors = .init()) {
|
||||||
public var humidity: RelativeHumidity?
|
self.sensors = sensors
|
||||||
|
|
||||||
public init(
|
|
||||||
temperature: Temperature? = nil,
|
|
||||||
humidity: RelativeHumidity? = nil,
|
|
||||||
needsProcessed: Bool = false
|
|
||||||
) {
|
|
||||||
self._temperature = .init(wrappedValue: temperature, needsProcessed: needsProcessed)
|
|
||||||
self._humidity = .init(wrappedValue: humidity, needsProcessed: needsProcessed)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public var needsProcessed: Bool {
|
public struct Sensors: Equatable {
|
||||||
$temperature.needsProcessed || $humidity.needsProcessed
|
|
||||||
|
public var mixedSensor: TemperatureHumiditySensor<Mixed>
|
||||||
|
public var postCoilSensor: TemperatureHumiditySensor<PostCoil>
|
||||||
|
public var returnSensor: TemperatureHumiditySensor<Return>
|
||||||
|
public var supplySensor: TemperatureHumiditySensor<Supply>
|
||||||
|
|
||||||
|
public init(
|
||||||
|
mixedSensor: TemperatureHumiditySensor<Mixed> = .init(),
|
||||||
|
postCoilSensor: TemperatureHumiditySensor<PostCoil> = .init(),
|
||||||
|
returnSensor: TemperatureHumiditySensor<Return> = .init(),
|
||||||
|
supplySensor: TemperatureHumiditySensor<Supply> = .init()
|
||||||
|
) {
|
||||||
|
self.mixedSensor = mixedSensor
|
||||||
|
self.postCoilSensor = postCoilSensor
|
||||||
|
self.returnSensor = returnSensor
|
||||||
|
self.supplySensor = supplySensor
|
||||||
|
}
|
||||||
|
|
||||||
|
public var needsProcessed: Bool {
|
||||||
|
mixedSensor.needsProcessed
|
||||||
|
|| postCoilSensor.needsProcessed
|
||||||
|
|| returnSensor.needsProcessed
|
||||||
|
|| supplySensor.needsProcessed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension State.Sensors {
|
||||||
|
public struct TemperatureHumiditySensor<Location>: Equatable {
|
||||||
|
@TrackedChanges
|
||||||
|
public var temperature: Temperature?
|
||||||
|
|
||||||
|
@TrackedChanges
|
||||||
|
public var humidity: RelativeHumidity?
|
||||||
|
|
||||||
|
public var needsProcessed: Bool {
|
||||||
|
$temperature.needsProcessed || $humidity.needsProcessed
|
||||||
|
}
|
||||||
|
|
||||||
|
public init(
|
||||||
|
temperature: Temperature? = nil,
|
||||||
|
humidity: RelativeHumidity? = nil,
|
||||||
|
needsProcessed: Bool = false
|
||||||
|
) {
|
||||||
|
self._temperature = .init(wrappedValue: temperature, needsProcessed: needsProcessed)
|
||||||
|
self._humidity = .init(wrappedValue: humidity, needsProcessed: needsProcessed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Temperature / Humidity Sensor Locations
|
||||||
|
public enum Mixed { }
|
||||||
|
public enum PostCoil { }
|
||||||
|
public enum Return { }
|
||||||
|
public enum Supply { }
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Tracked Changes
|
||||||
@propertyWrapper
|
@propertyWrapper
|
||||||
public struct TrackedChanges<Value> {
|
public struct TrackedChanges<Value> {
|
||||||
|
|
||||||
|
|||||||
@@ -36,29 +36,72 @@ public struct Topics: Codable, Equatable {
|
|||||||
/// Represents the sensor topics.
|
/// Represents the sensor topics.
|
||||||
public struct Sensors: Codable, Equatable {
|
public struct Sensors: Codable, Equatable {
|
||||||
|
|
||||||
/// The temperature sensor topic.
|
public var mixedAirSensor: TemperatureAndHumiditySensor<State.Sensors.Mixed>
|
||||||
public var temperature: String
|
public var postCoilSensor: TemperatureAndHumiditySensor<State.Sensors.PostCoil>
|
||||||
|
public var returnSensor: TemperatureAndHumiditySensor<State.Sensors.Return>
|
||||||
|
public var supplySensor: TemperatureAndHumiditySensor<State.Sensors.Supply>
|
||||||
|
|
||||||
/// The humidity sensor topic.
|
// TODO: Fix defaults.
|
||||||
public var humidity: String
|
|
||||||
|
|
||||||
/// The dew point topic (we write / publish this data from the application).
|
|
||||||
public var dewPoint: String
|
|
||||||
|
|
||||||
/// Create a new sensor topic container.
|
|
||||||
///
|
|
||||||
/// - Parameters:
|
|
||||||
/// - temperature: The temperature sensor topic.
|
|
||||||
/// - humidity: The humidity sensor topic.
|
|
||||||
/// - dewPoint: The dew point sensor topic.
|
|
||||||
public init(
|
public init(
|
||||||
temperature: String = "sensors/temperature",
|
mixedAirSensor: TemperatureAndHumiditySensor<State.Sensors.Mixed> = .init(),
|
||||||
humidity: String = "sensors/humidity",
|
postCoilSensor: TemperatureAndHumiditySensor<State.Sensors.PostCoil> = .init(),
|
||||||
dewPoint: String = "sensors/dew_point"
|
returnSensor: TemperatureAndHumiditySensor<State.Sensors.Return> = .init(),
|
||||||
|
supplySensor: TemperatureAndHumiditySensor<State.Sensors.Supply> = .init()
|
||||||
) {
|
) {
|
||||||
self.temperature = temperature
|
self.mixedAirSensor = mixedAirSensor
|
||||||
self.humidity = humidity
|
self.postCoilSensor = postCoilSensor
|
||||||
self.dewPoint = dewPoint
|
self.returnSensor = returnSensor
|
||||||
|
self.supplySensor = supplySensor
|
||||||
|
}
|
||||||
|
|
||||||
|
// /// The temperature sensor topic.
|
||||||
|
// public var temperature: String
|
||||||
|
//
|
||||||
|
// /// The humidity sensor topic.
|
||||||
|
// public var humidity: String
|
||||||
|
//
|
||||||
|
// /// The dew point topic (we write / publish this data from the application).
|
||||||
|
// public var dewPoint: String
|
||||||
|
//
|
||||||
|
// /// Create a new sensor topic container.
|
||||||
|
// ///
|
||||||
|
// /// - Parameters:
|
||||||
|
// /// - temperature: The temperature sensor topic.
|
||||||
|
// /// - humidity: The humidity sensor topic.
|
||||||
|
// /// - dewPoint: The dew point sensor topic.
|
||||||
|
// public init(
|
||||||
|
// temperature: String = "sensors/temperature",
|
||||||
|
// humidity: String = "sensors/humidity",
|
||||||
|
// dewPoint: String = "sensors/dew_point"
|
||||||
|
// ) {
|
||||||
|
// self.temperature = temperature
|
||||||
|
// self.humidity = humidity
|
||||||
|
// self.dewPoint = dewPoint
|
||||||
|
// }
|
||||||
|
|
||||||
|
public struct TemperatureAndHumiditySensor<Location>: Codable, Equatable {
|
||||||
|
public var temperature: String
|
||||||
|
public var humidity: String
|
||||||
|
public var dewPoint: String
|
||||||
|
public var enthalpy: String
|
||||||
|
|
||||||
|
/// Create a new sensor topic container.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - temperature: The temperature sensor topic.
|
||||||
|
/// - humidity: The humidity sensor topic.
|
||||||
|
/// - dewPoint: The dew point sensor topic.
|
||||||
|
public init(
|
||||||
|
temperature: String = "sensors/temperature",
|
||||||
|
humidity: String = "sensors/humidity",
|
||||||
|
dewPoint: String = "sensors/dew_point",
|
||||||
|
enthalpy: String = "sensors/enthalpy"
|
||||||
|
) {
|
||||||
|
self.temperature = temperature
|
||||||
|
self.humidity = humidity
|
||||||
|
self.dewPoint = dewPoint
|
||||||
|
self.enthalpy = enthalpy
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ if environment.envVars.appEnv == .production {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let relay = Relay(topic: environment.topics.commands.relays.dehumidification1)
|
let relay = Relay(topic: environment.topics.commands.relays.dehumidification1)
|
||||||
let tempSensor = Sensor<Temperature>(topic: environment.topics.sensors.temperature)
|
let tempSensor = Sensor<Temperature>(topic: environment.topics.sensors.returnSensor.temperature)
|
||||||
let humiditySensor = Sensor<RelativeHumidity>(topic: environment.topics.sensors.humidity)
|
let humiditySensor = Sensor<RelativeHumidity>(topic: environment.topics.sensors.returnSensor.humidity)
|
||||||
|
|
||||||
defer {
|
defer {
|
||||||
logger.debug("Disconnecting")
|
logger.debug("Disconnecting")
|
||||||
@@ -51,7 +51,7 @@ while true {
|
|||||||
|
|
||||||
try environment.mqttClient.publish(
|
try environment.mqttClient.publish(
|
||||||
dewPoint: dp,
|
dewPoint: dp,
|
||||||
to: environment.topics.sensors.dewPoint
|
to: environment.topics.sensors.returnSensor.dewPoint
|
||||||
).wait()
|
).wait()
|
||||||
|
|
||||||
logger.debug("Published dew point...")
|
logger.debug("Published dew point...")
|
||||||
|
|||||||
Reference in New Issue
Block a user