feat: Begins removing old interfaces and renaming

This commit is contained in:
2024-11-09 00:17:28 -05:00
parent 48d51419d7
commit 529b9b0bc5
5 changed files with 67 additions and 1 deletions

View File

@@ -14,7 +14,8 @@ let package = Package(
.library(name: "EnvVars", targets: ["EnvVars"]),
.library(name: "Models", targets: ["Models"]),
.library(name: "Client", targets: ["Client"]),
.library(name: "ClientLive", targets: ["ClientLive"])
.library(name: "ClientLive", targets: ["ClientLive"]),
.library(name: "SensorsService", targets: ["SensorsService"])
],
dependencies: [
.package(url: "https://github.com/swift-server-community/mqtt-nio.git", from: "2.0.0"),
@@ -97,6 +98,22 @@ let package = Package(
dependencies: [
"Models"
]
),
.target(
name: "SensorsService",
dependencies: [
"Models",
.product(name: "MQTTNIO", package: "mqtt-nio"),
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle")
]
),
.testTarget(
name: "SensorsServiceTests",
dependencies: [
"SensorsService",
// TODO: Remove.
"ClientLive"
]
)
]
)

View File

@@ -6,6 +6,7 @@ import NIO
import Psychrometrics
import ServiceLifecycle
// TODO: Remove.
// TODO: Pass in eventLoopGroup and MQTTClient.
public actor SensorsClient {

View File

@@ -0,0 +1,41 @@
import CoreUnitTypes
import Logging
import Models
import MQTTNIO
import NIO
import NIOFoundationCompat
import Psychrometrics
/// Represents a type that can be initialized by a ``ByteBuffer``.
protocol BufferInitalizable {
init?(buffer: inout ByteBuffer)
}
extension Double: BufferInitalizable {
/// Attempt to create / parse a double from a byte buffer.
init?(buffer: inout ByteBuffer) {
guard let string = buffer.readString(
length: buffer.readableBytes,
encoding: String.Encoding.utf8
)
else { return nil }
self.init(string)
}
}
extension Temperature: 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(value, units: .celsius)
}
}
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

@@ -99,6 +99,12 @@ public actor SensorsService: Service {
}
// MARK: - Errors
struct DecodingError: Error {}
struct NotFoundError: Error {}
struct SensorExists: Error {}
// MARK: - Helpers
struct MQTTClientNotConnected: Error {}

View File

@@ -5,6 +5,7 @@ import Models
import MQTTNIO
import NIO
import Psychrometrics
@testable import SensorsService
import XCTest
final class SensorsClientTests: XCTestCase {