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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17b9710dcfb0defef023c1adb4c4da4ca86fddc6f2e6c0d971bcb562c57ec61a
4
- data.tar.gz: 8d8afd006ca7892d74f33af84f4040aedd0718b13583e1708a6994bb7803c3d9
3
+ metadata.gz: a93b5e3363bf3af0a578de606c2d061c44db405f77ec3d88dacbbae9ac01b420
4
+ data.tar.gz: 3e5e17cd8438264c403ffab5292d813c08ab9ccff39e4a3b680fe912e56fab3d
5
5
  SHA512:
6
- metadata.gz: 8d3a2e81c450c2d1dd5c94ade3cf146ea4f56f4102f710051c54185902c388f9c9494a6f597f3f0ee05b59d0b0ade9ba837c2a7983df9679ce14ea34dd07e9eb
7
- data.tar.gz: eea449790732dbcfcd0795f1e01af3d6d1a19b800c3b41404fe0bd1a12a76fa706f59269f90320365dde650c6425811fca9bd0ea38558945e8d8c0800badcdc4
6
+ metadata.gz: 05103d25ba76ff79bfbf7655009d818a4425fc0d20dce2146473fe1c93b8d99dcaabe8ebaeed90e8bab88d75ed7679667941ae40d3c1eb181a2f0e39f0869e84
7
+ data.tar.gz: ca26e94b2d5ed62af06038da96a832f9694bc1b09065bdd161be6c222bd4c872397114b7565a89e4669d02cc2c7925907cdae6cb84db67d077fb9d638e7c27a5
@@ -7,7 +7,7 @@ jobs:
7
7
  timeout-minutes: 5
8
8
  steps:
9
9
  - name: Checkout
10
- uses: actions/checkout@v4
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@v4
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.2.2
1
+ 3.4.7
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2024 Sam Soffes, https://soff.es
1
+ Copyright (c) 2013-2025 Sam Soffes, https://soff.es
2
2
 
3
3
  MIT License
4
4
 
data/lib/hue/bridge.rb CHANGED
@@ -73,7 +73,9 @@ module Hue
73
73
 
74
74
  def lights
75
75
  @lights ||= begin
76
- json = JSON(Net::HTTP.get(URI.parse(base_url)))
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 = Net::HTTP.new(uri.host)
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
- json = JSON(Net::HTTP.get(URI.parse("#{base_url}/groups")))
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
- json = JSON(Net::HTTP.get(URI.parse("#{base_url}/scenes")))
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
- JSON(Net::HTTP.get(URI.parse("#{base_url}/config")))
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
- "http://#{ip}/api/#{@client.username}"
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
- response = JSON(Net::HTTP.get(URI.parse("http://#{bridge.ip}/api/#{@username}")))
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("http://#{bridge.ip}/api")
109
- http = Net::HTTP.new(uri.host)
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 = Net::HTTP.new(uri.host)
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 = Net::HTTP.new(uri.host)
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
- json = JSON(Net::HTTP.get(URI.parse(base_url)))
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("http://#{@bridge.ip}/api/#{@client.username}/groups")
126
- http = Net::HTTP.new(uri.host)
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 = Net::HTTP.new(uri.host)
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
- "http://#{@bridge.ip}/api/#{@client.username}/groups/#{id}"
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 = Net::HTTP.new(uri.host)
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 = Net::HTTP.new(uri.host)
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
- json = JSON(Net::HTTP.get(URI.parse(base_url)))
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
- "http://#{@bridge.ip}/api/#{@client.username}/lights/#{id}"
185
+ "https://#{@bridge.ip}/api/#{@client.username}/lights/#{id}"
184
186
  end
185
187
  end
186
188
  end
data/lib/hue/scene.rb CHANGED
@@ -42,7 +42,7 @@ module Hue
42
42
  end
43
43
 
44
44
  def base_url
45
- "http://#{@bridge.ip}/api/#{@client.username}/scenes/#{id}"
45
+ "https://#{@bridge.ip}/api/#{@client.username}/scenes/#{id}"
46
46
  end
47
47
  end
48
48
  end
data/lib/hue/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hue
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
data/lib/hue.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "hue/version"
2
2
  require "hue/errors"
3
+ require "hue/http_client"
3
4
  require "hue/client"
4
5
  require "hue/bridge"
5
6
  require "hue/editable_state"
@@ -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(:get, %r{http://192.168.0.1/api}).to_return(body: '[{"success":true}]')
11
- stub_request(:get, %r{http://192.168.0.1/api/*}).to_return(body: '[{"success":true}]')
12
- stub_request(:get, %r{http://192.168.0.2/api/*}).to_return(body: '[{"success":true}]')
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
@@ -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{http://localhost/api/*}).to_return(body: '[{"success":true}]')
11
- stub_request(:post, "http://localhost/api").to_return(body: '[{"success":{"username":"ruby"}}]')
12
- stub_request(:put, %r{http://localhost/api*}).to_return(body: "[{}]")
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{http://localhost/api/.*/lights/0}
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{http://localhost/api/.*/lights/0}
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{http://localhost/api/.*/lights/0}
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.1
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: 2024-01-03 00:00:00.000000000 Z
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.4.22
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: []