Review feedback
This commit is contained in:
@@ -221,6 +221,8 @@ class MainViewController: UIViewController, SwitchesViewControllerDelegate, Serv
|
||||
func serverMultiplex(_ multiplex: ServerMultiplex, didEncounterError error: Error)
|
||||
{
|
||||
_updateConnectivityStatus(.error)
|
||||
print(error.localizedDescription)
|
||||
|
||||
var stderr = StandardErrorOutputStream()
|
||||
print(error.localizedDescription, to: &stderr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ import Foundation
|
||||
|
||||
enum DeviceState : String, Codable
|
||||
{
|
||||
case off = "off"
|
||||
case on = "on"
|
||||
case off
|
||||
case on
|
||||
}
|
||||
|
||||
enum DeviceType : String, Codable
|
||||
{
|
||||
case `switch` = "switch"
|
||||
case `switch`
|
||||
}
|
||||
|
||||
protocol Device
|
||||
@@ -50,20 +50,21 @@ class AnyDevice : Device
|
||||
private var device: Device
|
||||
|
||||
public var name: String
|
||||
{ get { return device.name } }
|
||||
{ return device.name }
|
||||
|
||||
public var serial: String
|
||||
{ get { return device.serial } }
|
||||
{ return device.serial }
|
||||
|
||||
public var type: DeviceType
|
||||
{ get { return device.type } }
|
||||
{ return device.type }
|
||||
|
||||
public var state: DeviceState {
|
||||
get { return device.state }
|
||||
set { device.state = newValue }
|
||||
}
|
||||
|
||||
init(_ device: Device) {
|
||||
init(_ device: Device)
|
||||
{
|
||||
self.device = device
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,15 @@ public struct HubitatDevice : Device
|
||||
|
||||
var id: Int = -1
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
enum CodingKeys: String, CodingKey
|
||||
{
|
||||
case name = "label"
|
||||
case id = "id"
|
||||
case attributes = "attributes"
|
||||
}
|
||||
|
||||
enum AttributesKeys: String, CodingKey {
|
||||
enum AttributesKeys: String, CodingKey
|
||||
{
|
||||
case power
|
||||
case dataType
|
||||
case `switch`
|
||||
|
||||
@@ -17,7 +17,7 @@ protocol ServerMultiplexDelegate
|
||||
|
||||
enum ServerMultiplexError : Error
|
||||
{
|
||||
case UnknownDevice
|
||||
case unknownDevice
|
||||
}
|
||||
|
||||
class ServerMultiplex
|
||||
@@ -26,7 +26,7 @@ class ServerMultiplex
|
||||
public private(set) var devices = Set<AnyDevice>()
|
||||
|
||||
private var servers: [Server] = []
|
||||
public var numServers: Int { get { return servers.count } }
|
||||
public var numServers: Int { return servers.count }
|
||||
|
||||
public func addServer(_ server: Server)
|
||||
{
|
||||
@@ -48,7 +48,7 @@ class ServerMultiplex
|
||||
devices[index].state = state
|
||||
}
|
||||
} else {
|
||||
completion(ServerMultiplexError.UnknownDevice)
|
||||
completion(ServerMultiplexError.unknownDevice)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,17 +76,15 @@ class WemoServer : Server
|
||||
func fetchDevices(_ completion: @escaping (Result<[AnyDevice], Error>) -> Void)
|
||||
{
|
||||
let op = FetchDevicesOperation(baseURL: self.baseURL, session: _urlSession)
|
||||
weak var weakOp = op
|
||||
op.completionBlock = {
|
||||
guard let strongOp = weakOp else { return }
|
||||
if let error = strongOp.error {
|
||||
op.completionBlock = { [unowned op] in
|
||||
if let error = op.error {
|
||||
self._logError("Error fetching devices", error: error)
|
||||
completion(.failure(error))
|
||||
} else {
|
||||
self.devices = strongOp.devices
|
||||
self.devices = op.devices
|
||||
}
|
||||
|
||||
self.devices = strongOp.devices
|
||||
self.devices = op.devices
|
||||
completion(.success(self.devices.map { AnyDevice($0) }))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user