huey 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +3 -2
- data/Gemfile.lock +3 -1
- data/README.markdown +22 -16
- data/lib/huey/bulb.rb +9 -3
- data/lib/huey/group.rb +12 -4
- data/lib/huey/version.rb +1 -1
- data/test/test_helper.rb +5 -4
- data/test/unit/bulb_test.rb +7 -4
- data/test/unit/event_test.rb +1 -1
- data/test/unit/group_test.rb +33 -1
- data/test/unit/portal_test.rb +8 -4
- data/test/unit/request_test.rb +3 -2
- data/test/unit/ssdp_test.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 426fd9b03d93002081cb9226ff446bd7a094baf6
|
4
|
+
data.tar.gz: c54af8d42bcf2bc9d673d594351f059ddbac1b48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 729bbc4e6b64c4291d4e8b0b50c4bf9af2619674e1c44a8ab30c29deaee37b6dcded0785ca6031dee37d06d950c005ecdd8c699f3b4b31204e4203ce704e37eb
|
7
|
+
data.tar.gz: ef68f85d7fe6f7d356fad8494dfd69c3192d85a96a63744d50e1681ac532f5a2b03b3537906de09519d48b30bf9614605cee0cc161bc845ff563cb74b0bf8cf6
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
huey (2.0.
|
4
|
+
huey (2.0.1)
|
5
5
|
chronic (>= 0.9.0)
|
6
6
|
color (>= 1.4.1)
|
7
7
|
eventmachine (>= 1.0.0)
|
@@ -22,6 +22,7 @@ GEM
|
|
22
22
|
multi_xml (>= 0.5.2)
|
23
23
|
json (1.8.1)
|
24
24
|
metaclass (0.0.1)
|
25
|
+
minitest (5.0.8)
|
25
26
|
mocha (0.13.1)
|
26
27
|
metaclass (~> 0.0.1)
|
27
28
|
multi_json (1.8.2)
|
@@ -41,6 +42,7 @@ DEPENDENCIES
|
|
41
42
|
chronic
|
42
43
|
color-tools
|
43
44
|
huey!
|
45
|
+
minitest
|
44
46
|
mocha
|
45
47
|
rake
|
46
48
|
timecop
|
data/README.markdown
CHANGED
@@ -14,21 +14,23 @@ You shouldn't need to initialize anything to make Huey work correctly, but if yo
|
|
14
14
|
|
15
15
|
```ruby
|
16
16
|
Huey.configure do |config|
|
17
|
-
# Huey now uses the Phillips Hue API to discover local bridges, but you can
|
18
|
-
# manually if your Huey server is not on your
|
17
|
+
# Huey now uses the Phillips Hue API to discover local bridges, but you can
|
18
|
+
# specify the Hue IP manually if your Huey server is not on your
|
19
|
+
# local network.
|
19
20
|
config.hue_ip = '123.456.789.012'
|
20
21
|
|
21
|
-
# SSDP is disabled by default.
|
22
|
+
# SSDP is disabled by default. Do not enable it unless you have a compelling
|
23
|
+
# reason to do so.
|
22
24
|
config.ssdp = true
|
23
25
|
|
24
|
-
#
|
26
|
+
# Specify the SSDP IP. Do not use this unless you're using SSDP broadcasting
|
27
|
+
# at a non-standard IP.
|
25
28
|
config.ssdp_ip = '239.255.255.250'
|
26
29
|
|
27
|
-
#
|
30
|
+
# As per the above, but for a non-standard port.
|
28
31
|
config.ssdp_port = 1900
|
29
32
|
|
30
|
-
# If
|
31
|
-
# it's connected, increase this.
|
33
|
+
# If your SSDP connections keep timing out, increase this.
|
32
34
|
config.ssdp_ttl = 1
|
33
35
|
|
34
36
|
# Change this if you don't like the included uuid.
|
@@ -49,25 +51,27 @@ Just like the message says, go press the link button on your Hue hub, and then r
|
|
49
51
|
### Bulbs
|
50
52
|
|
51
53
|
```ruby
|
52
|
-
Huey::Bulb.all # Returns an array of your bulbs
|
53
|
-
|
54
54
|
bulb = Huey::Bulb.find(1) # Finds the bulb with the ID of 1
|
55
55
|
bulb = Huey::Bulb.find('Living Room') # Finds the bulb with the name 'Living Room'
|
56
56
|
|
57
|
-
bulb.alert! # Flashes the bulb in question once and immediately, useful
|
57
|
+
bulb.alert! # Flashes the bulb in question once and immediately, useful
|
58
|
+
# for checking connectivity
|
58
59
|
|
59
60
|
bulb.bri = 100 # Let's dim the bulb a little bit
|
60
|
-
bulb.ct = 500
|
61
|
-
|
62
|
-
bulb.save # Apply all the changes you've made
|
61
|
+
bulb.ct = 500 # And make it a little more orange
|
62
|
+
bulb.save # Apply all the changes you've made
|
63
63
|
|
64
64
|
bulb.update(bri: 100, ct: 500) # Set and save in one step
|
65
65
|
|
66
66
|
bulb.rgb = '#8FF1F5' # Everyone loves aqua
|
67
|
-
|
68
|
-
bulb.commit # Alias for save
|
67
|
+
bulb.commit # Alias for save
|
69
68
|
|
70
69
|
bulb.reload # Refresh changes to the bulb, made perhaps with another app
|
70
|
+
|
71
|
+
Huey::Bulb.all # Returns an array of your bulbs
|
72
|
+
Huey::Bulb.all.alert! # Makes all your bulbs start flashing
|
73
|
+
Huey::Bulb.all.update(bri: 255, on: true) # Turn on all your bulbs and
|
74
|
+
# increase brightness to max
|
71
75
|
```
|
72
76
|
|
73
77
|
Changes to the bulb only take effect when you call `save` on it. If you prefer, `save` is aliased as `commit`.
|
@@ -90,7 +94,9 @@ I've added in some convenience attributes as well:
|
|
90
94
|
|
91
95
|
### Groups
|
92
96
|
|
93
|
-
|
97
|
+
Returned arrays of bulbs are grouped into a convenience class called `Huey::Group`. It acts like an array, but any huey-specific method you pass in will be invoked on all the bulbs.
|
98
|
+
|
99
|
+
You can also simply and sensibly create groups of bulbs yourself if you like.
|
94
100
|
|
95
101
|
```ruby
|
96
102
|
Huey::Group.new('Living Room') # Contains all bulbs that have 'Living Room' in their name
|
data/lib/huey/bulb.rb
CHANGED
@@ -8,9 +8,13 @@ module Huey
|
|
8
8
|
attr_reader :id
|
9
9
|
|
10
10
|
def self.all
|
11
|
-
@all
|
12
|
-
|
11
|
+
return @all if @all
|
12
|
+
|
13
|
+
@all = Huey::Group.new
|
14
|
+
Huey::Request.get['lights'].collect do |id, hash|
|
15
|
+
@all.bulbs << Bulb.new(id, hash)
|
13
16
|
end
|
17
|
+
@all
|
14
18
|
end
|
15
19
|
|
16
20
|
def self.find(id)
|
@@ -18,7 +22,9 @@ module Huey
|
|
18
22
|
end
|
19
23
|
|
20
24
|
def self.find_all(id)
|
21
|
-
|
25
|
+
group = Huey::Group.new
|
26
|
+
self.all.select {|b| b.id == id || b.name.include?(id.to_s)}.each {|b| group.bulbs << b}
|
27
|
+
group
|
22
28
|
end
|
23
29
|
|
24
30
|
def initialize(id, hash)
|
data/lib/huey/group.rb
CHANGED
@@ -4,6 +4,7 @@ module Huey
|
|
4
4
|
|
5
5
|
# A group is a collection of bulbs.
|
6
6
|
class Group
|
7
|
+
include Enumerable
|
7
8
|
ATTRIBUTES = Huey::Bulb::ATTRIBUTES - [:name, :reachable] + [:rgb]
|
8
9
|
attr_accessor :bulbs, :name
|
9
10
|
|
@@ -26,6 +27,7 @@ module Huey
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def initialize(*string_or_array)
|
30
|
+
@bulbs = []
|
29
31
|
string_or_array = string_or_array.first if string_or_array.first.is_a?(Array)
|
30
32
|
|
31
33
|
self.bulbs = if string_or_array.first.is_a?(Bulb)
|
@@ -35,7 +37,7 @@ module Huey
|
|
35
37
|
end
|
36
38
|
|
37
39
|
@attributes_to_write = {}
|
38
|
-
Huey::Group.all << self
|
40
|
+
Huey::Group.all << self unless self.bulbs.nil? || self.bulbs.empty?
|
39
41
|
self
|
40
42
|
end
|
41
43
|
|
@@ -46,21 +48,27 @@ module Huey
|
|
46
48
|
end
|
47
49
|
|
48
50
|
def save
|
49
|
-
response =
|
51
|
+
response = self.collect {|b| b.update(@attributes_to_write)}
|
50
52
|
@attributes_to_write = {}
|
51
53
|
response
|
52
54
|
end
|
53
55
|
alias :commit :save
|
54
56
|
|
55
57
|
def update(attrs)
|
56
|
-
|
58
|
+
self.collect {|b| b.update(attrs)}
|
59
|
+
end
|
60
|
+
|
61
|
+
def each(&block)
|
62
|
+
bulbs.each {|b| block.call(b)}
|
57
63
|
end
|
58
64
|
|
59
65
|
def method_missing(meth, *args, &block)
|
60
66
|
if !self.bulbs.empty? && self.bulbs.first.respond_to?(meth)
|
61
67
|
h = {}
|
62
|
-
|
68
|
+
self.each {|b| h[b.id] = b.send(meth, *args, &block)}
|
63
69
|
h
|
70
|
+
elsif self.bulbs.respond_to?(meth)
|
71
|
+
bulbs.send(meth, *args, &block)
|
64
72
|
else
|
65
73
|
super
|
66
74
|
end
|
data/lib/huey/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
require '
|
2
|
-
require 'webmock/
|
3
|
-
require "mocha/setup"
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'webmock/minitest'
|
4
3
|
require 'timecop'
|
5
4
|
require 'huey'
|
5
|
+
require "mocha/setup"
|
6
|
+
|
6
7
|
|
7
|
-
class Test
|
8
|
+
class MiniTest::Test
|
8
9
|
def setup
|
9
10
|
super
|
10
11
|
# Prevent real connections to the hub
|
data/test/unit/bulb_test.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class BulbTest < Test
|
3
|
+
class BulbTest < MiniTest::Test
|
4
4
|
|
5
5
|
def setup
|
6
6
|
super
|
7
7
|
@bulb = init_bulb
|
8
|
+
Huey::Bulb.instance_variable_set(:@all, nil)
|
8
9
|
end
|
9
10
|
|
10
11
|
def test_initializes_bulb_from_hash
|
@@ -86,9 +87,11 @@ class BulbTest < Test::Unit::TestCase
|
|
86
87
|
end
|
87
88
|
|
88
89
|
def test_refresh_state
|
89
|
-
|
90
|
-
|
91
|
-
|
90
|
+
off_response = light_response('2', 'Bedroom').values.first
|
91
|
+
Huey::Request.expects(:get).with(nil).once.returns('lights' => {'2' => off_response})
|
92
|
+
on_response = light_response('2', 'Bedroom').values.first
|
93
|
+
on_response['state'].merge!('on' => true)
|
94
|
+
Huey::Request.expects(:get).with("lights/2").once.returns(on_response)
|
92
95
|
|
93
96
|
@bulb = Huey::Bulb.find(2)
|
94
97
|
assert_equal false, @bulb.on
|
data/test/unit/event_test.rb
CHANGED
data/test/unit/group_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class GroupTest < Test
|
3
|
+
class GroupTest < MiniTest::Test
|
4
4
|
|
5
5
|
def setup
|
6
6
|
super
|
@@ -48,6 +48,12 @@ class GroupTest < Test::Unit::TestCase
|
|
48
48
|
assert_equal g, Huey::Group.find('Living Room')
|
49
49
|
end
|
50
50
|
|
51
|
+
def test_not_included_in_all_if_empty
|
52
|
+
g = Huey::Group.new
|
53
|
+
|
54
|
+
assert !Huey::Group.all.include?(g)
|
55
|
+
end
|
56
|
+
|
51
57
|
def test_delegates_save_to_bulbs
|
52
58
|
@group = Huey::Group.new(@bulb1, @bulb2, @bulb3)
|
53
59
|
|
@@ -85,4 +91,30 @@ class GroupTest < Test::Unit::TestCase
|
|
85
91
|
|
86
92
|
assert_equal @group.bri, {1=>127, 2=>127, 3=>127}
|
87
93
|
end
|
94
|
+
|
95
|
+
def test_implements_each
|
96
|
+
@group = Huey::Group.new(@bulb1, @bulb2, @bulb3)
|
97
|
+
|
98
|
+
[@bulb1, @bulb2, @bulb3].each do |bulb|
|
99
|
+
Huey::Request.expects(:put).with("lights/#{bulb.id}/state", body: MultiJson.dump({on: true, bri: 101})).once.returns(true)
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
@group.each {|bulb| bulb.update(on: true, bri: 101)}
|
104
|
+
|
105
|
+
[@bulb1, @bulb2, @bulb3].each do |bulb|
|
106
|
+
assert_equal true, bulb.on
|
107
|
+
assert_equal 101, bulb.bri
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_includes_enumerable
|
112
|
+
@group = Huey::Group.new(@bulb1, @bulb2, @bulb3)
|
113
|
+
|
114
|
+
[@bulb1, @bulb2, @bulb3].each do |bulb|
|
115
|
+
Huey::Request.expects(:put).with("lights/#{bulb.id}/state", body: MultiJson.dump({on: true, bri: 102})).once.returns(true)
|
116
|
+
end
|
117
|
+
|
118
|
+
assert_equal [true, true, true], @group.collect {|bulb| bulb.update(on: true, bri: 102)}
|
119
|
+
end
|
88
120
|
end
|
data/test/unit/portal_test.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class PortalTest < Test
|
3
|
+
class PortalTest < MiniTest::Test
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
Huey::Portal.instance_variable_set(:@hue_ip, nil)
|
7
|
+
end
|
4
8
|
|
5
9
|
def test_gets_local_bridge_ip
|
6
|
-
stub_request(:get, 'http://www.meethue.com/api/nupnp').to_return(body: MultiJson.dump([{"id" => "001788fffe0931a2", "internalipaddress" => "192.168.123.123", "macaddress" => "00:17:88:09:31:a2"}]), headers: {"Content-Type" => 'application/json'})
|
10
|
+
stub_request(:get, 'http://www.meethue.com/api/nupnp').to_return(body: MultiJson.dump([{"id" => "001788fffe0931a2", "internalipaddress" => "192.168.123.123", "macaddress" => "00:17:88:09:31:a2"}]), headers: {"Content-Type" => 'application/json'}).times(2)
|
7
11
|
|
8
12
|
assert_equal Huey::Portal.hue_ip, '192.168.123.123'
|
9
13
|
|
10
14
|
assert_requested :get, 'http://www.meethue.com/api/nupnp'
|
11
15
|
end
|
12
16
|
|
13
|
-
def
|
14
|
-
stub_request(:get, 'http://www.meethue.com/api/nupnp').to_return(body: MultiJson.dump([]), headers: {"Content-Type" => 'application/json'})
|
17
|
+
def test_does_not_find_local_bridge
|
18
|
+
stub_request(:get, 'http://www.meethue.com/api/nupnp').to_return(body: MultiJson.dump([]), headers: {"Content-Type" => 'application/json'}).times(2)
|
15
19
|
|
16
20
|
assert_raises Huey::Errors::CouldNotFindHue do
|
17
21
|
Huey::Portal.hue_ip
|
data/test/unit/request_test.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class RequestTest < Test
|
3
|
+
class RequestTest < MiniTest::Test
|
4
4
|
|
5
5
|
def setup
|
6
6
|
super
|
7
7
|
set_hue_ip('0.0.0.0')
|
8
|
+
Huey::Config.hue_port = 80
|
8
9
|
end
|
9
10
|
|
10
11
|
[:get, :post, :put, :delete].each do |m|
|
@@ -48,7 +49,7 @@ class RequestTest < Test::Unit::TestCase
|
|
48
49
|
Huey::Config.hue_ip = nil
|
49
50
|
end
|
50
51
|
|
51
|
-
def
|
52
|
+
def test_uses_configured_ip
|
52
53
|
Huey::Config.hue_port = 12345
|
53
54
|
|
54
55
|
stub_request(:any, "http://0.0.0.0:12345/api/0123456789abdcef0123456789abcdef/")
|
data/test/unit/ssdp_test.rb
CHANGED