hue 0.3.1 → 0.3.2
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/.github/workflows/main.yml +2 -2
- data/.ruby-version +1 -1
- data/LICENSE +1 -1
- data/lib/hue/bridge.rb +14 -6
- data/lib/hue/client.rb +6 -3
- data/lib/hue/group.rb +9 -7
- data/lib/hue/http_client.rb +12 -0
- data/lib/hue/light.rb +6 -4
- data/lib/hue/scene.rb +1 -1
- data/lib/hue/version.rb +1 -1
- data/lib/hue.rb +1 -0
- data/test/hue/client_test.rb +3 -3
- data/test/hue/light_test.rb +6 -6
- metadata +4 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a93b5e3363bf3af0a578de606c2d061c44db405f77ec3d88dacbbae9ac01b420
|
|
4
|
+
data.tar.gz: 3e5e17cd8438264c403ffab5292d813c08ab9ccff39e4a3b680fe912e56fab3d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 05103d25ba76ff79bfbf7655009d818a4425fc0d20dce2146473fe1c93b8d99dcaabe8ebaeed90e8bab88d75ed7679667941ae40d3c1eb181a2f0e39f0869e84
|
|
7
|
+
data.tar.gz: ca26e94b2d5ed62af06038da96a832f9694bc1b09065bdd161be6c222bd4c872397114b7565a89e4669d02cc2c7925907cdae6cb84db67d077fb9d638e7c27a5
|
data/.github/workflows/main.yml
CHANGED
|
@@ -7,7 +7,7 @@ jobs:
|
|
|
7
7
|
timeout-minutes: 5
|
|
8
8
|
steps:
|
|
9
9
|
- name: Checkout
|
|
10
|
-
uses: actions/checkout@
|
|
10
|
+
uses: actions/checkout@v6
|
|
11
11
|
- name: Setup Ruby
|
|
12
12
|
uses: ruby/setup-ruby@v1
|
|
13
13
|
with:
|
|
@@ -20,7 +20,7 @@ jobs:
|
|
|
20
20
|
timeout-minutes: 5
|
|
21
21
|
steps:
|
|
22
22
|
- name: Checkout
|
|
23
|
-
uses: actions/checkout@
|
|
23
|
+
uses: actions/checkout@v6
|
|
24
24
|
- name: Setup Ruby
|
|
25
25
|
uses: ruby/setup-ruby@v1
|
|
26
26
|
with:
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.
|
|
1
|
+
3.4.7
|
data/LICENSE
CHANGED
data/lib/hue/bridge.rb
CHANGED
|
@@ -73,7 +73,9 @@ module Hue
|
|
|
73
73
|
|
|
74
74
|
def lights
|
|
75
75
|
@lights ||= begin
|
|
76
|
-
|
|
76
|
+
uri = URI.parse(base_url)
|
|
77
|
+
http = HttpClient.create(uri)
|
|
78
|
+
json = JSON(http.get(uri.path).body)
|
|
77
79
|
json["lights"].map do |key, value|
|
|
78
80
|
Light.new(@client, self, key, value)
|
|
79
81
|
end
|
|
@@ -82,14 +84,16 @@ module Hue
|
|
|
82
84
|
|
|
83
85
|
def add_lights
|
|
84
86
|
uri = URI.parse("#{base_url}/lights")
|
|
85
|
-
http =
|
|
87
|
+
http = HttpClient.create(uri)
|
|
86
88
|
response = http.request_post(uri.path, nil)
|
|
87
89
|
response.body.first
|
|
88
90
|
end
|
|
89
91
|
|
|
90
92
|
def groups
|
|
91
93
|
@groups ||= begin
|
|
92
|
-
|
|
94
|
+
uri = URI.parse("#{base_url}/groups")
|
|
95
|
+
http = HttpClient.create(uri)
|
|
96
|
+
json = JSON(http.get(uri.path).body)
|
|
93
97
|
json.map do |id, data|
|
|
94
98
|
Group.new(@client, self, id, data)
|
|
95
99
|
end
|
|
@@ -98,7 +102,9 @@ module Hue
|
|
|
98
102
|
|
|
99
103
|
def scenes
|
|
100
104
|
@scenes ||= begin
|
|
101
|
-
|
|
105
|
+
uri = URI.parse("#{base_url}/scenes")
|
|
106
|
+
http = HttpClient.create(uri)
|
|
107
|
+
json = JSON(http.get(uri.path).body)
|
|
102
108
|
json.map do |id, data|
|
|
103
109
|
Scene.new(@client, self, id, data)
|
|
104
110
|
end
|
|
@@ -130,11 +136,13 @@ module Hue
|
|
|
130
136
|
end
|
|
131
137
|
|
|
132
138
|
def get_configuration
|
|
133
|
-
|
|
139
|
+
uri = URI.parse("#{base_url}/config")
|
|
140
|
+
http = HttpClient.create(uri)
|
|
141
|
+
JSON(http.get(uri.path).body)
|
|
134
142
|
end
|
|
135
143
|
|
|
136
144
|
def base_url
|
|
137
|
-
"
|
|
145
|
+
"https://#{ip}/api/#{@client.username}"
|
|
138
146
|
end
|
|
139
147
|
end
|
|
140
148
|
end
|
data/lib/hue/client.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "net/http"
|
|
2
|
+
require "openssl"
|
|
2
3
|
require "json"
|
|
3
4
|
require "resolv"
|
|
4
5
|
|
|
@@ -87,7 +88,9 @@ module Hue
|
|
|
87
88
|
end
|
|
88
89
|
|
|
89
90
|
def validate_user
|
|
90
|
-
|
|
91
|
+
uri = URI.parse("https://#{bridge.ip}/api/#{@username}")
|
|
92
|
+
http = HttpClient.create(uri)
|
|
93
|
+
response = JSON(http.get(uri.path).body)
|
|
91
94
|
|
|
92
95
|
if response.is_a? Array
|
|
93
96
|
response = response.first
|
|
@@ -105,8 +108,8 @@ module Hue
|
|
|
105
108
|
devicetype: "Ruby"
|
|
106
109
|
})
|
|
107
110
|
|
|
108
|
-
uri = URI.parse("
|
|
109
|
-
http =
|
|
111
|
+
uri = URI.parse("https://#{bridge.ip}/api")
|
|
112
|
+
http = HttpClient.create(uri)
|
|
110
113
|
response = JSON(http.request_post(uri.path, body).body).first
|
|
111
114
|
|
|
112
115
|
if (error = response["error"])
|
data/lib/hue/group.rb
CHANGED
|
@@ -95,7 +95,7 @@ module Hue
|
|
|
95
95
|
body = translate_keys(attributes, GROUP_KEYS_MAP)
|
|
96
96
|
|
|
97
97
|
uri = URI.parse(base_url)
|
|
98
|
-
http =
|
|
98
|
+
http = HttpClient.create(uri)
|
|
99
99
|
response = http.request_put(uri.path, JSON.dump(body))
|
|
100
100
|
JSON(response.body)
|
|
101
101
|
end
|
|
@@ -105,13 +105,15 @@ module Hue
|
|
|
105
105
|
body = translate_keys(attributes, STATE_KEYS_MAP)
|
|
106
106
|
|
|
107
107
|
uri = URI.parse("#{base_url}/action")
|
|
108
|
-
http =
|
|
108
|
+
http = HttpClient.create(uri)
|
|
109
109
|
response = http.request_put(uri.path, JSON.dump(body))
|
|
110
110
|
JSON(response.body)
|
|
111
111
|
end
|
|
112
112
|
|
|
113
113
|
def refresh
|
|
114
|
-
|
|
114
|
+
uri = URI.parse(base_url)
|
|
115
|
+
http = HttpClient.create(uri)
|
|
116
|
+
json = JSON(http.get(uri.path).body)
|
|
115
117
|
unpack(json)
|
|
116
118
|
@lights = nil
|
|
117
119
|
end
|
|
@@ -122,8 +124,8 @@ module Hue
|
|
|
122
124
|
lights: @light_ids
|
|
123
125
|
}
|
|
124
126
|
|
|
125
|
-
uri = URI.parse("
|
|
126
|
-
http =
|
|
127
|
+
uri = URI.parse("https://#{@bridge.ip}/api/#{@client.username}/groups")
|
|
128
|
+
http = HttpClient.create(uri)
|
|
127
129
|
response = http.request_post(uri.path, JSON.dump(body))
|
|
128
130
|
json = JSON(response.body)
|
|
129
131
|
|
|
@@ -132,7 +134,7 @@ module Hue
|
|
|
132
134
|
|
|
133
135
|
def destroy!
|
|
134
136
|
uri = URI.parse(base_url)
|
|
135
|
-
http =
|
|
137
|
+
http = HttpClient.create(uri)
|
|
136
138
|
response = http.delete(uri.path)
|
|
137
139
|
json = JSON(response.body)
|
|
138
140
|
@id = nil if json[0]["success"]
|
|
@@ -173,7 +175,7 @@ module Hue
|
|
|
173
175
|
end
|
|
174
176
|
|
|
175
177
|
def base_url
|
|
176
|
-
"
|
|
178
|
+
"https://#{@bridge.ip}/api/#{@client.username}/groups/#{id}"
|
|
177
179
|
end
|
|
178
180
|
end
|
|
179
181
|
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Helper module for creating HTTPS connections to the Hue Bridge.
|
|
2
|
+
# The Hue Bridge uses a self-signed certificate, so we disable verification.
|
|
3
|
+
module Hue
|
|
4
|
+
module HttpClient
|
|
5
|
+
def self.create(uri)
|
|
6
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
7
|
+
http.use_ssl = true
|
|
8
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
9
|
+
http
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
data/lib/hue/light.rb
CHANGED
|
@@ -107,7 +107,7 @@ module Hue
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
uri = URI.parse(base_url)
|
|
110
|
-
http =
|
|
110
|
+
http = HttpClient.create(uri)
|
|
111
111
|
response = http.request_put(uri.path, JSON.dump(body))
|
|
112
112
|
response = JSON(response.body).first
|
|
113
113
|
if response["success"]
|
|
@@ -135,14 +135,16 @@ module Hue
|
|
|
135
135
|
body[:transitiontime] = transition if transition
|
|
136
136
|
|
|
137
137
|
uri = URI.parse("#{base_url}/state")
|
|
138
|
-
http =
|
|
138
|
+
http = HttpClient.create(uri)
|
|
139
139
|
response = http.request_put(uri.path, JSON.dump(body))
|
|
140
140
|
JSON(response.body)
|
|
141
141
|
end
|
|
142
142
|
|
|
143
143
|
# Refresh the state of the lamp
|
|
144
144
|
def refresh
|
|
145
|
-
|
|
145
|
+
uri = URI.parse(base_url)
|
|
146
|
+
http = HttpClient.create(uri)
|
|
147
|
+
json = JSON(http.get(uri.path).body)
|
|
146
148
|
unpack(json)
|
|
147
149
|
end
|
|
148
150
|
|
|
@@ -180,7 +182,7 @@ module Hue
|
|
|
180
182
|
end
|
|
181
183
|
|
|
182
184
|
def base_url
|
|
183
|
-
"
|
|
185
|
+
"https://#{@bridge.ip}/api/#{@client.username}/lights/#{id}"
|
|
184
186
|
end
|
|
185
187
|
end
|
|
186
188
|
end
|
data/lib/hue/scene.rb
CHANGED
data/lib/hue/version.rb
CHANGED
data/lib/hue.rb
CHANGED
data/test/hue/client_test.rb
CHANGED
|
@@ -7,9 +7,9 @@ class ClientTest < Minitest::Test
|
|
|
7
7
|
stub_request(:get, "https://discovery.meethue.com/")
|
|
8
8
|
.to_return(body: '[{"id":"ffa57b3b257200065704","internalipaddress":"192.168.0.1"},{"id":"63c2fc01391276a319f9","internalipaddress":"192.168.0.2"}]')
|
|
9
9
|
|
|
10
|
-
stub_request(:
|
|
11
|
-
stub_request(:get, %r{
|
|
12
|
-
stub_request(:get, %r{
|
|
10
|
+
stub_request(:post, "https://192.168.0.1/api").to_return(body: '[{"success":{"username":"ruby"}}]')
|
|
11
|
+
stub_request(:get, %r{https://192.168.0.1/api/*}).to_return(body: '[{"success":true}]')
|
|
12
|
+
stub_request(:get, %r{https://192.168.0.2/api/*}).to_return(body: '[{"success":true}]')
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def test_with_bridge_id
|
data/test/hue/light_test.rb
CHANGED
|
@@ -7,9 +7,9 @@ class LightTest < Minitest::Test
|
|
|
7
7
|
stub_request(:get, "https://discovery.meethue.com/")
|
|
8
8
|
.to_return(body: '[{"internalipaddress":"localhost"}]')
|
|
9
9
|
|
|
10
|
-
stub_request(:get, %r{
|
|
11
|
-
stub_request(:post, "
|
|
12
|
-
stub_request(:put, %r{
|
|
10
|
+
stub_request(:get, %r{https://localhost/api/*}).to_return(body: '[{"success":true}]')
|
|
11
|
+
stub_request(:post, "https://localhost/api").to_return(body: '[{"success":{"username":"ruby"}}]')
|
|
12
|
+
stub_request(:put, %r{https://localhost/api*}).to_return(body: "[{}]")
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
%w[on hue saturation brightness color_temperature alert effect].each do |attribute|
|
|
@@ -18,7 +18,7 @@ class LightTest < Minitest::Test
|
|
|
18
18
|
light = Hue::Light.new(client, client.bridge, 0, {"state" => {}})
|
|
19
19
|
|
|
20
20
|
light.send(:"#{attribute}=", 24)
|
|
21
|
-
assert_requested :put, %r{
|
|
21
|
+
assert_requested :put, %r{https://localhost/api/.*/lights/0}
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -28,7 +28,7 @@ class LightTest < Minitest::Test
|
|
|
28
28
|
assert_equal false, light.on?
|
|
29
29
|
|
|
30
30
|
light.toggle!
|
|
31
|
-
assert_requested :put, %r{
|
|
31
|
+
assert_requested :put, %r{https://localhost/api/.*/lights/0}
|
|
32
32
|
assert_equal true, light.on?
|
|
33
33
|
end
|
|
34
34
|
|
|
@@ -38,7 +38,7 @@ class LightTest < Minitest::Test
|
|
|
38
38
|
assert_equal true, light.on?
|
|
39
39
|
|
|
40
40
|
light.toggle!
|
|
41
|
-
assert_requested :put, %r{
|
|
41
|
+
assert_requested :put, %r{https://localhost/api/.*/lights/0}
|
|
42
42
|
assert_equal false, light.on?
|
|
43
43
|
end
|
|
44
44
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hue
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sam Soffes
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: thor
|
|
@@ -78,6 +77,7 @@ files:
|
|
|
78
77
|
- lib/hue/editable_state.rb
|
|
79
78
|
- lib/hue/errors.rb
|
|
80
79
|
- lib/hue/group.rb
|
|
80
|
+
- lib/hue/http_client.rb
|
|
81
81
|
- lib/hue/light.rb
|
|
82
82
|
- lib/hue/scene.rb
|
|
83
83
|
- lib/hue/translate_keys.rb
|
|
@@ -89,7 +89,6 @@ homepage: https://github.com/soffes/hue
|
|
|
89
89
|
licenses:
|
|
90
90
|
- MIT
|
|
91
91
|
metadata: {}
|
|
92
|
-
post_install_message:
|
|
93
92
|
rdoc_options: []
|
|
94
93
|
require_paths:
|
|
95
94
|
- lib
|
|
@@ -104,8 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
104
103
|
- !ruby/object:Gem::Version
|
|
105
104
|
version: '0'
|
|
106
105
|
requirements: []
|
|
107
|
-
rubygems_version: 3.
|
|
108
|
-
signing_key:
|
|
106
|
+
rubygems_version: 3.6.9
|
|
109
107
|
specification_version: 4
|
|
110
108
|
summary: Work with Philips Hue light bulbs from Ruby.
|
|
111
109
|
test_files: []
|