feat: Begins removing old interfaces and renaming
This commit is contained in:
@@ -14,7 +14,8 @@ let package = Package(
|
|||||||
.library(name: "EnvVars", targets: ["EnvVars"]),
|
.library(name: "EnvVars", targets: ["EnvVars"]),
|
||||||
.library(name: "Models", targets: ["Models"]),
|
.library(name: "Models", targets: ["Models"]),
|
||||||
.library(name: "Client", targets: ["Client"]),
|
.library(name: "Client", targets: ["Client"]),
|
||||||
.library(name: "ClientLive", targets: ["ClientLive"])
|
.library(name: "ClientLive", targets: ["ClientLive"]),
|
||||||
|
.library(name: "SensorsService", targets: ["SensorsService"])
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://github.com/swift-server-community/mqtt-nio.git", from: "2.0.0"),
|
.package(url: "https://github.com/swift-server-community/mqtt-nio.git", from: "2.0.0"),
|
||||||
@@ -97,6 +98,22 @@ let package = Package(
|
|||||||
dependencies: [
|
dependencies: [
|
||||||
"Models"
|
"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"
|
||||||
|
]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import NIO
|
|||||||
import Psychrometrics
|
import Psychrometrics
|
||||||
import ServiceLifecycle
|
import ServiceLifecycle
|
||||||
|
|
||||||
|
// TODO: Remove.
|
||||||
// TODO: Pass in eventLoopGroup and MQTTClient.
|
// TODO: Pass in eventLoopGroup and MQTTClient.
|
||||||
public actor SensorsClient {
|
public actor SensorsClient {
|
||||||
|
|
||||||
|
|||||||
41
Sources/SensorsService/Helpers.swift
Executable file
41
Sources/SensorsService/Helpers.swift
Executable 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -99,6 +99,12 @@ public actor SensorsService: Service {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Errors
|
||||||
|
|
||||||
|
struct DecodingError: Error {}
|
||||||
|
struct NotFoundError: Error {}
|
||||||
|
struct SensorExists: Error {}
|
||||||
|
|
||||||
// MARK: - Helpers
|
// MARK: - Helpers
|
||||||
|
|
||||||
struct MQTTClientNotConnected: Error {}
|
struct MQTTClientNotConnected: Error {}
|
||||||
@@ -5,6 +5,7 @@ import Models
|
|||||||
import MQTTNIO
|
import MQTTNIO
|
||||||
import NIO
|
import NIO
|
||||||
import Psychrometrics
|
import Psychrometrics
|
||||||
|
@testable import SensorsService
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
final class SensorsClientTests: XCTestCase {
|
final class SensorsClientTests: XCTestCase {
|
||||||
Reference in New Issue
Block a user