hue_bridge 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hue_bridge/light_bulp.rb +37 -2
- data/lib/hue_bridge/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f9e1a44e6fa827a1cfe5a7fd5c06778fe8e4558
|
4
|
+
data.tar.gz: bbcfc1b7e4b9832c52d8aeb5dcf442b899bb3e38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 233d971542cdcc0c16615c566851e6bc272df87114ca8121983c356806e0c2c1d580461af865c4fea5f54ebd90dc4cb68f8f9b81eaae7aa10c8d00bd7ff53aeb
|
7
|
+
data.tar.gz: 7adece19918852d9c86370278985f3dffae0368c6ecaab59623e482ca5399f2a2aa86e5f379779915c6e2dbfe3e4bbfc222ceba3c497b1529226d1858b42e658
|
@@ -6,7 +6,9 @@ module HueBridge
|
|
6
6
|
# light on, off and to toggle it.
|
7
7
|
#
|
8
8
|
class LightBulp
|
9
|
-
|
9
|
+
FORBIDDEN_STATS = %w(colormode reachable).freeze
|
10
|
+
|
11
|
+
attr_reader :power, :state
|
10
12
|
|
11
13
|
# @param [Hash] options LightBulp options
|
12
14
|
# @option options [String] :hue_bridge_ip The Hue Bridge's IP
|
@@ -66,8 +68,34 @@ module HueBridge
|
|
66
68
|
response_successful?(response)
|
67
69
|
end
|
68
70
|
|
71
|
+
# Stores the current state of the lightbulp.
|
72
|
+
# @return [Boolean] success of the operation
|
73
|
+
#
|
74
|
+
def store_state
|
75
|
+
response = get
|
76
|
+
success = !!(response.body =~ %r(state))
|
77
|
+
data = JSON.parse(response.body) if success
|
78
|
+
@state = data.fetch('state')
|
79
|
+
delete_forbidden_stats
|
80
|
+
success
|
81
|
+
end
|
82
|
+
|
83
|
+
# Restores the state of the lightbulp.
|
84
|
+
# @return [Boolean] success of the operation
|
85
|
+
#
|
86
|
+
def restore_state
|
87
|
+
response = put('state', state)
|
88
|
+
success = !!!(response.body =~ %r(error))
|
89
|
+
end
|
90
|
+
|
69
91
|
private
|
70
92
|
|
93
|
+
def delete_forbidden_stats
|
94
|
+
FORBIDDEN_STATS.each do |attr|
|
95
|
+
@state.delete(attr)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
71
99
|
def log_error(msg)
|
72
100
|
$stderr.puts(msg)
|
73
101
|
end
|
@@ -105,10 +133,17 @@ module HueBridge
|
|
105
133
|
end
|
106
134
|
|
107
135
|
def put(resource, params)
|
108
|
-
http = Net::HTTP.new(@ip)
|
109
136
|
http.request_put("/#{path}/#{resource}", JSON.generate(params))
|
110
137
|
end
|
111
138
|
|
139
|
+
def get(resource = '')
|
140
|
+
http.request_get("/#{path}/#{resource}")
|
141
|
+
end
|
142
|
+
|
143
|
+
def http
|
144
|
+
@http ||= Net::HTTP.new(@ip)
|
145
|
+
end
|
146
|
+
|
112
147
|
def path
|
113
148
|
File.join 'api', @user_id, 'lights', @light_bulp_id.to_s
|
114
149
|
end
|
data/lib/hue_bridge/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hue_bridge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristopher Bredemeier
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|