hue 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/Rakefile +9 -0
- data/Readme.markdown +1 -1
- data/hue.gemspec +2 -0
- data/lib/hue/client.rb +46 -35
- data/lib/hue/light.rb +6 -6
- data/lib/hue/version.rb +1 -1
- data/spec/hue/light_spec.rb +24 -0
- data/spec/spec_helper.rb +94 -0
- metadata +37 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06f9987573ff54e807b7cb86f72237c6ed8c825f
|
4
|
+
data.tar.gz: 1150180432174f58f9e19d4f9fa45cb8f98ddd99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5b848f3b17020b64327b235be4ef897b3c31d41aadb69b245b14ab8b0b7caa3a7b2e0469bd8cac8deb20cf1bfdaa67d27f52f5f7ec9e598d48b44f5e2a7a892
|
7
|
+
data.tar.gz: a01dcd6e0385d5b327c34fa308d6fd37381073b22270af0a692e498ef2f2172dab8a045e3d90f24fd0850d29f2684765705f44b3a2eb68c7202f902f3b5d9b49
|
data/.rspec
ADDED
data/Rakefile
CHANGED
data/Readme.markdown
CHANGED
@@ -64,7 +64,7 @@ group = client.group(1)
|
|
64
64
|
|
65
65
|
# Accessing group lights
|
66
66
|
group.lights.first.on!
|
67
|
-
group.lights.each { |light| light.hue = rand(
|
67
|
+
group.lights.each { |light| light.hue = rand(Hue::Light::HUE_RANGE) }
|
68
68
|
|
69
69
|
# Creating groups
|
70
70
|
group = client.group # Don't specify an ID
|
data/hue.gemspec
CHANGED
data/lib/hue/client.rb
CHANGED
@@ -6,16 +6,18 @@ module Hue
|
|
6
6
|
class Client
|
7
7
|
attr_reader :username
|
8
8
|
|
9
|
-
def initialize(username =
|
10
|
-
unless
|
11
|
-
raise InvalidUsername, "Usernames must be between #{USERNAME_RANGE.first} and #{USERNAME_RANGE.last}."
|
12
|
-
end
|
9
|
+
def initialize(username = nil)
|
10
|
+
username = find_username unless @username
|
13
11
|
|
14
12
|
@username = username
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
if @username
|
15
|
+
begin
|
16
|
+
validate_user
|
17
|
+
rescue Hue::UnauthorizedUser
|
18
|
+
register_user
|
19
|
+
end
|
20
|
+
else
|
19
21
|
register_user
|
20
22
|
end
|
21
23
|
end
|
@@ -75,44 +77,53 @@ module Hue
|
|
75
77
|
scenes.select { |s| s.id == id }.first
|
76
78
|
end
|
77
79
|
|
78
|
-
|
80
|
+
private
|
79
81
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
if response.is_a? Array
|
84
|
-
response = response.first
|
85
|
-
end
|
82
|
+
def find_username
|
83
|
+
return ENV['HUE_USERNAME'] if ENV['HUE_USERNAME']
|
86
84
|
|
87
|
-
|
88
|
-
|
85
|
+
json = JSON(File.read(File.expand_path('~/.hue')))
|
86
|
+
json['username']
|
87
|
+
rescue
|
88
|
+
return nil
|
89
89
|
end
|
90
90
|
|
91
|
-
|
92
|
-
|
91
|
+
def validate_user
|
92
|
+
response = JSON(Net::HTTP.get(URI.parse("http://#{bridge.ip}/api/#{@username}")))
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
username: @username
|
98
|
-
})
|
94
|
+
if response.is_a? Array
|
95
|
+
response = response.first
|
96
|
+
end
|
99
97
|
|
100
|
-
|
101
|
-
|
102
|
-
|
98
|
+
if error = response['error']
|
99
|
+
raise get_error(error)
|
100
|
+
end
|
103
101
|
|
104
|
-
|
105
|
-
raise get_error(error)
|
102
|
+
response['success']
|
106
103
|
end
|
107
104
|
|
108
|
-
|
109
|
-
|
105
|
+
def register_user
|
106
|
+
body = JSON.dump({
|
107
|
+
devicetype: 'Ruby'
|
108
|
+
})
|
110
109
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
110
|
+
uri = URI.parse("http://#{bridge.ip}/api")
|
111
|
+
http = Net::HTTP.new(uri.host)
|
112
|
+
response = JSON(http.request_post(uri.path, body).body).first
|
113
|
+
|
114
|
+
if error = response['error']
|
115
|
+
raise get_error(error)
|
116
|
+
end
|
116
117
|
|
118
|
+
if @username = response['success']['username']
|
119
|
+
File.write(File.expand_path('~/.hue'), JSON.dump({username: @username}))
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def get_error(error)
|
124
|
+
# Find error class and return instance
|
125
|
+
klass = Hue::ERROR_MAP[error['type']] || UnknownError unless klass
|
126
|
+
klass.new(error['description'])
|
127
|
+
end
|
117
128
|
end
|
118
129
|
end
|
data/lib/hue/light.rb
CHANGED
@@ -19,16 +19,16 @@ module Hue
|
|
19
19
|
|
20
20
|
# Hue of the light. This is a wrapping value between 0 and 65535.
|
21
21
|
# Both 0 and 65535 are red, 25500 is green and 46920 is blue.
|
22
|
-
|
22
|
+
attr_reader :hue
|
23
23
|
|
24
24
|
# Saturation of the light. 255 is the most saturated (colored)
|
25
25
|
# and 0 is the least saturated (white).
|
26
|
-
|
26
|
+
attr_reader :saturation
|
27
27
|
|
28
28
|
# Brightness of the light. This is a scale from the minimum
|
29
29
|
# brightness the light is capable of, 0, to the maximum capable
|
30
30
|
# brightness, 255. Note a brightness of 0 is not off.
|
31
|
-
|
31
|
+
attr_reader :brightness
|
32
32
|
|
33
33
|
# The x coordinate of a color in CIE color space. Between 0 and 1.
|
34
34
|
#
|
@@ -44,7 +44,7 @@ module Hue
|
|
44
44
|
# are capable of 153 (6500K) to 500 (2000K).
|
45
45
|
#
|
46
46
|
# @see http://en.wikipedia.org/wiki/Mired
|
47
|
-
|
47
|
+
attr_reader :color_temperature
|
48
48
|
|
49
49
|
# The alert effect, which is a temporary change to the bulb’s state.
|
50
50
|
# This can take one of the following values:
|
@@ -58,12 +58,12 @@ module Hue
|
|
58
58
|
# current state in an upcoming patch.
|
59
59
|
#
|
60
60
|
# @see http://developers.meethue.com/coreconcepts.html#some_extra_fun_stuff
|
61
|
-
|
61
|
+
attr_reader :alert
|
62
62
|
|
63
63
|
# The dynamic effect of the light, can either be `none` or
|
64
64
|
# `colorloop`. If set to colorloop, the light will cycle through
|
65
65
|
# all hues using the current brightness and saturation settings.
|
66
|
-
|
66
|
+
attr_reader :effect
|
67
67
|
|
68
68
|
# Indicates the color mode in which the light is working, this is
|
69
69
|
# the last command type it received. Values are `hs` for Hue and
|
data/lib/hue/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
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
ADDED
@@ -0,0 +1,94 @@
|
|
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
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Soffes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.2.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.2.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
description: Work with Philips Hue light bulbs.
|
70
98
|
email:
|
71
99
|
- sam@soff.es
|
@@ -75,6 +103,7 @@ extensions: []
|
|
75
103
|
extra_rdoc_files: []
|
76
104
|
files:
|
77
105
|
- ".gitignore"
|
106
|
+
- ".rspec"
|
78
107
|
- Contributing.markdown
|
79
108
|
- Gemfile
|
80
109
|
- LICENSE
|
@@ -94,6 +123,8 @@ files:
|
|
94
123
|
- lib/hue/scene.rb
|
95
124
|
- lib/hue/translate_keys.rb
|
96
125
|
- lib/hue/version.rb
|
126
|
+
- spec/hue/light_spec.rb
|
127
|
+
- spec/spec_helper.rb
|
97
128
|
homepage: https://github.com/soffes/hue
|
98
129
|
licenses:
|
99
130
|
- MIT
|
@@ -114,8 +145,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
145
|
version: '0'
|
115
146
|
requirements: []
|
116
147
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
148
|
+
rubygems_version: 2.5.1
|
118
149
|
signing_key:
|
119
150
|
specification_version: 4
|
120
151
|
summary: Work with Philips Hue light bulbs from Ruby.
|
121
|
-
test_files:
|
152
|
+
test_files:
|
153
|
+
- spec/hue/light_spec.rb
|
154
|
+
- spec/spec_helper.rb
|