test_driven_lighting 1.1.0
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 +7 -0
- data/.gitignore +5 -0
- data/.rubocop.yml +54 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +76 -0
- data/README.md +60 -0
- data/bin/tdl-pairing-start +42 -0
- data/bin/tdl-test-lighting +26 -0
- data/examples/example_config.yml +10 -0
- data/examples/lighting_client.rb +26 -0
- data/examples/spec/lighting_formatter.rb +52 -0
- data/examples/spec/spec_helper.rb +1 -0
- data/examples/spec/tests_spec.rb +14 -0
- data/lib/test_driven_lighting/data/default_colors.yml +28 -0
- data/lib/test_driven_lighting/hue.rb +29 -0
- data/lib/test_driven_lighting/lamp.rb +25 -0
- data/lib/test_driven_lighting/message_dispatcher.rb +22 -0
- data/lib/test_driven_lighting/messages/log_message.rb +20 -0
- data/lib/test_driven_lighting/messages/message.rb +20 -0
- data/lib/test_driven_lighting/receiver.rb +19 -0
- data/lib/test_driven_lighting/sender.rb +19 -0
- data/lib/test_driven_lighting/version.rb +3 -0
- data/lib/test_driven_lighting.rb +8 -0
- data/test_driven_lighting.gemspec +30 -0
- metadata +199 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dc6f69380759dd4d59c80930267af0c18f178681
|
4
|
+
data.tar.gz: 79440ded3b44ec566717140e33ac5eee0590d0e5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9b13767c30cff3f54b54cfa26b350f471dc2ae73177b38d873426791cbd8b3ebf3c15a4809444e05d009dc689a11eed460afc2215657d5609e2c8cef2ec57814
|
7
|
+
data.tar.gz: c77372f8a5f07fd0970aad4dfc9ada857c9d4232a124b5253eb082893dcef04f1ece43a89d3f8049943da9b4f8774a1ab18087ee79a184e7af627ebd3334db34
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
Style/StringLiterals:
|
2
|
+
Enabled: true
|
3
|
+
EnforcedStyle: single_quotes
|
4
|
+
|
5
|
+
Style/Documentation:
|
6
|
+
Enabled: true
|
7
|
+
Exclude:
|
8
|
+
- 'spec/**/*'
|
9
|
+
- 'test/**/*'
|
10
|
+
|
11
|
+
Metrics/ClassLength:
|
12
|
+
Enabled: true
|
13
|
+
Max: 100
|
14
|
+
|
15
|
+
Metrics/ModuleLength:
|
16
|
+
Enabled: true
|
17
|
+
Max: 100
|
18
|
+
|
19
|
+
Metrics/LineLength:
|
20
|
+
Enabled: true
|
21
|
+
Exclude:
|
22
|
+
- '*.gemspec'
|
23
|
+
|
24
|
+
# This is already the default in 0.51.0 but I want to state it explicitly
|
25
|
+
Metrics/ParameterLists:
|
26
|
+
Enabled: true
|
27
|
+
Max: 5
|
28
|
+
|
29
|
+
# Because Boards have forced indentation and I'm not using heredocs as
|
30
|
+
# documentation
|
31
|
+
# Layout/IndentHeredoc:
|
32
|
+
# Enabled: false
|
33
|
+
|
34
|
+
|
35
|
+
# I only ever use parallel assignment in constructors, but I ALWAYS use them in
|
36
|
+
# constructors. I wish I could change the cop to allow it only in constructors
|
37
|
+
# Style/ParallelAssignment:
|
38
|
+
# Enabled: false
|
39
|
+
|
40
|
+
# Because RuboCop is just plain WRONG about this, ESPECIALLY for multiline ifs
|
41
|
+
Style/NegatedIf:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
# Normally I favor requiring these but hey, this ain't CoffeeScript and half the
|
45
|
+
# hackathon team likes Seattle.rb style. Let's do it.
|
46
|
+
Style/MethodDefParentheses:
|
47
|
+
EnforcedStyle: require_no_parentheses
|
48
|
+
|
49
|
+
|
50
|
+
# I sort of agree and sort of don't with this one, but the important thing is
|
51
|
+
# emacs completely disagrees with it and there's certain things you just can't
|
52
|
+
# talk to emacs about without it getting all crazy
|
53
|
+
Layout/MultilineMethodCallIndentation:
|
54
|
+
Enabled: false
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
test_driven_lighting (1.0.2)
|
5
|
+
bunny (~> 2.7)
|
6
|
+
faraday (~> 0.12.2)
|
7
|
+
json (~> 2.1)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
amq-protocol (2.2.0)
|
13
|
+
ast (2.3.0)
|
14
|
+
bunny (2.7.2)
|
15
|
+
amq-protocol (>= 2.2.0)
|
16
|
+
byebug (9.0.6)
|
17
|
+
coderay (1.1.2)
|
18
|
+
diff-lcs (1.3)
|
19
|
+
docile (1.1.5)
|
20
|
+
faraday (0.12.2)
|
21
|
+
multipart-post (>= 1.2, < 3)
|
22
|
+
json (2.1.0)
|
23
|
+
method_source (0.9.0)
|
24
|
+
multipart-post (2.0.0)
|
25
|
+
parallel (1.12.0)
|
26
|
+
parser (2.4.0.2)
|
27
|
+
ast (~> 2.3)
|
28
|
+
powerpack (0.1.1)
|
29
|
+
pry (0.11.3)
|
30
|
+
coderay (~> 1.1.0)
|
31
|
+
method_source (~> 0.9.0)
|
32
|
+
rainbow (2.2.2)
|
33
|
+
rake
|
34
|
+
rake (12.3.0)
|
35
|
+
rspec (3.7.0)
|
36
|
+
rspec-core (~> 3.7.0)
|
37
|
+
rspec-expectations (~> 3.7.0)
|
38
|
+
rspec-mocks (~> 3.7.0)
|
39
|
+
rspec-core (3.7.0)
|
40
|
+
rspec-support (~> 3.7.0)
|
41
|
+
rspec-expectations (3.7.0)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.7.0)
|
44
|
+
rspec-mocks (3.7.0)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.7.0)
|
47
|
+
rspec-support (3.7.0)
|
48
|
+
rubocop (0.51.0)
|
49
|
+
parallel (~> 1.10)
|
50
|
+
parser (>= 2.3.3.1, < 3.0)
|
51
|
+
powerpack (~> 0.1)
|
52
|
+
rainbow (>= 2.2.2, < 3.0)
|
53
|
+
ruby-progressbar (~> 1.7)
|
54
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
55
|
+
ruby-progressbar (1.9.0)
|
56
|
+
simplecov (0.15.1)
|
57
|
+
docile (~> 1.1.0)
|
58
|
+
json (>= 1.8, < 3)
|
59
|
+
simplecov-html (~> 0.10.0)
|
60
|
+
simplecov-html (0.10.2)
|
61
|
+
unicode-display_width (1.3.0)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
ruby
|
65
|
+
|
66
|
+
DEPENDENCIES
|
67
|
+
byebug (~> 9.0)
|
68
|
+
pry (~> 0.11.3)
|
69
|
+
rake (~> 12.3)
|
70
|
+
rspec (~> 3.5)
|
71
|
+
rubocop (~> 0.51.0)
|
72
|
+
simplecov (~> 0.15.1)
|
73
|
+
test_driven_lighting!
|
74
|
+
|
75
|
+
BUNDLED WITH
|
76
|
+
1.15.4
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Test Driven Lighting
|
2
|
+
hue bulb test driven lighting
|
3
|
+
|
4
|
+
Running Tests:
|
5
|
+
|
6
|
+
```bash
|
7
|
+
bundle exec rspec spec -f LightingFormatter
|
8
|
+
#=> {'color':'green','type':'test'}`
|
9
|
+
```
|
10
|
+
|
11
|
+
Include the gem
|
12
|
+
```
|
13
|
+
gem 'test_driven_lighting'
|
14
|
+
```
|
15
|
+
|
16
|
+
Example Receiver Code
|
17
|
+
```
|
18
|
+
require 'test_driven_lighting'
|
19
|
+
include TestDrivenLighting
|
20
|
+
|
21
|
+
hue_config = { :hue_ip => '<your_hue_ip>',
|
22
|
+
:hue_api_id => '<your_hue_api_id>' }
|
23
|
+
bunny_config = { :bunny_username => '<bunny_username>',
|
24
|
+
:bunny_password =>'<bunny_password>',
|
25
|
+
:bunny_host => '<bunny_host>'}
|
26
|
+
|
27
|
+
hue = Hue.new(hue_config)
|
28
|
+
lamp = Lamp.new(1)
|
29
|
+
receiver = Receiver.new(bunny_config)
|
30
|
+
|
31
|
+
receiver.listen(`whoami`) do |payload|
|
32
|
+
puts "setting bulbs using #{payload}..."
|
33
|
+
case payload['status']
|
34
|
+
when 'fail'
|
35
|
+
lamp.color = 'red'
|
36
|
+
when 'pending'
|
37
|
+
lamp.color = 'yellow'
|
38
|
+
when 'pass'
|
39
|
+
lamp.color = 'green'
|
40
|
+
end
|
41
|
+
hue.change!(lamp)
|
42
|
+
end
|
43
|
+
|
44
|
+
```
|
45
|
+
|
46
|
+
Example Sender Code
|
47
|
+
```
|
48
|
+
require 'test_driven_lighting'
|
49
|
+
include TestDrivenLighting
|
50
|
+
|
51
|
+
bunny_config = { :bunny_username => '<bunny_username>',
|
52
|
+
:bunny_password =>'<bunny_password>',
|
53
|
+
:bunny_host => '<bunny_host>'}
|
54
|
+
|
55
|
+
sender = Sender.new(bunny_config)
|
56
|
+
sender.message_send("fail","test")
|
57
|
+
sender.message_send("pass","test")
|
58
|
+
sender.message_send("fail","suite")
|
59
|
+
sender.close_connection
|
60
|
+
```
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# tdl-pairing-start - start listening for lighting messages, and change HUE
|
3
|
+
# lights when you or your pair run your specs
|
4
|
+
#
|
5
|
+
# Your config file should be at .test_driven_lighting.conf
|
6
|
+
#
|
7
|
+
# tdl-pairing-start
|
8
|
+
|
9
|
+
require 'yaml'
|
10
|
+
config = YAML::load_file File.expand_path('~/.test_driven_lighting.conf')
|
11
|
+
|
12
|
+
require 'test_driven_lighting'
|
13
|
+
include TestDrivenLighting
|
14
|
+
|
15
|
+
require 'pp'
|
16
|
+
puts '-' * 80
|
17
|
+
pp config
|
18
|
+
puts '-' * 80
|
19
|
+
|
20
|
+
hue_config = {
|
21
|
+
hue_ip: config[:hue_ip],
|
22
|
+
hue_api_id: config[:hue_api_id]
|
23
|
+
}
|
24
|
+
|
25
|
+
hue = Hue.new hue_config
|
26
|
+
lamp = Lamp.new config[:my_lamp_id]
|
27
|
+
receiver = Receiver.new config[:bunny]
|
28
|
+
|
29
|
+
receiver.listen(`whoami`) do |payload|
|
30
|
+
puts "Receiving message with #{payload}"
|
31
|
+
|
32
|
+
case payload['status']
|
33
|
+
when 'fail'
|
34
|
+
lamp.color = 'red'
|
35
|
+
when 'pending'
|
36
|
+
lamp.color = 'yellow'
|
37
|
+
when 'pass'
|
38
|
+
lamp.color = 'green'
|
39
|
+
end
|
40
|
+
|
41
|
+
hue.change! lamp
|
42
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# tdl-test-lights - do a test of the lighting
|
3
|
+
require 'yaml'
|
4
|
+
require 'test_driven_lighting'
|
5
|
+
include TestDrivenLighting
|
6
|
+
|
7
|
+
puts "Sending test messages to your lights..."
|
8
|
+
puts "Loading config..."
|
9
|
+
config = YAML::load_file(File.expand_path('~/.test_driven_lighting.conf'))
|
10
|
+
bunny_config = config[:bunny]
|
11
|
+
|
12
|
+
puts "Connecting to message queue..."
|
13
|
+
sender = Sender.new bunny_config
|
14
|
+
|
15
|
+
puts "Sending test failed message..."
|
16
|
+
sender.message_send "fail", "test"
|
17
|
+
sleep 0.5
|
18
|
+
|
19
|
+
puts "Sending test pending message..."
|
20
|
+
sender.message_send "pending", "test"
|
21
|
+
sleep 0.5
|
22
|
+
|
23
|
+
puts "Sending suite passed message..."
|
24
|
+
sender.message_send "pass", "suite"
|
25
|
+
|
26
|
+
puts "All done!"
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# create a file called "~/.test_driven_lighting.conf"
|
2
|
+
# and add the following with your details
|
3
|
+
---
|
4
|
+
:hue_ip: 192.168.1.2
|
5
|
+
:hue_api_id: your_api_key_key
|
6
|
+
:my_lamp_id: 1
|
7
|
+
:bunny:
|
8
|
+
:bunny_username: guest
|
9
|
+
:bunny_password: guest
|
10
|
+
:bunny_host: localhost:5672
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
config = YAML::load_file(File.expand_path('~/.test_driven_lighting.conf'))
|
3
|
+
require_relative '../lib/test_driven_lighting'
|
4
|
+
include TestDrivenLighting
|
5
|
+
|
6
|
+
hue_config = {
|
7
|
+
hue_ip: config[:hue_ip],
|
8
|
+
hue_api_id: config[:hue_api_id]
|
9
|
+
}
|
10
|
+
|
11
|
+
hue = Hue.new hue_config
|
12
|
+
lamp = Lamp.new config[:my_lamp_id]
|
13
|
+
receiver = Receiver.new config[:bunny]
|
14
|
+
|
15
|
+
receiver.listen(`whoami`) do |payload|
|
16
|
+
puts "Receiving message with #{payload}"
|
17
|
+
|
18
|
+
case payload['status']
|
19
|
+
when 'fail'
|
20
|
+
lamp.color = 'red'
|
21
|
+
when 'pass'
|
22
|
+
lamp.color = 'green'
|
23
|
+
end
|
24
|
+
|
25
|
+
hue.change! lamp
|
26
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require_relative '../../config'
|
3
|
+
require_relative '../../lib/test_driven_lighting'
|
4
|
+
|
5
|
+
class LightingFormatter
|
6
|
+
RSpec::Core::Formatters.register self,
|
7
|
+
:example_passed,
|
8
|
+
:example_failed,
|
9
|
+
:example_pending,
|
10
|
+
:dump_summary,
|
11
|
+
:close
|
12
|
+
|
13
|
+
def initialize data
|
14
|
+
bunny_config = {
|
15
|
+
:bunny_username => BUNNY_USERNAME,
|
16
|
+
:bunny_password => BUNNY_PASSWORD,
|
17
|
+
:bunny_host => BUNNY_HOST
|
18
|
+
}
|
19
|
+
|
20
|
+
@sender = Sender.new bunny_config
|
21
|
+
end
|
22
|
+
|
23
|
+
def example_passed test_data
|
24
|
+
@sender.message_send 'pass','test'
|
25
|
+
end
|
26
|
+
|
27
|
+
def example_failed test_data
|
28
|
+
@sender.message_send 'fail','test'
|
29
|
+
end
|
30
|
+
|
31
|
+
def example_pending test_data
|
32
|
+
example_failed test_data
|
33
|
+
end
|
34
|
+
|
35
|
+
def dump_summary summary
|
36
|
+
if failed_or_pending? summary
|
37
|
+
@sender.message_send 'fail','suite'
|
38
|
+
else
|
39
|
+
@sender.message_send 'pass','suite'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def close param
|
44
|
+
@sender.close_connection
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def failed_or_pending? summary
|
50
|
+
summary.failed_examples.any? || summary.pending_examples.any?
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rspec'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
colors:
|
2
|
+
red:
|
3
|
+
hue: 0
|
4
|
+
saturation: 254
|
5
|
+
orange:
|
6
|
+
hue: 5000
|
7
|
+
saturation: 254
|
8
|
+
yellow:
|
9
|
+
hue: 10000
|
10
|
+
saturation: 254
|
11
|
+
green:
|
12
|
+
hue: 25000
|
13
|
+
saturation: 254
|
14
|
+
teal:
|
15
|
+
hue: 35000
|
16
|
+
saturation: 254
|
17
|
+
blue:
|
18
|
+
hue: 44000
|
19
|
+
saturation: 254
|
20
|
+
purple:
|
21
|
+
hue: 49000
|
22
|
+
saturation: 254
|
23
|
+
mauve:
|
24
|
+
hue: 52000
|
25
|
+
saturation: 150
|
26
|
+
pink:
|
27
|
+
hue: 55000
|
28
|
+
saturation: 254
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'faraday'
|
3
|
+
|
4
|
+
class Hue
|
5
|
+
attr_accessor :hue_ip, :hue_api_id
|
6
|
+
|
7
|
+
def initialize config
|
8
|
+
@hue_ip = config[:hue_ip]
|
9
|
+
@hue_api_id = config[:hue_api_id]
|
10
|
+
end
|
11
|
+
|
12
|
+
def change! lamp
|
13
|
+
data = {
|
14
|
+
:on => lamp.is_on,
|
15
|
+
:bri => lamp.brightness,
|
16
|
+
:sat => lamp.saturation,
|
17
|
+
:hue => lamp.hue,
|
18
|
+
:transitiontime => lamp.transition_time
|
19
|
+
}.to_json
|
20
|
+
|
21
|
+
connection = Faraday.new("http://#{@hue_ip}")
|
22
|
+
|
23
|
+
connection.put("/api/#{@hue_api_id}/lights/#{lamp.id}/state") do |request|
|
24
|
+
request.headers['Content-Type'] = 'application/json'
|
25
|
+
request.headers['Accept'] = 'application/json'
|
26
|
+
request.body = data
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class Lamp
|
4
|
+
attr_accessor :id,:hue,:saturation,:brightness,:is_on, :transition_time, :colors
|
5
|
+
|
6
|
+
DEFAULT_COLORS_FILE = "#{File.expand_path(File.dirname(__FILE__))}/data/default_colors.yml"
|
7
|
+
DEFAULT_COLORS = YAML.load_file(DEFAULT_COLORS_FILE)['colors']
|
8
|
+
|
9
|
+
def initialize(lamp_id)
|
10
|
+
@is_on = true
|
11
|
+
@id = lamp_id
|
12
|
+
@hue = 0
|
13
|
+
@saturation = 254
|
14
|
+
@brightness = 10
|
15
|
+
@transition_time = 0
|
16
|
+
@colors = DEFAULT_COLORS
|
17
|
+
end
|
18
|
+
|
19
|
+
def color= color
|
20
|
+
raise "unknown color of #{color}" if @colors[color].nil?
|
21
|
+
|
22
|
+
@hue = @colors[color]['hue']
|
23
|
+
@saturation = @colors[color]['saturation']
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class MessageDispatcher
|
2
|
+
attr_reader :message_classes
|
3
|
+
def initialize
|
4
|
+
# message_classes contains "class_name" => ClassName
|
5
|
+
@message_classes = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def register_message_class(name, klass)
|
9
|
+
# screw trying to upcase and snake case and pretend to be rails WE'RE NOT
|
10
|
+
# RAILS SO STOP TRYING
|
11
|
+
message_classes[name] = klass
|
12
|
+
end
|
13
|
+
|
14
|
+
def dispatch(outgoing_message)
|
15
|
+
klass = class_for outgoing_message.fetch("message_type")
|
16
|
+
klass.new(outgoing_message).process
|
17
|
+
end
|
18
|
+
|
19
|
+
def class_for(class_name)
|
20
|
+
message_classes.fetch class_name
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'message'
|
2
|
+
|
3
|
+
# LogMessage - prints a message to the log (currently just whatever screen is
|
4
|
+
# running the listener)
|
5
|
+
class LogMessage < Message
|
6
|
+
def initialize message
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def process
|
11
|
+
content = message.fetch 'content'
|
12
|
+
puts "%s %s" % [timestamp, content]
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def timestamp
|
18
|
+
Time.new.strftime "%F %T"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Base Message class. Child classes should call super from #initialize and must
|
2
|
+
# implement #process.
|
3
|
+
class Message
|
4
|
+
# (Mostly) Common message attributes
|
5
|
+
attr_reader :message
|
6
|
+
|
7
|
+
# message: hash with string keys containing the message data.
|
8
|
+
# MUST contain at least "message_type" => "name_of_this_message" so we know
|
9
|
+
# which message class should handle it, though technically that's all handled
|
10
|
+
# by MessageDispatcher before we ever construct the message
|
11
|
+
def initialize message
|
12
|
+
@message = message
|
13
|
+
end
|
14
|
+
|
15
|
+
def message_type
|
16
|
+
message.fetch 'message_type'
|
17
|
+
end
|
18
|
+
|
19
|
+
# NOTE: Subclass is expected to implement #process
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'bunny'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
STDOUT.sync = true
|
5
|
+
|
6
|
+
class Receiver
|
7
|
+
def initialize(config)
|
8
|
+
@connection = Bunny.new("amqp://#{config[:bunny_username]}:#{config[:bunny_password]}@#{config[:bunny_host]}").start
|
9
|
+
@channel = @connection.create_channel
|
10
|
+
@exchange = @channel.fanout('lighting.messages')
|
11
|
+
end
|
12
|
+
|
13
|
+
def listen(queue_name, &block)
|
14
|
+
puts 'listening for light messages...'
|
15
|
+
@channel.queue(queue_name, :auto_delete => true).bind(@exchange).subscribe(:block => true) do |delivery_info, metadata, payload|
|
16
|
+
yield JSON.parse(payload)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'bunny'
|
3
|
+
|
4
|
+
class Sender
|
5
|
+
def initialize config
|
6
|
+
@connection = Bunny.new("amqp://#{config[:bunny_username]}:#{config[:bunny_password]}@#{config[:bunny_host]}").start
|
7
|
+
@channel = @connection.create_channel
|
8
|
+
@exchange = @channel.fanout('lighting.messages')
|
9
|
+
end
|
10
|
+
|
11
|
+
def message_send status, type
|
12
|
+
message = Hash status: status, type: type
|
13
|
+
@exchange.publish message.to_json
|
14
|
+
end
|
15
|
+
|
16
|
+
def close_connection
|
17
|
+
@connection.close
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module TestDrivenLighting
|
2
|
+
require_relative 'test_driven_lighting/hue'
|
3
|
+
require_relative 'test_driven_lighting/lamp'
|
4
|
+
require_relative 'test_driven_lighting/sender'
|
5
|
+
require_relative 'test_driven_lighting/receiver'
|
6
|
+
require_relative 'test_driven_lighting/message_dispatcher'
|
7
|
+
require_relative 'test_driven_lighting/messages/log_message'
|
8
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'lib/test_driven_lighting/version.rb'
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'test_driven_lighting'
|
8
|
+
s.version = TestDrivenLighting::VERSION
|
9
|
+
s.license = 'MIT'
|
10
|
+
s.summary = 'test driven lighting for hue bulbs'
|
11
|
+
s.description = 'provides sender and receiver classes for entities that want to change the bulbs, and the entities that have bulbs to change'
|
12
|
+
s.authors = ['Ashton Freidenberger','Brian Lees','Dave Brady','Daniel DeStefano']
|
13
|
+
s.email = 'afreidenberger@covermymeds.com'
|
14
|
+
s.homepage = 'http://www.covermymeds.com'
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
s.bindir = "bin"
|
18
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
|
20
|
+
s.add_dependency 'bunny', '~> 2.7'
|
21
|
+
s.add_dependency 'faraday', '~> 0.12.2'
|
22
|
+
s.add_dependency 'json', '~> 2.1'
|
23
|
+
|
24
|
+
s.add_development_dependency 'byebug', '~> 9.0'
|
25
|
+
s.add_development_dependency 'pry', '~> 0.11.3'
|
26
|
+
s.add_development_dependency 'rake', '~> 12.3'
|
27
|
+
s.add_development_dependency 'rspec', '~> 3.5'
|
28
|
+
s.add_development_dependency 'rubocop', '~> 0.51.0'
|
29
|
+
s.add_development_dependency 'simplecov', '~> 0.15.1'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: test_driven_lighting
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ashton Freidenberger
|
8
|
+
- Brian Lees
|
9
|
+
- Dave Brady
|
10
|
+
- Daniel DeStefano
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2017-12-07 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bunny
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.7'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.7'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faraday
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - "~>"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.12.2
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.12.2
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: json
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - "~>"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '2.1'
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '2.1'
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: byebug
|
60
|
+
requirement: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - "~>"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '9.0'
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '9.0'
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: pry
|
74
|
+
requirement: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - "~>"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.11.3
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - "~>"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.11.3
|
86
|
+
- !ruby/object:Gem::Dependency
|
87
|
+
name: rake
|
88
|
+
requirement: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - "~>"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '12.3'
|
93
|
+
type: :development
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '12.3'
|
100
|
+
- !ruby/object:Gem::Dependency
|
101
|
+
name: rspec
|
102
|
+
requirement: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - "~>"
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '3.5'
|
107
|
+
type: :development
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - "~>"
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '3.5'
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: rubocop
|
116
|
+
requirement: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - "~>"
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 0.51.0
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - "~>"
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: 0.51.0
|
128
|
+
- !ruby/object:Gem::Dependency
|
129
|
+
name: simplecov
|
130
|
+
requirement: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - "~>"
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 0.15.1
|
135
|
+
type: :development
|
136
|
+
prerelease: false
|
137
|
+
version_requirements: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - "~>"
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: 0.15.1
|
142
|
+
description: provides sender and receiver classes for entities that want to change
|
143
|
+
the bulbs, and the entities that have bulbs to change
|
144
|
+
email: afreidenberger@covermymeds.com
|
145
|
+
executables:
|
146
|
+
- tdl-pairing-start
|
147
|
+
- tdl-test-lighting
|
148
|
+
extensions: []
|
149
|
+
extra_rdoc_files: []
|
150
|
+
files:
|
151
|
+
- ".gitignore"
|
152
|
+
- ".rubocop.yml"
|
153
|
+
- Gemfile
|
154
|
+
- Gemfile.lock
|
155
|
+
- README.md
|
156
|
+
- bin/tdl-pairing-start
|
157
|
+
- bin/tdl-test-lighting
|
158
|
+
- examples/example_config.yml
|
159
|
+
- examples/lighting_client.rb
|
160
|
+
- examples/spec/lighting_formatter.rb
|
161
|
+
- examples/spec/spec_helper.rb
|
162
|
+
- examples/spec/tests_spec.rb
|
163
|
+
- lib/test_driven_lighting.rb
|
164
|
+
- lib/test_driven_lighting/data/default_colors.yml
|
165
|
+
- lib/test_driven_lighting/hue.rb
|
166
|
+
- lib/test_driven_lighting/lamp.rb
|
167
|
+
- lib/test_driven_lighting/message_dispatcher.rb
|
168
|
+
- lib/test_driven_lighting/messages/log_message.rb
|
169
|
+
- lib/test_driven_lighting/messages/message.rb
|
170
|
+
- lib/test_driven_lighting/receiver.rb
|
171
|
+
- lib/test_driven_lighting/sender.rb
|
172
|
+
- lib/test_driven_lighting/version.rb
|
173
|
+
- test_driven_lighting.gemspec
|
174
|
+
homepage: http://www.covermymeds.com
|
175
|
+
licenses:
|
176
|
+
- MIT
|
177
|
+
metadata: {}
|
178
|
+
post_install_message:
|
179
|
+
rdoc_options: []
|
180
|
+
require_paths:
|
181
|
+
- lib
|
182
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
|
+
requirements:
|
189
|
+
- - ">="
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: '0'
|
192
|
+
requirements: []
|
193
|
+
rubyforge_project:
|
194
|
+
rubygems_version: 2.6.13
|
195
|
+
signing_key:
|
196
|
+
specification_version: 4
|
197
|
+
summary: test driven lighting for hue bulbs
|
198
|
+
test_files: []
|
199
|
+
has_rdoc:
|