lightwave_rf 0.0.1
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +1 -0
- data/lib/lightwave_rf.rb +64 -0
- data/lightwave_rf.gemspec +22 -0
- data/spec/lightwave_rf_spec.rb +129 -0
- data/spec/spec_helper.rb +17 -0
- metadata +94 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Steve Smith
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# LightwaveRf
|
2
|
+
|
3
|
+
Control LightwaveRF devices with the Wifi Link box
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'lightwave_rf'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install lightwave_rf
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
lightwave = LightwaveRF.new
|
22
|
+
|
23
|
+
# Initial Registration (Only needs doing once per device)
|
24
|
+
lightwave.register
|
25
|
+
|
26
|
+
# Turn the light on in room 1, device number 1
|
27
|
+
lightwave.turn_on(1, 1)
|
28
|
+
|
29
|
+
# Dim the lights in room 2, device number 3 after turning them on
|
30
|
+
lightwave.turn_on(2, 3)
|
31
|
+
lightwave.dim(2, 3, 50)
|
32
|
+
|
33
|
+
# Turn off the lights
|
34
|
+
lightwave.turn_off(1, 1)
|
35
|
+
lightwave.turn_off(2, 3)
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/lightwave_rf.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
class LightwaveRF
|
4
|
+
VERSION = "0.0.1"
|
5
|
+
PORT = 9760
|
6
|
+
|
7
|
+
attr_accessor :prefix
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@prefix = generate_prefix
|
11
|
+
end
|
12
|
+
|
13
|
+
def register
|
14
|
+
generate_and_send_command(1, 1, "F0", 533)
|
15
|
+
end
|
16
|
+
|
17
|
+
def turn_on(room_number, device_number)
|
18
|
+
generate_and_send_command(room_number, device_number, "F1")
|
19
|
+
end
|
20
|
+
|
21
|
+
def turn_off(room_number, device_number)
|
22
|
+
generate_and_send_command(room_number, device_number, "F0")
|
23
|
+
end
|
24
|
+
|
25
|
+
def dim(room_number, device_number, percentage)
|
26
|
+
generate_and_send_command(room_number, device_number, "FdP#{level(percentage)}")
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
def level(percentage)
|
31
|
+
1 + (percentage * 0.3125).to_i
|
32
|
+
end
|
33
|
+
|
34
|
+
def generate_prefix
|
35
|
+
"%03d" % rand(99)
|
36
|
+
end
|
37
|
+
|
38
|
+
def generate_and_send_command(room_number, device_number, command, prefix = @prefix)
|
39
|
+
generated_string = generate_command(room_number, device_number, command, prefix)
|
40
|
+
send_command(generated_string)
|
41
|
+
end
|
42
|
+
|
43
|
+
def generate_command(room_number, device_number, command, prefix = @prefix)
|
44
|
+
"#{prefix},!R#{room_number}D#{device_number}#{command}|"
|
45
|
+
end
|
46
|
+
|
47
|
+
def send_command(command)
|
48
|
+
socket = UDPSocket.new
|
49
|
+
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
|
50
|
+
socket.send(command, 0, "255.255.255.255", 9760)
|
51
|
+
socket.close
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# lightwave = LightwaveRF.new
|
56
|
+
# lightwave.turn_on(1, 1)
|
57
|
+
# sleep(5)
|
58
|
+
# lightwave.dim(1, 1, 25)
|
59
|
+
# sleep(3)
|
60
|
+
# lightwave.dim(1, 1, 50)
|
61
|
+
# sleep(3)
|
62
|
+
# lightwave.dim(1, 1, 100)
|
63
|
+
# sleep(5)
|
64
|
+
# lightwave.turn_off(1, 1)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lightwave_rf'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "lightwave_rf"
|
8
|
+
gem.version = LightwaveRF::VERSION
|
9
|
+
gem.authors = ["Steve Smith"]
|
10
|
+
gem.email = ["gems@dynedge.co.uk"]
|
11
|
+
gem.description = %q{Control LightwaveRF devices with the Wifi Link box}
|
12
|
+
gem.summary = %q{Control LightwaveRF devices with the Wifi Link box}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
gem.add_development_dependency "rspec"
|
22
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
describe LightwaveRF do
|
2
|
+
describe ".new" do
|
3
|
+
it "should assign @prefix" do
|
4
|
+
LightwaveRF.new.prefix.should_not be_nil
|
5
|
+
LightwaveRF.new.prefix.should match(/\d{3}/)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "protected methods" do
|
10
|
+
describe "#generate_prefix" do
|
11
|
+
it "should create string of length 3" do
|
12
|
+
prefix = LightwaveRF.new.send(:generate_prefix)
|
13
|
+
prefix.class.name.should == "String"
|
14
|
+
prefix.length.should == 3
|
15
|
+
prefix.should match(/0\d{2}/)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#generate_command" do
|
20
|
+
it "should correctly format a command using the default prefix" do
|
21
|
+
lightwave = LightwaveRF.new
|
22
|
+
prefix = lightwave.prefix
|
23
|
+
lightwave.send(:generate_command, 1, 1, "F0").should == "#{prefix},!R1D1F0|"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#generate_and_send_command" do
|
28
|
+
it "should call generate_command with the given arguments then call send_command" do
|
29
|
+
lightwave = LightwaveRF.new
|
30
|
+
prefix = lightwave.prefix
|
31
|
+
lightwave.should_receive("generate_command").with(1, 1, "F0", prefix)
|
32
|
+
lightwave.should_receive("send_command").and_return(true)
|
33
|
+
lightwave.send(:generate_and_send_command, 1, 1, "F0")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should call send_command with the given arguments" do
|
37
|
+
lightwave = LightwaveRF.new
|
38
|
+
prefix = lightwave.prefix
|
39
|
+
lightwave.should_receive("generate_command").and_return("command_name")
|
40
|
+
lightwave.should_receive("send_command").with("command_name")
|
41
|
+
lightwave.send(:generate_and_send_command, 1, 1, "F0")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#level" do
|
46
|
+
it "should return 1 for 0%" do
|
47
|
+
LightwaveRF.new.send(:level, 0).should == 1
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return 16 for 50%" do
|
51
|
+
LightwaveRF.new.send(:level, 50).should == 16
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return 32 for 100%" do
|
55
|
+
LightwaveRF.new.send(:level, 100).should == 32
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "register" do
|
61
|
+
it "should send '533,!R1D1F0|'" do
|
62
|
+
lightwave = LightwaveRF.new
|
63
|
+
lightwave.should_receive("send_command").with("533,!R1D1F0|")
|
64
|
+
lightwave.register
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#turn_on" do
|
69
|
+
it "should send '001,!R1D1F1|' for room 1 device 1" do
|
70
|
+
lightwave = LightwaveRF.new
|
71
|
+
lightwave.prefix = "001"
|
72
|
+
lightwave.should_receive("send_command").with("001,!R1D1F1|")
|
73
|
+
lightwave.turn_on(1, 1)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should send '001,!R3D4F1|' for room 3 device 4" do
|
77
|
+
lightwave = LightwaveRF.new
|
78
|
+
lightwave.prefix = "001"
|
79
|
+
lightwave.should_receive("send_command").with("001,!R3D4F1|")
|
80
|
+
lightwave.turn_on(3, 4)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#turn_off" do
|
85
|
+
it "should send '001,!R1D1F0|' for room 1 device 1" do
|
86
|
+
lightwave = LightwaveRF.new
|
87
|
+
lightwave.prefix = "001"
|
88
|
+
lightwave.should_receive("send_command").with("001,!R1D1F0|")
|
89
|
+
lightwave.turn_off(1, 1)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should send '001,!R3D4F0|' for room 3 device 4" do
|
93
|
+
lightwave = LightwaveRF.new
|
94
|
+
lightwave.prefix = "001"
|
95
|
+
lightwave.should_receive("send_command").with("001,!R3D4F0|")
|
96
|
+
lightwave.turn_off(3, 4)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#dim" do
|
101
|
+
it "should send 001,!R1D1FdP32 for 0% brightness" do
|
102
|
+
lightwave = LightwaveRF.new
|
103
|
+
lightwave.prefix = "001"
|
104
|
+
lightwave.should_receive("send_command").with("001,!R1D1FdP1|")
|
105
|
+
lightwave.dim(1, 1, 0)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should send 001,!R1D1FdP6 for 20% brightness" do
|
109
|
+
lightwave = LightwaveRF.new
|
110
|
+
lightwave.prefix = "001"
|
111
|
+
lightwave.should_receive("send_command").with("001,!R1D1FdP7|")
|
112
|
+
lightwave.dim(1, 1, 20)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should send 001,!R1D1FdP32 for 50% brightness" do
|
116
|
+
lightwave = LightwaveRF.new
|
117
|
+
lightwave.prefix = "001"
|
118
|
+
lightwave.should_receive("send_command").with("001,!R1D1FdP16|")
|
119
|
+
lightwave.dim(1, 1, 50)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should send 001,!R1D1FdP32 for 100% brightness" do
|
123
|
+
lightwave = LightwaveRF.new
|
124
|
+
lightwave.prefix = "001"
|
125
|
+
lightwave.should_receive("send_command").with("001,!R1D1FdP32|")
|
126
|
+
lightwave.dim(1, 1, 100)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lightwave_rf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Steve Smith
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Control LightwaveRF devices with the Wifi Link box
|
47
|
+
email:
|
48
|
+
- gems@dynedge.co.uk
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/lightwave_rf.rb
|
59
|
+
- lightwave_rf.gemspec
|
60
|
+
- spec/lightwave_rf_spec.rb
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
homepage: ''
|
63
|
+
licenses: []
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
hash: 595400561521727292
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
hash: 595400561521727292
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.8.23
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Control LightwaveRF devices with the Wifi Link box
|
92
|
+
test_files:
|
93
|
+
- spec/lightwave_rf_spec.rb
|
94
|
+
- spec/spec_helper.rb
|