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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b4954b76f2043d1e65f11b4ed3babd779106b06
4
- data.tar.gz: 133e6453fe934a22d91e859cb39a6a0552f86481
3
+ metadata.gz: 6f9e1a44e6fa827a1cfe5a7fd5c06778fe8e4558
4
+ data.tar.gz: bbcfc1b7e4b9832c52d8aeb5dcf442b899bb3e38
5
5
  SHA512:
6
- metadata.gz: c91f9f1f968533b5c2f2357728db18229fb57e91895061301311e34c3969ba9ff58abf9d018ba2c925b4632bec8621f275f5143a7aec97df51d87beec0298df5
7
- data.tar.gz: 19bbbd8706528b3dd25624fd9fb047ac88556a93949207b92348a25fd19cc4b35267d9180dc0935fbab42cae66b5b1a3ba9bb2549a4ddf970434f8822a24ff56
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
- attr_reader :power
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
@@ -1,3 +1,3 @@
1
1
  module HueBridge
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
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-20 00:00:00.000000000 Z
11
+ date: 2016-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler