hue 0.2.0 → 0.3.0

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
- SHA1:
3
- metadata.gz: 06f9987573ff54e807b7cb86f72237c6ed8c825f
4
- data.tar.gz: 1150180432174f58f9e19d4f9fa45cb8f98ddd99
2
+ SHA256:
3
+ metadata.gz: af74df93c5514679bab0613c9c6c87b0a0dfae19b919fc903ad42a8fafe9b681
4
+ data.tar.gz: 0afb9bd5b7ee11be0a1dce6b56846c6d13fa7cd9a9b67e2f9c8014c8d03f0fb7
5
5
  SHA512:
6
- metadata.gz: d5b848f3b17020b64327b235be4ef897b3c31d41aadb69b245b14ab8b0b7caa3a7b2e0469bd8cac8deb20cf1bfdaa67d27f52f5f7ec9e598d48b44f5e2a7a892
7
- data.tar.gz: a01dcd6e0385d5b327c34fa308d6fd37381073b22270af0a692e498ef2f2172dab8a045e3d90f24fd0850d29f2684765705f44b3a2eb68c7202f902f3b5d9b49
6
+ metadata.gz: 00f64a5fdad18722af090747e6a2dfe2a5fefb556bcd634ee7b498f54df80e23e94975c295a2925a46cf2166e88df0af07dee1999e26446f7e42e66ebbc8778b
7
+ data.tar.gz: f54f5552bceb7456b0a1d6ccdc29f7ca3cb01636231d83a5f0d7d93b907defce6bfbfcb0e2f96444e49543fbb85f7cda66586f72eedaea912c7a18f5ededb570
@@ -0,0 +1,14 @@
1
+ name: Tests
2
+ on: [push]
3
+ jobs:
4
+ test:
5
+ name: Test Swift Package
6
+ runs-on: ubuntu-latest
7
+ timeout-minutes: 5
8
+ steps:
9
+ - uses: actions/checkout@v1
10
+ - uses: actions/setup-ruby@v1
11
+ - name: 'Install Dependencies'
12
+ run: sudo apt-get install libcurl4-openssl-dev && gem install bundler && bundle install
13
+ - name: 'Test'
14
+ run: bundle exec rake test
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2014 Sam Soffes, http://soff.es
1
+ Copyright (c) 2013-2024 Sam Soffes, https://soff.es
2
2
 
3
3
  MIT License
4
4
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  Work with Philips Hue light bulbs from Ruby.
4
4
 
5
- [![Code Climate](https://codeclimate.com/github/soffes/hue.png)](https://codeclimate.com/github/soffes/hue) [![Dependency Status](https://gemnasium.com/soffes/hue.png)](https://gemnasium.com/soffes/hue) [![Gem Version](https://badge.fury.io/rb/hue.png)](http://badge.fury.io/rb/hue)
6
5
 
7
6
  ## Installation
8
7
 
@@ -78,7 +77,3 @@ group.new? # => false
78
77
  # Destroying groups
79
78
  client.groups.last.destroy!
80
79
  ```
81
-
82
- ## Contributing
83
-
84
- See the [contributing guide](Contributing.markdown).
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
2
3
 
3
- begin
4
- require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new(:spec)
6
-
7
- task :default => :spec
8
- rescue LoadError
9
- # no rspec available
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
10
8
  end
9
+
10
+ task :default => :test
data/bin/hue CHANGED
@@ -5,4 +5,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'hue'
6
6
  require 'hue/cli'
7
7
 
8
- Hue::Cli.start
8
+ begin
9
+ Hue::Cli.start
10
+ rescue Hue::LinkButtonNotPressed
11
+ abort("Error: Press the link button on your bridge and then run this command again within 30 seconds of pressing it.")
12
+ end
data/hue.gemspec CHANGED
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.required_ruby_version = '>= 1.9.3'
21
+ spec.required_ruby_version = '>= 2.1.0'
22
22
  spec.add_dependency 'thor'
23
23
  spec.add_dependency 'json'
24
24
  spec.add_dependency 'log_switch', '0.4.0'
25
25
  spec.add_dependency 'curb'
26
- spec.add_development_dependency 'rspec', '~> 3.2.0'
26
+ spec.add_development_dependency 'minitest', '~> 5.0'
27
27
  spec.add_development_dependency 'webmock'
28
28
  end
data/lib/hue/bridge.rb CHANGED
@@ -66,6 +66,9 @@ module Hue
66
66
  def refresh
67
67
  json = get_configuration
68
68
  unpack(json)
69
+ @lights = nil
70
+ @groups = nil
71
+ @scenes = nil
69
72
  end
70
73
 
71
74
  def lights
data/lib/hue/client.rb CHANGED
@@ -1,15 +1,16 @@
1
1
  require 'net/http'
2
2
  require 'json'
3
+ require 'resolv'
3
4
  require 'curb'
4
5
 
5
6
  module Hue
6
7
  class Client
7
8
  attr_reader :username
8
9
 
9
- def initialize(username = nil)
10
- username = find_username unless @username
11
-
12
- @username = username
10
+ def initialize(username = nil, use_mdns: true)
11
+ @bridge_id = nil
12
+ @username = username || find_username
13
+ @use_mdns = use_mdns
13
14
 
14
15
  if @username
15
16
  begin
@@ -23,8 +24,12 @@ module Hue
23
24
  end
24
25
 
25
26
  def bridge
26
- # Pick the first one for now. In theory, they should all do the same thing.
27
- bridge = bridges.first
27
+ @bridge_id = find_bridge_id unless @bridge_id
28
+ if @bridge_id
29
+ bridge = bridges.select { |b| b.id == @bridge_id }.first
30
+ else
31
+ bridge = bridges.first
32
+ end
28
33
  raise NoBridgeFound unless bridge
29
34
  bridge
30
35
  end
@@ -32,14 +37,8 @@ module Hue
32
37
  def bridges
33
38
  @bridges ||= begin
34
39
  bs = []
35
- easy = Curl::Easy.new
36
- easy.follow_location = true
37
- easy.max_redirects = 10
38
- easy.url = 'https://www.meethue.com/api/nupnp'
39
- easy.perform
40
- JSON(easy.body).each do |hash|
41
- bs << Bridge.new(self, hash)
42
- end
40
+ discovery_mdns(bs) if @use_mdns
41
+ discovery_meethue(bs) if bs.empty?
43
42
  bs
44
43
  end
45
44
  end
@@ -120,6 +119,42 @@ module Hue
120
119
  end
121
120
  end
122
121
 
122
+ def find_bridge_id
123
+ return ENV['HUE_BRIDGE_ID'] if ENV['HUE_BRIDGE_ID']
124
+
125
+ json = JSON(File.read(File.expand_path('~/.hue')))
126
+ json['bridge_id']
127
+ rescue
128
+ return nil
129
+ end
130
+
131
+ def discovery_mdns(bs)
132
+ resolver = Resolv::MDNS.new
133
+ resolver.timeouts = 10
134
+
135
+ resolver.each_resource("_hue._tcp.local", Resolv::DNS::Resource::IN::PTR) do |bridge_ptr|
136
+ bridge_target = resolver.getresource(bridge_ptr.name, Resolv::DNS::Resource::IN::SRV).target
137
+
138
+ bridge_hash = {
139
+ 'id' => resolver.getresource(bridge_ptr.name, Resolv::DNS::Resource::IN::TXT).strings[0].split('=')[1],
140
+ 'internalipaddress' => resolver.getresource(bridge_target, Resolv::DNS::Resource::IN::A).address
141
+ }
142
+
143
+ bs << Bridge.new(self, bridge_hash)
144
+ end
145
+ end
146
+
147
+ def discovery_meethue(bs)
148
+ easy = Curl::Easy.new
149
+ easy.follow_location = true
150
+ easy.max_redirects = 10
151
+ easy.url = 'https://discovery.meethue.com/'
152
+ easy.perform
153
+ JSON(easy.body).each do |hash|
154
+ bs << Bridge.new(self, hash)
155
+ end
156
+ end
157
+
123
158
  def get_error(error)
124
159
  # Find error class and return instance
125
160
  klass = Hue::ERROR_MAP[error['type']] || UnknownError unless klass
data/lib/hue/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hue
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ class ClientTest < Minitest::Test
4
+ def before_setup
5
+ super
6
+
7
+ stub_request(:get, "https://discovery.meethue.com/").
8
+ to_return(:body => '[{"id":"ffa57b3b257200065704","internalipaddress":"192.168.0.1"},{"id":"63c2fc01391276a319f9","internalipaddress":"192.168.0.2"}]')
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.2/api/*}).to_return(:body => '[{"success":true}]')
12
+ end
13
+
14
+ def test_with_bridge_id
15
+ client = Hue::Client.new(use_mdns: false)
16
+ client.stub :find_bridge_id, '63c2fc01391276a319f9' do
17
+ assert_equal '63c2fc01391276a319f9', client.bridge.id
18
+ end
19
+ end
20
+
21
+ def test_without_bridge_id
22
+ client = Hue::Client.new(use_mdns: false)
23
+ assert_equal 'ffa57b3b257200065704', client.bridge.id
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+
3
+ class LightTest < Minitest::Test
4
+ def before_setup
5
+ super
6
+
7
+ stub_request(:get, "https://discovery.meethue.com/").
8
+ to_return(:body => '[{"internalipaddress":"localhost"}]')
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 => '[{}]')
13
+ end
14
+
15
+ %w{on hue saturation brightness color_temperature alert effect}.each do |attribute|
16
+ define_method "test_setting_#{attribute}" do
17
+ client = Hue::Client.new(use_mdns: false)
18
+ light = Hue::Light.new(client, client.bridge, 0, {"state" => {}})
19
+
20
+ light.send("#{attribute}=", 24)
21
+ assert_requested :put, %r{http://localhost/api/.*/lights/0}
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'hue'
3
+
4
+ require 'minitest'
5
+ require 'webmock/minitest'
6
+ require 'minitest/autorun'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Soffes
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-05 00:00:00.000000000 Z
11
+ date: 2024-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -67,19 +67,19 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec
70
+ name: minitest
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 3.2.0
75
+ version: '5.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 3.2.0
82
+ version: '5.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: webmock
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -102,14 +102,12 @@ executables:
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
+ - ".github/workflows/main.yml"
105
106
  - ".gitignore"
106
- - ".rspec"
107
- - Contributing.markdown
108
107
  - Gemfile
109
108
  - LICENSE
109
+ - README.md
110
110
  - Rakefile
111
- - Readme.markdown
112
- - Todo.markdown
113
111
  - bin/hue
114
112
  - hue.gemspec
115
113
  - lib/hue.rb
@@ -123,13 +121,14 @@ files:
123
121
  - lib/hue/scene.rb
124
122
  - lib/hue/translate_keys.rb
125
123
  - lib/hue/version.rb
126
- - spec/hue/light_spec.rb
127
- - spec/spec_helper.rb
124
+ - test/hue/client_test.rb
125
+ - test/hue/light_test.rb
126
+ - test/test_helper.rb
128
127
  homepage: https://github.com/soffes/hue
129
128
  licenses:
130
129
  - MIT
131
130
  metadata: {}
132
- post_install_message:
131
+ post_install_message:
133
132
  rdoc_options: []
134
133
  require_paths:
135
134
  - lib
@@ -137,18 +136,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
136
  requirements:
138
137
  - - ">="
139
138
  - !ruby/object:Gem::Version
140
- version: 1.9.3
139
+ version: 2.1.0
141
140
  required_rubygems_version: !ruby/object:Gem::Requirement
142
141
  requirements:
143
142
  - - ">="
144
143
  - !ruby/object:Gem::Version
145
144
  version: '0'
146
145
  requirements: []
147
- rubyforge_project:
148
- rubygems_version: 2.5.1
149
- signing_key:
146
+ rubygems_version: 3.4.22
147
+ signing_key:
150
148
  specification_version: 4
151
149
  summary: Work with Philips Hue light bulbs from Ruby.
152
150
  test_files:
153
- - spec/hue/light_spec.rb
154
- - spec/spec_helper.rb
151
+ - test/hue/client_test.rb
152
+ - test/hue/light_test.rb
153
+ - test/test_helper.rb
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --require spec_helper
@@ -1,19 +0,0 @@
1
- ## Submitting a Pull Request
2
-
3
- 1. [Fork the repository.][fork]
4
- 2. [Create a topic branch.][branch]
5
- 3. Add tests for your unimplemented feature or bug fix.
6
- 4. Run `bundle exec rake`. If your tests pass, return to step 3.
7
- 5. Implement your feature or bug fix.
8
- 6. Run `bundle exec rake`. If your tests fail, return to step 5.
9
- 7. Run `open coverage/index.html`. If your changes are not completely covered
10
- by your tests, return to step 3.
11
- 8. Add documentation for your feature or bug fix.
12
- 9. Run `bundle exec rake doc`. If your changes are not 100% documented, go
13
- back to step 8.
14
- 10. Add, commit, and push your changes.
15
- 11. [Submit a pull request.][pr]
16
-
17
- [fork]: http://help.github.com/fork-a-repo/
18
- [branch]: http://learn.github.com/p/branching.html
19
- [pr]: http://help.github.com/send-pull-requests/
data/Todo.markdown DELETED
@@ -1,8 +0,0 @@
1
- # To Do
2
-
3
- * RGB translation
4
- * Hex translation
5
- * Scheduling
6
- * Effects
7
- * User management
8
- * Configuration
@@ -1,24 +0,0 @@
1
- RSpec.describe Hue::Light do
2
- %w{on hue saturation brightness color_temperature alert effect}.each do |attribute|
3
- before do
4
- stub_request(:get, "https://www.meethue.com/api/nupnp").
5
- to_return(:body => '[{"internalipaddress":"localhost"}]')
6
-
7
- stub_request(:get, %r{http://localhost/api/*}).
8
- to_return(:body => '[{"success":true}]')
9
-
10
- stub_request(:put, %r{http://localhost/api*}).
11
- to_return(:body => '[{}]')
12
- end
13
-
14
- describe "##{attribute}=" do
15
- it "PUTs the new attribute value" do
16
- client = Hue::Client.new
17
- light = Hue::Light.new(client, client.bridge, 0, {"state" => {}})
18
-
19
- light.send("#{attribute}=", 24)
20
- expect(a_request(:put, %r{http://localhost/api/.*/lights/0})).to have_been_made
21
- end
22
- end
23
- end
24
- end
data/spec/spec_helper.rb DELETED
@@ -1,94 +0,0 @@
1
- require_relative '../lib/hue'
2
- require 'webmock/rspec'
3
-
4
- # This file was generated by the `rspec --init` command. Conventionally, all
5
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
- # The generated `.rspec` file contains `--require spec_helper` which will cause
7
- # this file to always be loaded, without a need to explicitly require it in any
8
- # files.
9
- #
10
- # Given that it is always loaded, you are encouraged to keep this file as
11
- # light-weight as possible. Requiring heavyweight dependencies from this file
12
- # will add to the boot time of your test suite on EVERY test run, even for an
13
- # individual file that may not need all of that loaded. Instead, consider making
14
- # a separate helper file that requires the additional dependencies and performs
15
- # the additional setup, and require it from the spec files that actually need
16
- # it.
17
- #
18
- # The `.rspec` file also contains a few flags that are not defaults but that
19
- # users commonly want.
20
- #
21
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
22
- RSpec.configure do |config|
23
- # rspec-expectations config goes here. You can use an alternate
24
- # assertion/expectation library such as wrong or the stdlib/minitest
25
- # assertions if you prefer.
26
- config.expect_with :rspec do |expectations|
27
- # This option will default to `true` in RSpec 4. It makes the `description`
28
- # and `failure_message` of custom matchers include text for helper methods
29
- # defined using `chain`, e.g.:
30
- # be_bigger_than(2).and_smaller_than(4).description
31
- # # => "be bigger than 2 and smaller than 4"
32
- # ...rather than:
33
- # # => "be bigger than 2"
34
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
- end
36
-
37
- # rspec-mocks config goes here. You can use an alternate test double
38
- # library (such as bogus or mocha) by changing the `mock_with` option here.
39
- config.mock_with :rspec do |mocks|
40
- # Prevents you from mocking or stubbing a method that does not exist on
41
- # a real object. This is generally recommended, and will default to
42
- # `true` in RSpec 4.
43
- mocks.verify_partial_doubles = true
44
- end
45
-
46
- # The settings below are suggested to provide a good initial experience
47
- # with RSpec, but feel free to customize to your heart's content.
48
- =begin
49
- # These two settings work together to allow you to limit a spec run
50
- # to individual examples or groups you care about by tagging them with
51
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
52
- # get run.
53
- config.filter_run :focus
54
- config.run_all_when_everything_filtered = true
55
-
56
- # Limits the available syntax to the non-monkey patched syntax that is
57
- # recommended. For more details, see:
58
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
59
- # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
60
- # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
61
- config.disable_monkey_patching!
62
-
63
- # This setting enables warnings. It's recommended, but in some cases may
64
- # be too noisy due to issues in dependencies.
65
- config.warnings = true
66
-
67
- # Many RSpec users commonly either run the entire suite or an individual
68
- # file, and it's useful to allow more verbose output when running an
69
- # individual spec file.
70
- if config.files_to_run.one?
71
- # Use the documentation formatter for detailed output,
72
- # unless a formatter has already been configured
73
- # (e.g. via a command-line flag).
74
- config.default_formatter = 'doc'
75
- end
76
-
77
- # Print the 10 slowest examples and example groups at the
78
- # end of the spec run, to help surface which specs are running
79
- # particularly slow.
80
- config.profile_examples = 10
81
-
82
- # Run specs in random order to surface order dependencies. If you find an
83
- # order dependency and want to debug it, you can fix the order by providing
84
- # the seed, which is printed after each run.
85
- # --seed 1234
86
- config.order = :random
87
-
88
- # Seed global randomization in this process using the `--seed` CLI option.
89
- # Setting this allows you to use `--seed` to deterministically reproduce
90
- # test failures related to randomization by passing the same `--seed` value
91
- # as the one that triggered the failure.
92
- Kernel.srand config.seed
93
- =end
94
- end