ServerMultiplex: Introduces a server mutiplexer

- Also moves all the existing Wemo* stuff over to support the multiplexer
- Moves MainViewController to be the owner of the multiplexer, and its delegate
This commit is contained in:
2020-03-14 18:33:02 -07:00
parent f1f86ced29
commit 918818cd99
8 changed files with 335 additions and 83 deletions

View File

@@ -0,0 +1,71 @@
//
// DeviceProtocol.swift
// XIONControlPanel
//
// Created by James Magahern on 3/13/20.
// Copyright © 2020 XION. All rights reserved.
//
import Foundation
enum DeviceState
{
case off
case on
}
enum DeviceType
{
case `switch`
}
protocol Device
{
// Read-only properties
var name: String { get }
var serial: String { get }
var type: DeviceType { get }
// Writable properties
var state: DeviceState { get set }
}
extension Device where Self: Hashable
{
func hash(into hasher: inout Hasher)
{
hasher.combine(self.name)
hasher.combine(self.type)
hasher.combine(self.serial)
}
static func == (lhs: Self, rhs: Self) -> Bool
{
return lhs.name == rhs.name && lhs.serial == rhs.serial
}
}
class AnyDevice : Device
{
private var device: Device
public var name: String
{ get { return device.name } }
public var serial: String
{ get { return device.serial } }
public var type: DeviceType
{ get { return device.type } }
public var state: DeviceState {
get { return device.state }
set { device.state = newValue }
}
init(_ device: Device) {
self.device = device
}
}
extension AnyDevice : Hashable {}

View File

@@ -8,23 +8,12 @@
import Foundation
class WemoDevice: Hashable
class WemoDevice : Device
{
enum State
{
case off
case on
}
enum DeviceType
{
case `switch`
}
var name: String = ""
var host: String = ""
var model: String = ""
var state: State = .off
var state: DeviceState = .off
var type: DeviceType = .switch
var serial: String = ""