Files
Xaibatsu-Control-Panel/XIONControlPanel/Models/DeviceProtocol.swift
2020-05-01 00:16:10 -07:00

73 lines
1.3 KiB
Swift

//
// DeviceProtocol.swift
// XIONControlPanel
//
// Created by James Magahern on 3/13/20.
// Copyright © 2020 XION. All rights reserved.
//
import Foundation
enum DeviceState : String, Codable
{
case off
case on
}
enum DeviceType : String, Codable
{
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
{ return device.name }
public var serial: String
{ return device.serial }
public var type: DeviceType
{ return device.type }
public var state: DeviceState {
get { return device.state }
set { device.state = newValue }
}
init(_ device: Device)
{
self.device = device
}
}
extension AnyDevice : Hashable {}