huey 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +4 -2
- data/huey.gemspec +1 -0
- data/lib/huey/bulb.rb +10 -10
- data/lib/huey/group.rb +2 -2
- data/lib/huey/version.rb +1 -1
- data/test/unit/bulb_test.rb +3 -3
- metadata +18 -2
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
huey (1.0.
|
4
|
+
huey (1.0.1)
|
5
5
|
chronic (>= 0.9.0)
|
6
|
+
color (>= 1.4.1)
|
6
7
|
eventmachine (>= 1.0.0)
|
7
8
|
httparty (>= 0.9.0)
|
8
9
|
|
@@ -11,9 +12,10 @@ GEM
|
|
11
12
|
specs:
|
12
13
|
addressable (2.3.2)
|
13
14
|
chronic (0.9.0)
|
15
|
+
color (1.4.1)
|
14
16
|
color-tools (1.3.0)
|
15
17
|
crack (0.3.1)
|
16
|
-
eventmachine (1.0.
|
18
|
+
eventmachine (1.0.3)
|
17
19
|
httparty (0.10.2)
|
18
20
|
multi_json (~> 1.0)
|
19
21
|
multi_xml (>= 0.5.2)
|
data/huey.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_dependency('eventmachine', '>=1.0.0')
|
22
22
|
s.add_dependency('httparty', '>=0.9.0')
|
23
23
|
s.add_dependency('chronic', '>=0.9.0')
|
24
|
+
s.add_dependency('color', '>= 1.4.1')
|
24
25
|
|
25
26
|
s.add_development_dependency('bundler', '>=0')
|
26
27
|
s.add_development_dependency('yard', '>=0.8.3')
|
data/lib/huey/bulb.rb
CHANGED
@@ -4,7 +4,7 @@ module Huey
|
|
4
4
|
|
5
5
|
# An actual object for a bulb.
|
6
6
|
class Bulb
|
7
|
-
|
7
|
+
ATTRIBUTES = [:on, :bri, :hue, :sat, :xy, :ct, :name, :transitiontime, :colormode, :effect, :reachable, :alert]
|
8
8
|
attr_reader :id
|
9
9
|
|
10
10
|
def self.all
|
@@ -18,7 +18,7 @@ module Huey
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.find_all(id)
|
21
|
-
self.all.select {|b| b.name.include?(id)}
|
21
|
+
self.all.select {|b| b.id == id || b.name.include?(id.to_s)}
|
22
22
|
end
|
23
23
|
|
24
24
|
def initialize(id, hash)
|
@@ -26,22 +26,22 @@ module Huey
|
|
26
26
|
@changes = {}
|
27
27
|
@name = hash['name']
|
28
28
|
|
29
|
-
(Huey::Bulb::
|
29
|
+
(Huey::Bulb::ATTRIBUTES - [:name]).each do |attribute|
|
30
30
|
instance_variable_set("@#{attribute}".to_sym, hash['state'][attribute.to_s])
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
Huey::Bulb::
|
34
|
+
Huey::Bulb::ATTRIBUTES.each do |attribute|
|
35
35
|
define_method(attribute) do
|
36
36
|
instance_variable_get("@#{attribute}".to_sym)
|
37
37
|
end
|
38
38
|
|
39
39
|
define_method("#{attribute}=".to_sym) do |new_value|
|
40
|
-
return
|
40
|
+
return new_value if self.send(attribute) == new_value
|
41
41
|
|
42
42
|
@changes[attribute] = new_value
|
43
43
|
instance_variable_set("@#{attribute}".to_sym, new_value)
|
44
|
-
end unless
|
44
|
+
end unless [:colormode, :reachable].include?(attribute)
|
45
45
|
end
|
46
46
|
|
47
47
|
def save
|
@@ -74,12 +74,12 @@ module Huey
|
|
74
74
|
v = max * 100
|
75
75
|
|
76
76
|
if (max != 0.0)
|
77
|
-
s = delta / max *100
|
77
|
+
s = delta / max * 100
|
78
78
|
else
|
79
79
|
s = 0.0
|
80
80
|
end
|
81
81
|
|
82
|
-
if (s == 0.0)
|
82
|
+
if (s == 0.0)
|
83
83
|
h = 0.0
|
84
84
|
else
|
85
85
|
if (r == max)
|
@@ -103,8 +103,8 @@ module Huey
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def alert!
|
106
|
-
|
106
|
+
self.update(alert: 'select')
|
107
107
|
end
|
108
108
|
|
109
109
|
end
|
110
|
-
end
|
110
|
+
end
|
data/lib/huey/group.rb
CHANGED
@@ -4,7 +4,7 @@ module Huey
|
|
4
4
|
|
5
5
|
# A group is a collection of bulbs.
|
6
6
|
class Group
|
7
|
-
|
7
|
+
ATTRIBUTES = Huey::Bulb::ATTRIBUTES - [:name, :reachable] + [:rgb]
|
8
8
|
attr_accessor :bulbs, :name
|
9
9
|
|
10
10
|
def self.import(file)
|
@@ -39,7 +39,7 @@ module Huey
|
|
39
39
|
self
|
40
40
|
end
|
41
41
|
|
42
|
-
Huey::Group::
|
42
|
+
Huey::Group::ATTRIBUTES.each do |attribute|
|
43
43
|
define_method("#{attribute}=".to_sym) do |new_value|
|
44
44
|
@attributes_to_write[attribute] = new_value
|
45
45
|
end
|
data/lib/huey/version.rb
CHANGED
data/test/unit/bulb_test.rb
CHANGED
@@ -28,7 +28,7 @@ class BulbTest < Test::Unit::TestCase
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_bulb_get_attributes
|
31
|
-
Huey::Bulb::
|
31
|
+
Huey::Bulb::ATTRIBUTES.each do |attr|
|
32
32
|
assert @bulb.respond_to?(attr), "#{attr} is not set"
|
33
33
|
assert @bulb.instance_variable_defined?("@#{attr}".to_sym), "#{attr} has no instance variable"
|
34
34
|
end
|
@@ -37,8 +37,8 @@ class BulbTest < Test::Unit::TestCase
|
|
37
37
|
def test_bulb_set_attributes
|
38
38
|
assert @bulb.instance_variable_defined?(:@changes), "@changes has no instance variable"
|
39
39
|
|
40
|
-
Huey::Bulb::
|
41
|
-
assert @bulb.respond_to?("#{attr}="), "#{attr} is not set" unless
|
40
|
+
Huey::Bulb::ATTRIBUTES.each do |attr|
|
41
|
+
assert @bulb.respond_to?("#{attr}="), "#{attr} is not set" unless [:colormode, :reachable].include?(attr)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: huey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.9.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: color
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.4.1
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.4.1
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
name: bundler
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|