Skip to content

Commit

Permalink
Implements Hashable for Rule, Schedule and Sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
J3y-S authored and Jerome Schmitz committed May 19, 2016
1 parent 721c702 commit 0c43a5b
Show file tree
Hide file tree
Showing 32 changed files with 316 additions and 26 deletions.
28 changes: 20 additions & 8 deletions SwiftyHue/Classes/BridgeResourceModels/Rule/Rule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,8 @@
import Foundation
import Gloss

public func ==(lhs: Rule, rhs: Rule) -> Bool {
return lhs.identifier == rhs.identifier
}

public class Rule: BridgeResource, BridgeResourceDictGenerator {

public var hashValue: Int {
return 1
}

public typealias AssociatedBridgeResourceType = Rule

public let identifier: String
Expand Down Expand Up @@ -75,4 +67,24 @@ public class Rule: BridgeResource, BridgeResourceDictGenerator {

return json
}
}

extension Rule: Hashable {

public var hashValue: Int {

return Int(self.identifier)!
}
}

public func ==(lhs: Rule, rhs: Rule) -> Bool {
return lhs.identifier == rhs.identifier &&
lhs.name == rhs.name &&
lhs.created == rhs.created &&
lhs.lasttriggered == rhs.lasttriggered &&
lhs.timestriggered == rhs.timestriggered &&
lhs.owner == rhs.owner &&
lhs.status == rhs.status &&
lhs.conditions == rhs.conditions &&
lhs.actions == rhs.actions
}
16 changes: 15 additions & 1 deletion SwiftyHue/Classes/BridgeResourceModels/Rule/RuleAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class RuleAction: Decodable, Encodable {

public let address: String
public let method: String
public let body: JSON
public let body: NSDictionary

public required init?(json: JSON) {

Expand All @@ -38,4 +38,18 @@ public class RuleAction: Decodable, Encodable {

return json
}
}

extension RuleAction: Hashable {

public var hashValue: Int {

return 1
}
}

public func ==(lhs: RuleAction, rhs: RuleAction) -> Bool {
return lhs.address == rhs.address &&
lhs.method == rhs.method &&
lhs.body == rhs.body
}
14 changes: 14 additions & 0 deletions SwiftyHue/Classes/BridgeResourceModels/Rule/RuleCondition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,18 @@ public class RuleCondition: Decodable, Encodable {

return json
}
}

extension RuleCondition: Hashable {

public var hashValue: Int {

return 1
}
}

public func ==(lhs: RuleCondition, rhs: RuleCondition) -> Bool {
return lhs.address == rhs.address &&
lhs.conditionOperator == rhs.conditionOperator &&
lhs.value == rhs.value
}
27 changes: 19 additions & 8 deletions SwiftyHue/Classes/BridgeResourceModels/Schedule/Schedule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,8 @@
import Foundation
import Gloss

public func ==(lhs: Schedule, rhs: Schedule) -> Bool {
return lhs.identifier == rhs.identifier
}

public class Schedule: BridgeResource, BridgeResourceDictGenerator {

public var hashValue: Int {
return 1
}

public typealias AssociatedBridgeResourceType = Schedule

public let identifier: String
Expand Down Expand Up @@ -66,3 +58,22 @@ public class Schedule: BridgeResource, BridgeResourceDictGenerator {
return json
}
}

extension Schedule: Hashable {

public var hashValue: Int {

return 1
}
}

public func ==(lhs: Schedule, rhs: Schedule) -> Bool {
return lhs.identifier == rhs.identifier &&
lhs.name == rhs.name &&
lhs.scheduleDescription == rhs.scheduleDescription &&
lhs.command == rhs.command &&
lhs.status == rhs.status &&
lhs.recycle == rhs.recycle &&
lhs.autodelete == rhs.autodelete &&
lhs.localtime == rhs.localtime
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ScheduleCommand: Decodable, Encodable {

public let address: String
public let method: String
public let body: JSON
public let body: NSDictionary

public required init?(json: JSON) {

Expand All @@ -39,3 +39,17 @@ public class ScheduleCommand: Decodable, Encodable {
return json
}
}

extension ScheduleCommand: Hashable {

public var hashValue: Int {

return 1
}
}

public func ==(lhs: ScheduleCommand, rhs: ScheduleCommand) -> Bool {
return lhs.address == rhs.address &&
lhs.method == rhs.method &&
lhs.body == rhs.body
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ public class DaylightSensor: Sensor {
required public init?(json: JSON) {
super.init(json: json)
}
}

public func ==(lhs: DaylightSensor, rhs: DaylightSensor) -> Bool {
return lhs.identifier == rhs.identifier &&
lhs.name == rhs.name &&
lhs.state == rhs.state &&
lhs.config == rhs.config &&
lhs.type == rhs.type &&
lhs.modelId == rhs.modelId &&
lhs.manufacturerName == rhs.manufacturerName &&
lhs.swVersion == rhs.swVersion
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@ public class DaylightSensorConfig: SensorConfig {
return nil
}
}

public func ==(lhs: DaylightSensorConfig, rhs: DaylightSensorConfig) -> Bool {
return lhs.on == rhs.on &&
lhs.reachable == rhs.reachable &&
lhs.battery == rhs.battery &&
lhs.url == rhs.url &&
lhs.long == rhs.long &&
lhs.lat == rhs.lat &&
lhs.sunriseOffset == rhs.sunriseOffset &&
lhs.sunsetOffset == rhs.sunsetOffset
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ public class DaylightSensorState: SensorState {

return nil
}
}

public func ==(lhs: DaylightSensorState, rhs: DaylightSensorState) -> Bool {
return lhs.lastUpdated == rhs.lastUpdated &&
lhs.daylight == rhs.daylight
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ public class GenericFlagSensor: Sensor {
required public init?(json: JSON) {
super.init(json: json)
}
}

public func ==(lhs: GenericFlagSensor, rhs: GenericFlagSensor) -> Bool {
return lhs.identifier == rhs.identifier &&
lhs.name == rhs.name &&
lhs.state == rhs.state &&
lhs.config == rhs.config &&
lhs.type == rhs.type &&
lhs.modelId == rhs.modelId &&
lhs.manufacturerName == rhs.manufacturerName &&
lhs.swVersion == rhs.swVersion
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ public class GenericFlagSensorConfig: SensorConfig {

super.init(json: json)
}
}

public func ==(lhs: DaylightSensorConfig, rhs: DaylightSensorConfig) -> Bool {
return lhs.on == rhs.on &&
lhs.reachable == rhs.reachable &&
lhs.battery == rhs.battery &&
lhs.url == rhs.url
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ public class GenericFlagSensorState: SensorState {

return nil
}
}

public func ==(lhs: GenericFlagSensorState, rhs: GenericFlagSensorState) -> Bool {
return lhs.lastUpdated == rhs.lastUpdated &&
lhs.flag == rhs.flag
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ public class GenericStatusSensor: Sensor {
required public init?(json: JSON) {
super.init(json: json)
}
}

public func ==(lhs: GenericStatusSensor, rhs: GenericStatusSensor) -> Bool {
return lhs.identifier == rhs.identifier &&
lhs.name == rhs.name &&
lhs.state == rhs.state &&
lhs.config == rhs.config &&
lhs.type == rhs.type &&
lhs.modelId == rhs.modelId &&
lhs.manufacturerName == rhs.manufacturerName &&
lhs.swVersion == rhs.swVersion
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ public class GenericStatusSensorConfig: SensorConfig {
super.init(json: json)
}
}

public func ==(lhs: GenericStatusSensorConfig, rhs: GenericStatusSensorConfig) -> Bool {
return lhs.on == rhs.on &&
lhs.reachable == rhs.reachable &&
lhs.battery == rhs.battery &&
lhs.url == rhs.url
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ public class GenericStatusState: SensorState {
return nil
}
}

public func ==(lhs: GenericStatusState, rhs: GenericStatusState) -> Bool {
return lhs.lastUpdated == rhs.lastUpdated &&
lhs.status == rhs.status
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ public class HumiditySensor: Sensor {
required public init?(json: JSON) {
super.init(json: json)
}
}

public func ==(lhs: HumiditySensor, rhs: HumiditySensor) -> Bool {
return lhs.identifier == rhs.identifier &&
lhs.name == rhs.name &&
lhs.state == rhs.state &&
lhs.config == rhs.config &&
lhs.type == rhs.type &&
lhs.modelId == rhs.modelId &&
lhs.manufacturerName == rhs.manufacturerName &&
lhs.swVersion == rhs.swVersion
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ public class HumiditySensorConfig: SensorConfig {
super.init(json: json)
}
}

public func ==(lhs: HumiditySensorConfig, rhs: HumiditySensorConfig) -> Bool {
return lhs.on == rhs.on &&
lhs.reachable == rhs.reachable &&
lhs.battery == rhs.battery &&
lhs.url == rhs.url
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ public class HumiditySensorState: SensorState {
return nil
}
}

public func ==(lhs: HumiditySensorState, rhs: HumiditySensorState) -> Bool {
return lhs.lastUpdated == rhs.lastUpdated &&
lhs.humidity == rhs.humidity
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ public class OpenCloseSensor: Sensor {
required public init?(json: JSON) {
super.init(json: json)
}
}

public func ==(lhs: OpenCloseSensor, rhs: OpenCloseSensor) -> Bool {
return lhs.identifier == rhs.identifier &&
lhs.name == rhs.name &&
lhs.state == rhs.state &&
lhs.config == rhs.config &&
lhs.type == rhs.type &&
lhs.modelId == rhs.modelId &&
lhs.manufacturerName == rhs.manufacturerName &&
lhs.swVersion == rhs.swVersion
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ public class OpenCloseSensorConfig: SensorConfig {
super.init(json: json)
}
}

public func ==(lhs: OpenCloseSensorConfig, rhs: OpenCloseSensorConfig) -> Bool {
return lhs.on == rhs.on &&
lhs.reachable == rhs.reachable &&
lhs.battery == rhs.battery &&
lhs.url == rhs.url
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ public class OpenCloseSensorState: SensorState {
return nil
}
}

public func ==(lhs: OpenCloseSensorState, rhs: OpenCloseSensorState) -> Bool {
return lhs.lastUpdated == rhs.lastUpdated &&
lhs.open == rhs.open
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ public class PresenceSensor: Sensor {
required public init?(json: JSON) {
super.init(json: json)
}
}

public func ==(lhs: PresenceSensor, rhs: PresenceSensor) -> Bool {
return lhs.identifier == rhs.identifier &&
lhs.name == rhs.name &&
lhs.state == rhs.state &&
lhs.config == rhs.config &&
lhs.type == rhs.type &&
lhs.modelId == rhs.modelId &&
lhs.manufacturerName == rhs.manufacturerName &&
lhs.swVersion == rhs.swVersion
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ public class PresenceSensorConfig: SensorConfig {
super.init(json: json)
}
}

public func ==(lhs: PresenceSensorConfig, rhs: PresenceSensorConfig) -> Bool {
return lhs.on == rhs.on &&
lhs.reachable == rhs.reachable &&
lhs.battery == rhs.battery &&
lhs.url == rhs.url
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ public class PresenceSensorState: SensorState {
return nil
}
}

public func ==(lhs: PresenceSensorState, rhs: PresenceSensorState) -> Bool {
return lhs.lastUpdated == rhs.lastUpdated &&
lhs.presence == rhs.presence
}
Loading

0 comments on commit 0c43a5b

Please sign in to comment.