Files
Xaibatsu-Control-Panel/XIONControlPanel/Models/WemoDevice.swift

79 lines
1.6 KiB
Swift
Raw Normal View History

2015-12-31 15:41:32 -08:00
//
// WemoDevice.swift
// XIONControlPanel
//
// Created by Charles Magahern on 12/31/15.
// Copyright © 2015 XION. All rights reserved.
//
import Foundation
2016-07-24 00:14:04 -07:00
class WemoDevice: Hashable
{
enum State
{
2017-05-13 00:40:03 -07:00
case off
case on
2015-12-31 15:41:32 -08:00
}
2017-05-13 00:40:03 -07:00
enum DeviceType
2016-07-24 00:14:04 -07:00
{
2017-05-13 00:40:03 -07:00
case `switch`
2015-12-31 15:41:32 -08:00
}
var name: String = ""
var host: String = ""
var model: String = ""
2017-05-13 00:40:03 -07:00
var state: State = .off
var type: DeviceType = .switch
2015-12-31 15:41:32 -08:00
var serial: String = ""
init()
{}
init(_ dict: NSDictionary)
2015-12-31 15:41:32 -08:00
{
if let name = dict["name"] as? NSString {
self.name = String(name)
}
if let host = dict["host"] as? NSString {
self.host = String(host)
}
if let model = dict["model"] as? NSString {
self.model = String(model)
}
if let state = dict["state"] as? NSNumber {
2017-05-13 00:40:03 -07:00
switch (state.intValue) {
case 0:
2017-05-13 00:40:03 -07:00
self.state = .off
case 1:
2017-05-13 00:40:03 -07:00
self.state = .on
default:
2017-05-13 00:40:03 -07:00
self.state = .off
2015-12-31 15:41:32 -08:00
}
}
if let serial = dict["serialnumber"] as? NSString {
self.serial = String(serial)
}
2015-12-31 15:41:32 -08:00
}
2019-10-13 00:19:23 -07:00
func hash(into hasher: inout Hasher)
{
2019-10-13 00:19:23 -07:00
hasher.combine(self.name)
hasher.combine(self.host)
hasher.combine(self.model)
hasher.combine(self.state)
hasher.combine(self.type)
hasher.combine(self.serial)
}
}
func ==(lhs: WemoDevice, rhs: WemoDevice) -> Bool
{
return (lhs.serial == rhs.serial)
2015-12-31 15:41:32 -08:00
}