From c6fa9fe96053e7f7ce172f3399b44c11687aa9c3 Mon Sep 17 00:00:00 2001 From: James Magahern Date: Fri, 1 May 2020 00:16:10 -0700 Subject: [PATCH] Review feedback --- .../Controllers/MainViewController.swift | 4 +++- XIONControlPanel/Models/DeviceProtocol.swift | 15 ++++++++------- XIONControlPanel/Models/HubitatDevice.swift | 6 ++++-- XIONControlPanel/Servers/ServerMultiplex.swift | 6 +++--- XIONControlPanel/Servers/WemoServer.swift | 10 ++++------ 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/XIONControlPanel/Controllers/MainViewController.swift b/XIONControlPanel/Controllers/MainViewController.swift index 467ab0d..ea39e6d 100644 --- a/XIONControlPanel/Controllers/MainViewController.swift +++ b/XIONControlPanel/Controllers/MainViewController.swift @@ -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) } } diff --git a/XIONControlPanel/Models/DeviceProtocol.swift b/XIONControlPanel/Models/DeviceProtocol.swift index bbdfd0e..15db6a6 100644 --- a/XIONControlPanel/Models/DeviceProtocol.swift +++ b/XIONControlPanel/Models/DeviceProtocol.swift @@ -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 } } diff --git a/XIONControlPanel/Models/HubitatDevice.swift b/XIONControlPanel/Models/HubitatDevice.swift index 076e4d0..72461c6 100644 --- a/XIONControlPanel/Models/HubitatDevice.swift +++ b/XIONControlPanel/Models/HubitatDevice.swift @@ -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` diff --git a/XIONControlPanel/Servers/ServerMultiplex.swift b/XIONControlPanel/Servers/ServerMultiplex.swift index 53416cc..cdfcfbf 100644 --- a/XIONControlPanel/Servers/ServerMultiplex.swift +++ b/XIONControlPanel/Servers/ServerMultiplex.swift @@ -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() 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) } } diff --git a/XIONControlPanel/Servers/WemoServer.swift b/XIONControlPanel/Servers/WemoServer.swift index 5fc9c16..5e688ac 100644 --- a/XIONControlPanel/Servers/WemoServer.swift +++ b/XIONControlPanel/Servers/WemoServer.swift @@ -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) })) }