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
|
|
|
|
|
{
|
2015-12-31 15:41:32 -08:00
|
|
|
case Off
|
|
|
|
|
case On
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-24 00:14:04 -07:00
|
|
|
enum Type
|
|
|
|
|
{
|
2015-12-31 15:41:32 -08:00
|
|
|
case Switch
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var name: String = ""
|
|
|
|
|
var host: String = ""
|
|
|
|
|
var model: String = ""
|
|
|
|
|
var state: State = .Off
|
|
|
|
|
var type: Type = .Switch
|
|
|
|
|
var serial: String = ""
|
|
|
|
|
|
|
|
|
|
init()
|
|
|
|
|
{}
|
|
|
|
|
|
2015-12-31 19:51:51 -08:00
|
|
|
init(_ dict: NSDictionary)
|
2015-12-31 15:41:32 -08:00
|
|
|
{
|
2015-12-31 19:51:51 -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 {
|
|
|
|
|
switch (state.integerValue) {
|
|
|
|
|
case 0:
|
|
|
|
|
self.state = .Off
|
|
|
|
|
case 1:
|
|
|
|
|
self.state = .On
|
|
|
|
|
default:
|
|
|
|
|
self.state = .Off
|
2015-12-31 15:41:32 -08:00
|
|
|
}
|
|
|
|
|
}
|
2015-12-31 19:51:51 -08:00
|
|
|
|
|
|
|
|
if let serial = dict["serialnumber"] as? NSString {
|
|
|
|
|
self.serial = String(serial)
|
|
|
|
|
}
|
2015-12-31 15:41:32 -08:00
|
|
|
}
|
2015-12-31 23:29:48 -08:00
|
|
|
|
|
|
|
|
var hashValue: Int
|
|
|
|
|
{
|
|
|
|
|
var hash: Int = 0x0
|
|
|
|
|
hash ^= self.name.hash
|
|
|
|
|
hash ^= self.host.hash
|
|
|
|
|
hash ^= self.model.hash
|
|
|
|
|
hash ^= self.state.hashValue
|
|
|
|
|
hash ^= self.type.hashValue
|
|
|
|
|
hash ^= self.serial.hashValue
|
|
|
|
|
|
|
|
|
|
return hash
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ==(lhs: WemoDevice, rhs: WemoDevice) -> Bool
|
|
|
|
|
{
|
|
|
|
|
return (lhs.serial == rhs.serial)
|
2015-12-31 15:41:32 -08:00
|
|
|
}
|