Cleaning up the api.
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
|
||||
public struct HumiditySensor: Equatable {
|
||||
public var topic: String
|
||||
|
||||
public init(topic: String) {
|
||||
self.topic = topic
|
||||
}
|
||||
}
|
||||
37
Sources/Models/Mode.swift
Normal file
37
Sources/Models/Mode.swift
Normal file
@@ -0,0 +1,37 @@
|
||||
import CoreUnitTypes
|
||||
|
||||
/// 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)
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,40 @@
|
||||
|
||||
/// Represents a relay that can be controlled by the MQTT Broker.
|
||||
public struct Relay {
|
||||
|
||||
/// The topic for the relay.
|
||||
public var topic: String
|
||||
|
||||
/// Create a new relay at the given topic.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - topic: The topic for commanding the relay.
|
||||
public init(topic: String) {
|
||||
self.topic = topic
|
||||
}
|
||||
}
|
||||
|
||||
public enum Relay2 {
|
||||
|
||||
/// The topic to read the current state of the relay from.
|
||||
case read(topic: String)
|
||||
|
||||
/// The topic to command the relay state.
|
||||
case command(topic: String)
|
||||
}
|
||||
|
||||
extension Relay {
|
||||
|
||||
/// Represents the different commands that can be sent to a relay.
|
||||
public enum State: String {
|
||||
|
||||
/// Toggle the relay state on or off based on it's current state.
|
||||
case toggle
|
||||
|
||||
/// Turn the relay off.
|
||||
case off
|
||||
|
||||
/// Turn the relay on.
|
||||
case on
|
||||
}
|
||||
}
|
||||
|
||||
15
Sources/Models/Sensor.swift
Normal file
15
Sources/Models/Sensor.swift
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
/// Represents a sensor that provides a reading.
|
||||
public struct Sensor<Reading>: Equatable {
|
||||
|
||||
/// The topic to retrieve the reading from.
|
||||
public var topic: String
|
||||
|
||||
/// Create a new sensor for the given topic.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - topic: The topic to retrieve the readings from.
|
||||
public init(topic: String) {
|
||||
self.topic = topic
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
|
||||
public struct TemperatureSensor: Equatable {
|
||||
public var topic: String
|
||||
|
||||
public init(topic: String) {
|
||||
self.topic = topic
|
||||
}
|
||||
}
|
||||
91
Sources/Models/Topics.swift
Normal file
91
Sources/Models/Topics.swift
Normal file
@@ -0,0 +1,91 @@
|
||||
public struct Topics {
|
||||
|
||||
public var sensors: Sensors
|
||||
public var setPoints: SetPoints
|
||||
public var states: States
|
||||
public var relays: Relays
|
||||
|
||||
public init(
|
||||
sensors: Sensors = .init(),
|
||||
setPoints: SetPoints = .init(),
|
||||
states: States = .init(),
|
||||
relays: Relays = .init()
|
||||
) {
|
||||
self.sensors = sensors
|
||||
self.setPoints = setPoints
|
||||
self.states = states
|
||||
self.relays = relays
|
||||
}
|
||||
|
||||
public struct Sensors {
|
||||
public var temperature: String
|
||||
public var humidity: String
|
||||
public var dewPoint: String
|
||||
|
||||
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 SetPoints {
|
||||
public var humidify: String
|
||||
public var dehumidify: Dehumidify
|
||||
|
||||
public init(
|
||||
humidify: String = "set_points/humidify",
|
||||
dehumidify: Dehumidify = .init()
|
||||
) {
|
||||
self.humidify = humidify
|
||||
self.dehumidify = dehumidify
|
||||
}
|
||||
|
||||
public struct Dehumidify {
|
||||
public var lowDewPoint: String
|
||||
public var highDewPoint: String
|
||||
public var lowRelativeHumidity: String
|
||||
public var highRelativeHumidity: String
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct States {
|
||||
public var mode: String
|
||||
|
||||
public init(mode: String = "states/mode") {
|
||||
self.mode = mode
|
||||
}
|
||||
}
|
||||
|
||||
public struct Relays {
|
||||
public var dehumidification1: String
|
||||
public var dehumidification2: String
|
||||
public var humidification: String
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user