lights 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +6 -0
- data/bin/lights +302 -0
- data/lib/lights.rb +142 -0
- data/lib/lights/bridge.rb +21 -0
- data/lib/lights/bulb.rb +25 -0
- data/lib/lights/bulbstate.rb +183 -0
- data/lib/lights/exception.rb +23 -0
- data/lib/lights/group.rb +16 -0
- data/lib/lights/loggerconfig.rb +5 -0
- data/lib/lights/sensor.rb +31 -0
- data/lib/lights/version.rb +3 -0
- data/lights.gemspec +27 -0
- data/spec/bridge_spec.rb +28 -0
- data/spec/bulb_spec.rb +32 -0
- data/spec/bulbstate_spec.rb +432 -0
- data/spec/features/rue.feature +26 -0
- data/spec/features/support/setup.rb +1 -0
- data/spec/group_spec.rb +23 -0
- metadata +142 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
class Bridge
|
2
|
+
|
3
|
+
attr_reader :id, :ip, :name, :mac
|
4
|
+
|
5
|
+
def initialize(data = {})
|
6
|
+
@id = data["id"]
|
7
|
+
@ip = data["internalipaddress"]
|
8
|
+
@mac = data["macaddress"]
|
9
|
+
@name = data["name"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def data
|
13
|
+
data = {}
|
14
|
+
data["id"] = @id if @id
|
15
|
+
data["internalipaddress"] = @ip if @ip
|
16
|
+
data["macaddress"] = @mac if @mac
|
17
|
+
data["name"] = @name if @name
|
18
|
+
data
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
data/lib/lights/bulb.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'lights/bulbstate'
|
2
|
+
|
3
|
+
class Bulb
|
4
|
+
|
5
|
+
attr_reader :id, :name, :type, :swversion,
|
6
|
+
:state
|
7
|
+
|
8
|
+
def initialize(id,data = {})
|
9
|
+
@id = id
|
10
|
+
@name = data["name"]
|
11
|
+
@type = data["type"]
|
12
|
+
@swversion = data["type"]
|
13
|
+
@state = BulbState.new data["state"]
|
14
|
+
end
|
15
|
+
|
16
|
+
def data
|
17
|
+
data = {}
|
18
|
+
data["name"] = @name if @name
|
19
|
+
data["type"] = @type if @type
|
20
|
+
data["swversion"] = @swversion if @swversion
|
21
|
+
data["state"] = @state.data if !@state.data.empty?
|
22
|
+
data
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,183 @@
|
|
1
|
+
class BulbState
|
2
|
+
|
3
|
+
MAX_CT = 500
|
4
|
+
MIN_CT = 153
|
5
|
+
MAX_BRI = 255
|
6
|
+
MIN_BRI = 0
|
7
|
+
MAX_SAT = 255
|
8
|
+
MIN_SAT = 0
|
9
|
+
MAX_HUE = 65535
|
10
|
+
MIN_HUE = 0
|
11
|
+
MIN_TRANSITION_TIME = 0
|
12
|
+
MAX_XY = 1.0
|
13
|
+
MIN_XY = 0.0
|
14
|
+
|
15
|
+
module Effect
|
16
|
+
NONE = "none"
|
17
|
+
COLORLOOP = "colorloop"
|
18
|
+
end
|
19
|
+
|
20
|
+
module Alert
|
21
|
+
NONE = "none"
|
22
|
+
SELECT = "select"
|
23
|
+
LSELECT = "lselect"
|
24
|
+
end
|
25
|
+
|
26
|
+
module ColorMode
|
27
|
+
HS = "hs"
|
28
|
+
XY = "xy"
|
29
|
+
CT = "ct"
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_reader :on, :bri, :hue, :sat, :xy, :ct,
|
33
|
+
:alert, :effect, :color_mode,
|
34
|
+
:reachable, :transition_time
|
35
|
+
|
36
|
+
def initialize( data = {} )
|
37
|
+
data = {} if data == nil
|
38
|
+
@on = data["on"]
|
39
|
+
set_bri data["bri"]
|
40
|
+
set_hue data["hue"]
|
41
|
+
set_sat data["sat"]
|
42
|
+
set_xy data["xy"]
|
43
|
+
set_ct data["ct"]
|
44
|
+
set_alert data["alert"]
|
45
|
+
set_effect data["effect"]
|
46
|
+
set_color_mode data["colormode"]
|
47
|
+
@reachable = data["reachable"]
|
48
|
+
set_transition_time data["transitiontime"]
|
49
|
+
end
|
50
|
+
|
51
|
+
def color_mode=(value) set_color_mode(value) end
|
52
|
+
def set_color_mode(value)
|
53
|
+
if value.nil? || value == ColorMode::XY \
|
54
|
+
|| value == ColorMode::HS \
|
55
|
+
|| value == ColorMode::CT
|
56
|
+
@color_mode = value
|
57
|
+
else
|
58
|
+
raise BulbStateValueTypeException, "Value has incorrect type. Requires 'hs', 'xy', or 'ct'"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def alert=(value) set_alert(value) end
|
63
|
+
def set_alert(value)
|
64
|
+
if value.nil? || value == Alert::NONE \
|
65
|
+
|| value == Alert::SELECT \
|
66
|
+
|| value == Alert::LSELECT
|
67
|
+
@alert = value
|
68
|
+
else
|
69
|
+
raise BulbStateValueTypeException, "Value has incorrect type. Requires 'none', 'select', or 'lselect'"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def effect=(value) set_effect(value) end
|
74
|
+
def set_effect(value)
|
75
|
+
if value.nil? || value == Effect::NONE || value == Effect::COLORLOOP
|
76
|
+
@effect = value
|
77
|
+
else
|
78
|
+
raise BulbStateValueTypeException, "Value has incorrect type. Requires 'none' or 'colorloop'"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def on=(value) set_on(value) end
|
83
|
+
def set_on(value)
|
84
|
+
# Tests if value is boolean
|
85
|
+
if !!value == value
|
86
|
+
@on = value
|
87
|
+
else
|
88
|
+
raise BulbStateValueTypeException, "Value has incorrect type. Requires boolean, got #{value.class}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def bri=(value); set_bri(value) end
|
93
|
+
def set_bri(value)
|
94
|
+
if value.nil? || value.between?(MIN_BRI,MAX_BRI)
|
95
|
+
@bri = value
|
96
|
+
else
|
97
|
+
raise BulbStateValueOutOfRangeException, "Value out of range. Must be [#{MIN_BRI},#{MAX_BRI}]"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def ct=(value); set_ct(value) end
|
102
|
+
def set_ct(value)
|
103
|
+
if !value.nil? && (!value.is_a? Integer)
|
104
|
+
raise BulbStateValueTypeException, "Value has incorrect type. Requires integer, got #{value.class}"
|
105
|
+
elsif value.nil? || value.between?(MIN_CT,MAX_CT)
|
106
|
+
@ct = value
|
107
|
+
else
|
108
|
+
raise BulbStateValueOutOfRangeException, "Value out of range. Must be [#{MIN_CT},#{MAX_CT}]"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def sat=(value); set_sat(value) end
|
113
|
+
def set_sat(value)
|
114
|
+
if !value.nil? && (!value.is_a? Integer)
|
115
|
+
raise BulbStateValueTypeException, "Value has incorrect type. Requires integer, got #{value.class}"
|
116
|
+
elsif value.nil? || value.between?(MIN_SAT,MAX_SAT)
|
117
|
+
@sat = value
|
118
|
+
else
|
119
|
+
raise BulbStateValueOutOfRangeException, "Value out of range. Must be [#{MIN_SAT},#{MAX_SAT}]"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def hue=(value); set_hue(value) end
|
124
|
+
def set_hue(value)
|
125
|
+
if !value.nil? && (!value.is_a? Integer)
|
126
|
+
raise BulbStateValueTypeException, "Value has incorrect type. Requires integer, got #{value.class}"
|
127
|
+
elsif value.nil? || value.between?(MIN_HUE,MAX_HUE)
|
128
|
+
@hue = value
|
129
|
+
else
|
130
|
+
raise BulbStateValueOutOfRangeException, "Value out of range. Must be [#{MIN_HUE},#{MAX_HUE}]"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def transition_time=(value); set_transition_time(value) end
|
135
|
+
def set_transition_time(value)
|
136
|
+
if !value.nil? && (!value.is_a? Numeric)
|
137
|
+
raise BulbStateValueTypeException, "Value has incorrect type. Requires decimal, got #{value.class}"
|
138
|
+
elsif value.nil? || value >= MIN_TRANSITION_TIME
|
139
|
+
@transition_time = value
|
140
|
+
else
|
141
|
+
raise BulbStateValueOutOfRangeException, "Value out of range. Must be > #{MIN_TRANSITION_TIME}"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def xy=(value); set_xy(value) end
|
146
|
+
def set_xy(value)
|
147
|
+
if !value.nil? && (!value.is_a? Array)
|
148
|
+
raise BulbStateValueTypeException, "Value has incorrect type. Requires array, got #{value.class}"
|
149
|
+
elsif value.nil?
|
150
|
+
return
|
151
|
+
elsif value.length == 2 && value[0].to_f.is_a?(Numeric) \
|
152
|
+
&& value[1].to_f.is_a?(Numeric) && value[0].to_f >= MIN_XY \
|
153
|
+
&& value[0].to_f <= MAX_XY && value[1].to_f >= MIN_XY \
|
154
|
+
&& value[1].to_f <= MAX_XY
|
155
|
+
@xy = []
|
156
|
+
@xy[0] = value[0].to_f
|
157
|
+
@xy[1] = value[1].to_f
|
158
|
+
else
|
159
|
+
raise BulbStateValueOutOfRangeException, "Value out of range. Must be [#{MIN_XY},#{MAX_XY}]"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def data
|
164
|
+
data = {}
|
165
|
+
data["on"] = @on if (@on!=nil)
|
166
|
+
data["bri"] = @bri if @bri
|
167
|
+
data["hue"] = @hue if @hue
|
168
|
+
data["sat"] = @sat if @sat
|
169
|
+
data["xy"] = @xy if @xy
|
170
|
+
data["ct"] = @ct if @ct
|
171
|
+
data["alert"] = @alert if @alert
|
172
|
+
data["effect"] = @effect if @effect
|
173
|
+
data["colormode"] = @color_mode if @color_mode
|
174
|
+
data["reachable"] = @reachable if @reachable
|
175
|
+
data["transitiontime"] = @transition_time if @transition_time
|
176
|
+
data
|
177
|
+
end
|
178
|
+
|
179
|
+
def to_json
|
180
|
+
data.to_json
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class BridgeConnectException < Exception
|
2
|
+
def initialize(msg = "Press the button on the Hue bridge and try again.")
|
3
|
+
super
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class UsernameException < Exception
|
8
|
+
def initialize(msg = "Please register username and try again.")
|
9
|
+
super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class BulbStateValueOutOfRangeException < Exception
|
14
|
+
def initalize(msg = "Value out of range.")
|
15
|
+
super(msg)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class BulbStateValueTypeException < Exception
|
20
|
+
def initialize(msg = "Value is of incorrect type.")
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
data/lib/lights/group.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
class Group
|
2
|
+
|
3
|
+
attr_reader :id, :data, :name, :lights
|
4
|
+
def initialize( id, data = {} )
|
5
|
+
@id = id
|
6
|
+
@data = data
|
7
|
+
@action = BulbState.new(data["action"])
|
8
|
+
@name = data["name"]
|
9
|
+
@lights = data["lights"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def action
|
13
|
+
@action.data
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class SensorState
|
2
|
+
attr_reader :data, :last_updated
|
3
|
+
def initialize(data)
|
4
|
+
@data = data
|
5
|
+
@last_updated = data["lastupdated"]
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class TapState < SensorState
|
10
|
+
attr_reader :button_event
|
11
|
+
def initialize(data)
|
12
|
+
@button_event = data["button_event"]
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Sensor
|
18
|
+
attr_reader :id, :data, :name, :type, :model_id, :manufacturer_name, :unique_id, :sw_version, :state
|
19
|
+
def initialize( id, data = {} )
|
20
|
+
@id = id
|
21
|
+
@data = data
|
22
|
+
@name = data["name"]
|
23
|
+
@type = data["type"]
|
24
|
+
@model_id = data["modelid"]
|
25
|
+
@manufacturer_name = data["manufacturername"]
|
26
|
+
@unique_id = data["uniqueid"]
|
27
|
+
@sw_version = data["swversion"]
|
28
|
+
@state = SensorState.new(data["state"])
|
29
|
+
#@config = SensorConfig.new(data["config"])
|
30
|
+
end
|
31
|
+
end
|
data/lights.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lights/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'lights'
|
8
|
+
s.version = LightsConst::VERSION
|
9
|
+
s.authors = ["Brady Turner"]
|
10
|
+
s.email = 'bradyaturner@gmail.com'
|
11
|
+
s.description = "Client library and CLI for controlling Phillips Hue lights."
|
12
|
+
s.summary = "lights"
|
13
|
+
s.homepage = 'http://rubygems.org/gems/lights'
|
14
|
+
s.license = 'MIT'
|
15
|
+
s.date = '2014-08-17'
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split($/)
|
18
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
s.add_development_dependency "rake"
|
24
|
+
s.add_development_dependency "rspec", "~> 2.6"
|
25
|
+
s.add_development_dependency "cucumber"
|
26
|
+
s.add_development_dependency "aruba"
|
27
|
+
end
|
data/spec/bridge_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'lights'
|
2
|
+
|
3
|
+
describe Bridge do
|
4
|
+
it "properly parse input parameters" do
|
5
|
+
data = {
|
6
|
+
"id" => "test id",
|
7
|
+
"internalipaddress" => "192.168.1.27",
|
8
|
+
"macaddress" => "01:23:45:67:89:AB",
|
9
|
+
"name" => "test name",
|
10
|
+
}
|
11
|
+
bridge = Bridge.new(data)
|
12
|
+
bridge.id.should eql "test id"
|
13
|
+
bridge.ip.should eql "192.168.1.27"
|
14
|
+
bridge.mac.should eql "01:23:45:67:89:AB"
|
15
|
+
bridge.name.should eql "test name"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "properly reconstructs object hash" do
|
19
|
+
data = {
|
20
|
+
"id" => "test id",
|
21
|
+
"internalipaddress" => "192.168.1.27",
|
22
|
+
"macaddress" => "01:23:45:67:89:AB",
|
23
|
+
"name" => "test name",
|
24
|
+
}
|
25
|
+
bridge = Bridge.new(data)
|
26
|
+
bridge.data.should eql data
|
27
|
+
end
|
28
|
+
end
|
data/spec/bulb_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'lights'
|
2
|
+
|
3
|
+
describe Bulb do
|
4
|
+
it "properly parse input parameters" do
|
5
|
+
data = { "name" => "test name" }
|
6
|
+
bulb = Bulb.new(1,data)
|
7
|
+
bulb.name.should eql "test name"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "properly creates state object" do
|
11
|
+
data = {
|
12
|
+
"name" => "test name",
|
13
|
+
"state" => {
|
14
|
+
"on" => true
|
15
|
+
}
|
16
|
+
}
|
17
|
+
bulb = Bulb.new(1,data)
|
18
|
+
bulb.state.on.should eql true
|
19
|
+
bulb.state.data.should eql data["state"]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "properly reconstucts object hash" do
|
23
|
+
data = {
|
24
|
+
"name" => "test name",
|
25
|
+
"state" => {
|
26
|
+
"on" => true
|
27
|
+
}
|
28
|
+
}
|
29
|
+
bulb = Bulb.new(1,data)
|
30
|
+
bulb.data.should eql data
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,432 @@
|
|
1
|
+
require 'lights'
|
2
|
+
|
3
|
+
describe BulbState do
|
4
|
+
|
5
|
+
it "properly reconstructs object hash" do
|
6
|
+
data = { "on" => true }
|
7
|
+
state = BulbState.new(data)
|
8
|
+
state.data.should eql data
|
9
|
+
end
|
10
|
+
|
11
|
+
it "properly reconstructs object hash" do
|
12
|
+
data = { "on" => false }
|
13
|
+
state = BulbState.new(data)
|
14
|
+
state.data.should eql data
|
15
|
+
end
|
16
|
+
|
17
|
+
# ON
|
18
|
+
it "should properly set on value in constructor" do
|
19
|
+
data = { "on" => true }
|
20
|
+
bulb = BulbState.new(data)
|
21
|
+
bulb.on.should eql true
|
22
|
+
end
|
23
|
+
it "should properly set on value" do
|
24
|
+
b = BulbState.new
|
25
|
+
b.on = true
|
26
|
+
b.on.should eq true
|
27
|
+
end
|
28
|
+
it "should raise exception when on has invalid type" do
|
29
|
+
b = BulbState.new
|
30
|
+
expect { b.on = "test state" }.to raise_error
|
31
|
+
end
|
32
|
+
|
33
|
+
# BRI
|
34
|
+
it "should properly set brightness value in constructor" do
|
35
|
+
data = { "bri" => BulbState::MAX_BRI }
|
36
|
+
b = BulbState.new(data)
|
37
|
+
b.bri.should eq BulbState::MAX_BRI
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should properly set brightness value in constructor" do
|
41
|
+
data = { "bri" => BulbState::MIN_BRI }
|
42
|
+
b = BulbState.new(data)
|
43
|
+
b.bri.should eq BulbState::MIN_BRI
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should properly set brightness value" do
|
47
|
+
b = BulbState.new
|
48
|
+
b.bri = BulbState::MAX_BRI
|
49
|
+
b.bri.should eq BulbState::MAX_BRI
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should properly set brightness value" do
|
53
|
+
b = BulbState.new
|
54
|
+
b.bri = BulbState::MIN_BRI
|
55
|
+
b.bri.should eq BulbState::MIN_BRI
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should raise exception when brightness value is not an integer" do
|
59
|
+
data = { "bri" => "test value" }
|
60
|
+
expect { BulbState.new(data) }.to raise_error
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should raise exception when initial brightness is out of range (high)" do
|
64
|
+
data = { "bri" => BulbState::MAX_BRI + 1 }
|
65
|
+
expect { BulbState.new(data) }.to raise_error
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should raise exception when initial brightness is out of range (low)" do
|
69
|
+
data = { "bri" => BulbState::MIN_BRI - 1 }
|
70
|
+
expect { BulbState.new(data) }.to raise_error
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should raise exception when set brightness is out of range (high)" do
|
74
|
+
b = BulbState.new()
|
75
|
+
expect { b.bri = BulbState::MAX_BRI + 1 }.to raise_error
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should raise exception when set brightness is out of range (LOW)" do
|
79
|
+
b = BulbState.new()
|
80
|
+
expect { b.bri = BulbState::MIN_BRI - 1 }.to raise_error
|
81
|
+
end
|
82
|
+
|
83
|
+
# SAT
|
84
|
+
it "should properly set saturation value in constructor" do
|
85
|
+
data = { "sat" => BulbState::MAX_SAT }
|
86
|
+
b = BulbState.new(data)
|
87
|
+
b.sat.should eq BulbState::MAX_SAT
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should properly set saturation value in constructor" do
|
91
|
+
data = { "sat" => BulbState::MIN_SAT }
|
92
|
+
b = BulbState.new(data)
|
93
|
+
b.sat.should eq BulbState::MIN_SAT
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should properly set saturation value" do
|
97
|
+
b = BulbState.new
|
98
|
+
b.sat = BulbState::MAX_SAT
|
99
|
+
b.sat.should eq BulbState::MAX_SAT
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should properly set saturation value" do
|
103
|
+
b = BulbState.new
|
104
|
+
b.sat = BulbState::MIN_SAT
|
105
|
+
b.sat.should eq BulbState::MIN_SAT
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should raise exception when sat value is not an integer" do
|
109
|
+
data = { "sat" => "test value" }
|
110
|
+
expect { BulbState.new(data) }.to raise_error
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should raise exception when initial saturation is out of range (high)" do
|
114
|
+
data = { "sat" => BulbState::MAX_SAT + 1 }
|
115
|
+
expect { BulbState.new(data) }.to raise_error
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should raise exception when initial saturation is out of range (low)" do
|
119
|
+
data = { "sat" => BulbState::MIN_SAT - 1 }
|
120
|
+
expect { BulbState.new(data) }.to raise_error
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should raise exception when set saturation is out of range (high)" do
|
124
|
+
b = BulbState.new()
|
125
|
+
expect { b.sat = BulbState::MAX_SAT + 1 }.to raise_error
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should raise exception when set saturation is out of range (LOW)" do
|
129
|
+
b = BulbState.new()
|
130
|
+
expect { b.sat = BulbState::MIN_SAT - 1 }.to raise_error
|
131
|
+
end
|
132
|
+
|
133
|
+
# HUE
|
134
|
+
it "should properly set hue value in constructor" do
|
135
|
+
data = { "hue" => BulbState::MAX_HUE }
|
136
|
+
b = BulbState.new(data)
|
137
|
+
b.hue.should eq BulbState::MAX_HUE
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should properly set hue value in constructor" do
|
141
|
+
data = { "hue" => BulbState::MIN_HUE }
|
142
|
+
b = BulbState.new(data)
|
143
|
+
b.hue.should eq BulbState::MIN_HUE
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should properly set hue value" do
|
147
|
+
b = BulbState.new
|
148
|
+
b.hue = BulbState::MAX_HUE
|
149
|
+
b.hue.should eq BulbState::MAX_HUE
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should properly set hue value" do
|
153
|
+
b = BulbState.new
|
154
|
+
b.hue = BulbState::MIN_HUE
|
155
|
+
b.hue.should eq BulbState::MIN_HUE
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should raise exception when hue value is not an integer" do
|
159
|
+
data = { "hue" => "test value" }
|
160
|
+
expect { BulbState.new(data) }.to raise_error
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should raise exception when initial hue is out of range (high)" do
|
164
|
+
data = { "hue" => BulbState::MAX_HUE + 1 }
|
165
|
+
expect { BulbState.new(data) }.to raise_error
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should raise exception when initial hue is out of range (low)" do
|
169
|
+
data = { "hue" => BulbState::MIN_HUE - 1 }
|
170
|
+
expect { BulbState.new(data) }.to raise_error
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should raise exception when set hue is out of range (high)" do
|
174
|
+
b = BulbState.new()
|
175
|
+
expect { b.hue = BulbState::MAX_HUE + 1 }.to raise_error
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should raise exception when set hue is out of range (LOW)" do
|
179
|
+
b = BulbState.new()
|
180
|
+
expect { b.hue = BulbState::MIN_HUE - 1 }.to raise_error
|
181
|
+
end
|
182
|
+
|
183
|
+
# CT
|
184
|
+
it "should properly set color temperature value in constructor" do
|
185
|
+
data = { "ct" => BulbState::MAX_CT }
|
186
|
+
b = BulbState.new(data)
|
187
|
+
b.ct.should eq BulbState::MAX_CT
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should properly set color temperature value in constructor" do
|
191
|
+
data = { "ct" => BulbState::MIN_CT }
|
192
|
+
b = BulbState.new(data)
|
193
|
+
b.ct.should eq BulbState::MIN_CT
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should properly set color temperature value" do
|
197
|
+
b = BulbState.new
|
198
|
+
b.ct = BulbState::MAX_CT
|
199
|
+
b.ct.should eq BulbState::MAX_CT
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should properly set color temperature value" do
|
203
|
+
b = BulbState.new
|
204
|
+
b.ct = BulbState::MIN_CT
|
205
|
+
b.ct.should eq BulbState::MIN_CT
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should raise exception when color temperature value is not an integer" do
|
209
|
+
data = { "ct" => "test value" }
|
210
|
+
expect { BulbState.new(data) }.to raise_error
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should raise exception when initial color temperature is out of range (high)" do
|
214
|
+
data = { "ct" => BulbState::MAX_CT + 1 }
|
215
|
+
expect { BulbState.new(data) }.to raise_error
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should raise exception when initial color temperature is out of range (low)" do
|
219
|
+
data = { "ct" => BulbState::MIN_CT - 1 }
|
220
|
+
expect { BulbState.new(data) }.to raise_error
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should raise exception when set color temperature is out of range (high)" do
|
224
|
+
b = BulbState.new()
|
225
|
+
expect { b.ct = BulbState::MAX_CT + 1 }.to raise_error
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should raise exception when set color temperature is out of range (LOW)" do
|
229
|
+
b = BulbState.new()
|
230
|
+
expect { b.ct = BulbState::MIN_CT - 1 }.to raise_error
|
231
|
+
end
|
232
|
+
|
233
|
+
# EFFECT
|
234
|
+
it "should properly set effect value in constructor" do
|
235
|
+
data = { "effect" => BulbState::Effect::COLORLOOP }
|
236
|
+
b = BulbState.new(data)
|
237
|
+
b.effect.should eq BulbState::Effect::COLORLOOP
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should properly set effect value in constructor" do
|
241
|
+
data = { "effect" => BulbState::Effect::COLORLOOP }
|
242
|
+
b = BulbState.new(data)
|
243
|
+
b.effect.should eq BulbState::Effect::COLORLOOP
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should properly set effect value" do
|
247
|
+
b = BulbState.new
|
248
|
+
b.effect = BulbState::Effect::COLORLOOP
|
249
|
+
b.effect.should eq BulbState::Effect::COLORLOOP
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should properly set effect value" do
|
253
|
+
b = BulbState.new
|
254
|
+
b.effect = BulbState::Effect::NONE
|
255
|
+
b.effect.should eq BulbState::Effect::NONE
|
256
|
+
end
|
257
|
+
|
258
|
+
it "should raise exception when effect value is invalid" do
|
259
|
+
data = { "effect" => "test value" }
|
260
|
+
expect { BulbState.new(data) }.to raise_error
|
261
|
+
end
|
262
|
+
|
263
|
+
# TRANSITION TIME
|
264
|
+
it "should properly set transition time value in constructor" do
|
265
|
+
data = { "transitiontime" => 0.1 }
|
266
|
+
b = BulbState.new(data)
|
267
|
+
b.transition_time.should eq 0.1
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should properly set transition time value" do
|
271
|
+
b = BulbState.new
|
272
|
+
b.transition_time = BulbState::MIN_TRANSITION_TIME
|
273
|
+
b.transition_time.should eq BulbState::MIN_TRANSITION_TIME
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should raise exception when transition time value is invalid" do
|
277
|
+
data = { "transitiontime" => "test value" }
|
278
|
+
expect { BulbState.new(data) }.to raise_error
|
279
|
+
end
|
280
|
+
|
281
|
+
it "should raise exception when transition time is out of range (LOW)" do
|
282
|
+
data = { "transitiontime" => -1 }
|
283
|
+
expect { BulbState.new(data) }.to raise_error
|
284
|
+
end
|
285
|
+
|
286
|
+
# ALERT
|
287
|
+
it "should properly set alert value in constructor" do
|
288
|
+
data = { "alert" => BulbState::Alert::SELECT }
|
289
|
+
b = BulbState.new(data)
|
290
|
+
b.alert.should eq BulbState::Alert::SELECT
|
291
|
+
end
|
292
|
+
|
293
|
+
it "should properly set alert value" do
|
294
|
+
b = BulbState.new
|
295
|
+
b.alert = BulbState::Alert::LSELECT
|
296
|
+
b.alert.should eq BulbState::Alert::LSELECT
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should properly set alert value" do
|
300
|
+
b = BulbState.new
|
301
|
+
b.alert = BulbState::Alert::NONE
|
302
|
+
b.alert.should eq BulbState::Alert::NONE
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should raise exception when alert value is invalid" do
|
306
|
+
data = { "alert" => "test value" }
|
307
|
+
expect { BulbState.new(data) }.to raise_error
|
308
|
+
end
|
309
|
+
|
310
|
+
# COLORMODE
|
311
|
+
it "should properly set color mode value in constructor" do
|
312
|
+
data = { "colormode" => BulbState::ColorMode::HS }
|
313
|
+
b = BulbState.new(data)
|
314
|
+
b.color_mode.should eq BulbState::ColorMode::HS
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should properly set color mode value" do
|
318
|
+
b = BulbState.new
|
319
|
+
b.color_mode = BulbState::ColorMode::XY
|
320
|
+
b.color_mode.should eq BulbState::ColorMode::XY
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should properly set color mode value" do
|
324
|
+
b = BulbState.new
|
325
|
+
b.color_mode = BulbState::ColorMode::CT
|
326
|
+
b.color_mode.should eq BulbState::ColorMode::CT
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should raise exception when alert value is invalid" do
|
330
|
+
data = { "colormode" => "test value" }
|
331
|
+
expect { BulbState.new(data) }.to raise_error
|
332
|
+
end
|
333
|
+
|
334
|
+
# XY
|
335
|
+
it "should properly set xy value in constructor" do
|
336
|
+
xy = [BulbState::MAX_XY,BulbState::MAX_XY]
|
337
|
+
data = { "xy" => xy }
|
338
|
+
b = BulbState.new(data)
|
339
|
+
b.xy.should eq xy
|
340
|
+
end
|
341
|
+
|
342
|
+
it "should properly set xy value in constructor" do
|
343
|
+
xy = [BulbState::MIN_XY,BulbState::MIN_XY]
|
344
|
+
data = { "xy" => xy }
|
345
|
+
b = BulbState.new(data)
|
346
|
+
b.xy.should eq xy
|
347
|
+
end
|
348
|
+
|
349
|
+
it "should properly set xy value" do
|
350
|
+
b = BulbState.new
|
351
|
+
xy = [BulbState::MAX_XY,BulbState::MAX_XY]
|
352
|
+
b.xy = xy
|
353
|
+
b.xy.should eq xy
|
354
|
+
end
|
355
|
+
|
356
|
+
it "should properly set xy value" do
|
357
|
+
b = BulbState.new
|
358
|
+
xy = [BulbState::MIN_XY,BulbState::MIN_XY]
|
359
|
+
b.xy = xy
|
360
|
+
b.xy.should eq xy
|
361
|
+
end
|
362
|
+
|
363
|
+
it "should raise exception when xy value is not an array" do
|
364
|
+
xy = {}
|
365
|
+
data = { "xy" => xy }
|
366
|
+
expect { BulbState.new(data) }.to raise_error
|
367
|
+
end
|
368
|
+
|
369
|
+
# XY - X
|
370
|
+
it "should raise exception when x value is not a number" do
|
371
|
+
xy = ["test value",BulbState::MIN_XY]
|
372
|
+
data = { "xy" => xy }
|
373
|
+
expect { BulbState.new(data) }.to raise_error
|
374
|
+
end
|
375
|
+
|
376
|
+
it "should raise exception when initial xy is out of range (X,HIGH)" do
|
377
|
+
xy = [BulbState::MAX_XY+1,BulbState::MIN_XY]
|
378
|
+
data = { "xy" => xy }
|
379
|
+
expect { BulbState.new(data) }.to raise_error
|
380
|
+
end
|
381
|
+
|
382
|
+
it "should raise exception when initial xy is out of range (X,LOW)" do
|
383
|
+
xy = [BulbState::MIN_XY-1,BulbState::MIN_XY]
|
384
|
+
data = { "xy" => xy }
|
385
|
+
expect { BulbState.new(data) }.to raise_error
|
386
|
+
end
|
387
|
+
|
388
|
+
it "should raise exception when set xy is out of range (X,HIGH)" do
|
389
|
+
xy = [BulbState::MAX_XY+1,BulbState::MIN_XY]
|
390
|
+
b = BulbState.new()
|
391
|
+
expect { b.xy = xy }.to raise_error
|
392
|
+
end
|
393
|
+
|
394
|
+
it "should raise exception when set xy is out of range (X,LOW)" do
|
395
|
+
xy = [BulbState::MIN_XY-1,BulbState::MIN_XY]
|
396
|
+
b = BulbState.new()
|
397
|
+
expect { b.xy = xy }.to raise_error
|
398
|
+
end
|
399
|
+
|
400
|
+
# XY - Y
|
401
|
+
it "should raise exception when y value is not a number" do
|
402
|
+
xy = [BulbState::MIN_XY,"test value"]
|
403
|
+
data = { "xy" => xy }
|
404
|
+
expect { BulbState.new(data) }.to raise_error
|
405
|
+
end
|
406
|
+
|
407
|
+
it "should raise exception when initial xy is out of range (Y,HIGH)" do
|
408
|
+
xy = [BulbState::MIN_XY,BulbState::MAX_XY+1]
|
409
|
+
data = { "xy" => xy }
|
410
|
+
expect { BulbState.new(data) }.to raise_error
|
411
|
+
end
|
412
|
+
|
413
|
+
it "should raise exception when initial xy is out of range (Y,LOW)" do
|
414
|
+
xy = [BulbState::MIN_XY,BulbState::MIN_XY-1]
|
415
|
+
data = { "xy" => xy }
|
416
|
+
expect { BulbState.new(data) }.to raise_error
|
417
|
+
end
|
418
|
+
|
419
|
+
it "should raise exception when set xy is out of range (Y,HIGH)" do
|
420
|
+
xy = [BulbState::MAX_XY,BulbState::MAX_XY+1]
|
421
|
+
b = BulbState.new()
|
422
|
+
expect { b.xy = xy }.to raise_error
|
423
|
+
end
|
424
|
+
|
425
|
+
it "should raise exception when set xy is out of range (Y,LOW)" do
|
426
|
+
xy = [BulbState::MIN_XY,BulbState::MIN_XY-1]
|
427
|
+
b = BulbState.new()
|
428
|
+
expect { b.xy = xy }.to raise_error
|
429
|
+
end
|
430
|
+
|
431
|
+
end
|
432
|
+
|