feat: Updates to newer psychrometrics package. Not yet a working example.

This commit is contained in:
2024-11-09 11:35:30 -05:00
parent e2683d3f06
commit a87addaf0b
13 changed files with 821 additions and 737 deletions

View File

@@ -1,10 +1,9 @@
import CoreUnitTypes
import Logging
import Models
import MQTTNIO
import NIO
import NIOFoundationCompat
import Psychrometrics
import SharedModels
/// Represents a type that can be initialized by a ``ByteBuffer``.
protocol BufferInitalizable {
@@ -24,18 +23,39 @@ extension Double: BufferInitalizable {
}
}
extension Temperature: BufferInitalizable {
/// Attempt to create / parse a temperature from a byte buffer.
// extension DryBulb: BufferInitalizable {
// /// Attempt to create / parse a temperature from a byte buffer.
// init?(buffer: inout ByteBuffer) {
// guard let value = Double(buffer: &buffer) else { return nil }
// self.init(.init(value, units: .celsius))
// }
// }
extension Tagged: BufferInitalizable where RawValue: BufferInitalizable {
init?(buffer: inout ByteBuffer) {
guard let value = Double(buffer: &buffer) else { return nil }
self.init(value, units: .celsius)
guard let value = RawValue(buffer: &buffer) else { return nil }
self.init(value)
}
}
extension RelativeHumidity: BufferInitalizable {
/// Attempt to create / parse a relative humidity from a byte buffer.
extension Humidity<Relative>: BufferInitalizable {
init?(buffer: inout ByteBuffer) {
guard let value = Double(buffer: &buffer) else { return nil }
self.init(value)
}
}
extension Temperature<DryAir>: BufferInitalizable {
init?(buffer: inout ByteBuffer) {
guard let value = Double(buffer: &buffer) else { return nil }
self.init(value)
}
}
// extension RelativeHumidity: BufferInitalizable {
// /// Attempt to create / parse a relative humidity from a byte buffer.
// init?(buffer: inout ByteBuffer) {
// guard let value = Double(buffer: &buffer) else { return nil }
// self.init(value)
// }
// }

View File

@@ -3,7 +3,7 @@ import Logging
import Models
@preconcurrency import MQTTNIO
import NIO
import Psychrometrics
import PsychrometricClient
import ServiceLifecycle
public actor SensorsService: Service {
@@ -52,7 +52,7 @@ public actor SensorsService: Service {
if topic.contains("temperature") {
// do something.
var buffer = value.payload
guard let temperature = Temperature(buffer: &buffer) else {
guard let temperature = DryBulb(buffer: &buffer) else {
logger.trace("Decoding error for topic: \(topic)")
throw DecodingError()
}
@@ -96,8 +96,8 @@ public actor SensorsService: Service {
private func publishUpdates() async throws {
for sensor in sensors.filter(\.needsProcessed) {
try await publish(double: sensor.dewPoint?.rawValue, to: sensor.topics.dewPoint)
try await publish(double: sensor.enthalpy?.rawValue, to: sensor.topics.enthalpy)
try await publish(double: sensor.dewPoint?.value, to: sensor.topics.dewPoint)
try await publish(double: sensor.enthalpy?.value, to: sensor.topics.enthalpy)
try sensors.hasProcessed(sensor)
}
}