Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Spriter committed May 19, 2016
1 parent 791b53b commit 721c702
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions SwiftyHue/Classes/BridgeResourceModels/LightState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,8 @@
import Foundation
import Gloss

public func ==(lhs: LightState, rhs: LightState) -> Bool {
return (lhs.on ?? false) == (rhs.on ?? false) &&
lhs.brightness == rhs.brightness &&
(lhs.hue ?? -1) == (rhs.hue ?? -1) &&
(lhs.saturation ?? -1) == (rhs.saturation ?? -1) &&
(lhs.xy ?? [-1, -1]) == (rhs.xy ?? [-1, -1]) &&
lhs.ct == rhs.ct &&
lhs.alert == rhs.alert &&
lhs.effect == rhs.effect &&
lhs.colormode == rhs.colormode &&
lhs.reachable == rhs.reachable
}

public struct LightState: Decodable, Encodable {

public var hashValue: Int {
return (self.brightness ?? 0) + (self.hue ?? 0) + (self.saturation ?? 0)
}

/**
The on off status to set the light to.
true means on, false means off.
Expand Down Expand Up @@ -101,4 +84,24 @@ public struct LightState: Decodable, Encodable {

])
}
}

extension LightState: Hashable {

public var hashValue: Int {
return (self.brightness ?? 0) + (self.hue ?? 0) + (self.saturation ?? 0)
}
}

public func ==(lhs: LightState, rhs: LightState) -> Bool {
return lhs.on == rhs.on &&
lhs.brightness == rhs.brightness &&
lhs.hue == rhs.hue &&
lhs.saturation == rhs.saturation &&
(lhs.xy ?? [-1, -1]) == (rhs.xy ?? [-1, -1]) &&
lhs.ct == rhs.ct &&
lhs.alert == rhs.alert &&
lhs.effect == rhs.effect &&
lhs.colormode == rhs.colormode &&
lhs.reachable == rhs.reachable
}

0 comments on commit 721c702

Please sign in to comment.