feat: Removing old libraries

This commit is contained in:
2024-11-09 12:15:59 -05:00
parent 936dd0b816
commit 320a733d12
13 changed files with 151 additions and 1486 deletions

69
Sources/Models/EnvVars.swift Executable file
View File

@@ -0,0 +1,69 @@
import Foundation
/// Holds common settings for connecting to your MQTT broker. The default values can be used,
/// they can be loaded from the shell environment, or from a file located in the root directory.
///
/// This allows us to keep sensitve settings out of the repository.
public struct EnvVars: Codable, Equatable, Sendable {
/// The current app environment.
public var appEnv: AppEnv
/// The MQTT host.
public var host: String
/// The MQTT port.
public var port: String?
/// The identifier to use when connecting to the MQTT broker.
public var identifier: String
/// The MQTT user name.
public var userName: String?
/// The MQTT user password.
public var password: String?
/// Create a new ``EnvVars``
///
/// - Parameters:
/// - appEnv: The current application environment
/// - host: The MQTT host.
/// - port: The MQTT port.
/// - identifier: The identifier to use when connecting to the MQTT broker.
/// - userName: The MQTT user name to connect to the broker with.
/// - password: The MQTT user password to connect to the broker with.
public init(
appEnv: AppEnv = .development,
host: String = "127.0.0.1",
port: String? = "1883",
identifier: String = "dewPoint-controller",
userName: String? = "mqtt_user",
password: String? = "secret!"
) {
self.appEnv = appEnv
self.host = host
self.port = port
self.identifier = identifier
self.userName = userName
self.password = password
}
/// Custom coding keys.
private enum CodingKeys: String, CodingKey {
case appEnv = "APP_ENV"
case host = "MQTT_HOST"
case port = "MQTT_PORT"
case identifier = "MQTT_IDENTIFIER"
case userName = "MQTT_USERNAME"
case password = "MQTT_PASSWORD"
}
/// Represents the different app environments.
public enum AppEnv: String, Codable, Sendable {
case development
case production
case staging
case testing
}
}

View File

@@ -1,39 +0,0 @@
import PsychrometricClient
// 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(DewPoint)
/// 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: DewPoint, low: DewPoint)
/// Control humidifying based off relative humidity.
case relativeHumidity(high: RelativeHumidity, low: RelativeHumidity)
}
}

View File

@@ -1,102 +0,0 @@
import Foundation
import PsychrometricClient
// TODO: Remove
// TODO: Make this a struct, then create a Store class that holds the state??
public final class State {
public var altitude: Length
public var sensors: Sensors
public var units: PsychrometricUnits
public init(
altitude: Length = .seaLevel,
sensors: Sensors = .init(),
units: PsychrometricUnits = .imperial
) {
self.altitude = altitude
self.sensors = sensors
self.units = units
}
public struct Sensors: Equatable {
public var mixedAirSensor: TemperatureHumiditySensor<MixedAir>
public var postCoilSensor: TemperatureHumiditySensor<PostCoil>
public var returnAirSensor: TemperatureHumiditySensor<Return>
public var supplyAirSensor: TemperatureHumiditySensor<Supply>
public init(
mixedAirSensor: TemperatureHumiditySensor<MixedAir> = .init(),
postCoilSensor: TemperatureHumiditySensor<PostCoil> = .init(),
returnAirSensor: TemperatureHumiditySensor<Return> = .init(),
supplyAirSensor: TemperatureHumiditySensor<Supply> = .init()
) {
self.mixedAirSensor = mixedAirSensor
self.postCoilSensor = postCoilSensor
self.returnAirSensor = returnAirSensor
self.supplyAirSensor = supplyAirSensor
}
public var needsProcessed: Bool {
mixedAirSensor.needsProcessed
|| postCoilSensor.needsProcessed
|| returnAirSensor.needsProcessed
|| supplyAirSensor.needsProcessed
}
}
}
public extension State.Sensors {
struct TemperatureHumiditySensor<Location>: Equatable {
@TrackedChanges
public var temperature: DryBulb?
@TrackedChanges
public var humidity: RelativeHumidity?
public var needsProcessed: Bool {
get { $temperature.needsProcessed || $humidity.needsProcessed }
set {
$temperature.needsProcessed = newValue
$humidity.needsProcessed = newValue
}
}
// WARN: Fix me.
public func dewPoint(units _: PsychrometricUnits? = nil) -> DewPoint? {
guard let temperature = temperature,
let humidity = humidity
else { return nil }
return nil
// return .init(dryBulb: temperature, humidity: humidity, units: units)
}
// WARN: Fix me.
public func enthalpy(altitude _: Length, units _: PsychrometricUnits? = nil) -> EnthalpyOf<MoistAir>? {
guard let temperature = temperature,
let humidity = humidity
else { return nil }
return nil
// return .init(dryBulb: temperature, humidity: humidity, altitude: altitude, units: units)
}
public init(
temperature: DryBulb? = 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 Location Namespaces
enum MixedAir {}
enum PostCoil {}
enum Return {}
enum Supply {}
}

View File

@@ -1,262 +0,0 @@
// TODO: Remove
/// A container for all the different MQTT topics that are needed by the application.
public struct Topics: Codable, Equatable, Sendable {
/// The command topics the application can publish to.
public var commands: Commands
/// The sensor topics the application can read from / write to.
public var sensors: Sensors
/// The set point topics the application can read set point values from.
public var setPoints: SetPoints
/// The state topics the application can read state values from.
public var states: States
/// Create the topics required by the application.
///
/// - Parameters:
/// - sensors: The sensor topics.
/// - setPoints: The set point topics
/// - states: The states topics
/// - relays: The relay topics
public init(
commands: Commands = .init(),
sensors: Sensors = .init(),
setPoints: SetPoints = .init(),
states: States = .init()
) {
self.commands = commands
self.sensors = sensors
self.setPoints = setPoints
self.states = states
}
/// Represents the sensor topics.
public struct Sensors: Codable, Equatable, Sendable {
public var mixedAirSensor: TemperatureAndHumiditySensor<State.Sensors.MixedAir>
public var postCoilSensor: TemperatureAndHumiditySensor<State.Sensors.PostCoil>
public var returnAirSensor: TemperatureAndHumiditySensor<State.Sensors.Return>
public var supplyAirSensor: TemperatureAndHumiditySensor<State.Sensors.Supply>
public init(
mixedAirSensor: TemperatureAndHumiditySensor<State.Sensors.MixedAir> = .default(location: "mixed-air"),
postCoilSensor: TemperatureAndHumiditySensor<State.Sensors.PostCoil> = .default(location: "post-coil"),
returnAirSensor: TemperatureAndHumiditySensor<State.Sensors.Return> = .default(location: "return"),
supplyAirSensor: TemperatureAndHumiditySensor<State.Sensors.Supply> = .default(location: "supply")
) {
self.mixedAirSensor = mixedAirSensor
self.postCoilSensor = postCoilSensor
self.returnAirSensor = returnAirSensor
self.supplyAirSensor = supplyAirSensor
}
public struct TemperatureAndHumiditySensor<Location>: Codable, Equatable, Sendable {
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,
humidity: String,
dewPoint: String,
enthalpy: String
) {
self.temperature = temperature
self.humidity = humidity
self.dewPoint = dewPoint
self.enthalpy = enthalpy
}
}
}
/// A container for set point related topics used by the application.
public struct SetPoints: Codable, Equatable, Sendable {
/// The topic for the humidify set point.
public var humidify: Humidify
/// The topics for dehumidification set points.
public var dehumidify: Dehumidify
/// Create a new set point topic container.
///
/// - Parameters:
/// - humidify: The topic for humidification set points.
/// - dehumidify: The topics for dehumidification set points.
public init(
humidify: Humidify = .init(),
dehumidify: Dehumidify = .init()
) {
self.humidify = humidify
self.dehumidify = dehumidify
}
/// A container for the humidification set point topics used by the application.
public struct Humidify: Codable, Equatable, Sendable {
/// The topic for dew point control mode set point.
public var dewPoint: String
/// The topic for relative humidity control mode set point.
public var relativeHumidity: String
/// Create a new container for the humidification set point topics.
///
/// - Parameters:
/// - dewPoint: The topic for dew point control mode set point.
/// - relativeHumidity: The topic for relative humidity control mode set point.
public init(
dewPoint: String = "set_points/humidify/dew_point",
relativeHumidity: String = "set_points/humidify/relative_humidity"
) {
self.dewPoint = dewPoint
self.relativeHumidity = relativeHumidity
}
}
/// A container for dehumidifcation set point topics.
public struct Dehumidify: Codable, Equatable, Sendable {
/// A low setting for dew point control modes.
public var lowDewPoint: String
/// A high setting for dew point control modes.
public var highDewPoint: String
/// A low setting for relative humidity control modes.
public var lowRelativeHumidity: String
/// A high setting for relative humidity control modes.
public var highRelativeHumidity: String
/// Create a new container for dehumidification set point topics.
///
/// - Parameters:
/// - lowDewPoint: A low setting for dew point control modes.
/// - highDewPoint: A high setting for dew point control modes.
/// - lowRelativeHumidity: A low setting for relative humidity control modes.
/// - highRelativeHumidity: A high setting for relative humidity control modes.
public init(
lowDewPoint: String = "set_points/dehumidify/low_dew_point",
highDewPoint: String = "set_points/dehumidify/high_dew_point",
lowRelativeHumidity: String = "set_points/dehumidify/low_relative_humidity",
highRelativeHumidity: String = "set_points/dehumidify/high_relative_humidity"
) {
self.lowDewPoint = lowDewPoint
self.highDewPoint = highDewPoint
self.lowRelativeHumidity = lowRelativeHumidity
self.highRelativeHumidity = highRelativeHumidity
}
}
}
/// A container for control state topics used by the application.
public struct States: Codable, Equatable, Sendable {
/// The topic for the control mode.
public var mode: String
/// The relay state topics.
public var relays: Relays
/// Create a new container for control state topics.
///
/// - Parameters:
/// - mode: The topic for the control mode.
public init(
mode: String = "states/mode",
relays: Relays = .init()
) {
self.mode = mode
self.relays = relays
}
/// A container for reading the current state of a relay.
public struct Relays: Codable, Equatable, Sendable {
/// The dehumidification stage-1 relay topic.
public var dehumdification1: String
/// The dehumidification stage-2 relay topic.
public var dehumidification2: String
/// The humidification relay topic.
public var humdification: String
/// Create a new container for relay state topics.
///
/// - Parameters:
/// - dehumidification1: The dehumidification stage-1 relay topic.
/// - dehumidification2: The dehumidification stage-2 relay topic.
/// - humidification: The humidification relay topic.
public init(
dehumidefication1: String = "states/relays/dehumidification_1",
dehumidification2: String = "states/relays/dehumidification_2",
humidification: String = "states/relays/humidification"
) {
self.dehumdification1 = dehumidefication1
self.dehumidification2 = dehumidification2
self.humdification = humidification
}
}
}
/// A container for commands topics that the application can publish to.
public struct Commands: Codable, Equatable, Sendable {
/// The relay command topics.
public var relays: Relays
/// Create a new command topics container.
///
/// - Parameters:
/// - relays: The relay command topics.
public init(relays: Relays = .init()) {
self.relays = relays
}
/// A container for relay command topics used by the application.
public struct Relays: Codable, Equatable, Sendable {
/// The dehumidification stage-1 relay topic.
public var dehumidification1: String
/// The dehumidification stage-2 relay topic.
public var dehumidification2: String
/// The humidification relay topic.
public var humidification: String
/// Create a new container for commanding relays.
///
/// - Parameters:
/// - dehumidification1: The dehumidification stage-1 relay topic.
/// - dehumidification2: The dehumidification stage-2 relay topic.
/// - humidification: The humidification relay topic.
public init(
dehumidification1: String = "relays/dehumidification_1",
dehumidification2: String = "relays/dehumidification_2",
humidification: String = "relays/humidification"
) {
self.dehumidification1 = dehumidification1
self.dehumidification2 = dehumidification2
self.humidification = humidification
}
}
}
}
// MARK: Helpers
public extension Topics.Sensors.TemperatureAndHumiditySensor {
static func `default`(location: String) -> Self {
.init(
temperature: "sensors/\(location)/temperature",
humidity: "sensors/\(location)/humidity",
dewPoint: "sensors/\(location)/dew-point",
enthalpy: "sensors/\(location)/enthalpy"
)
}
}