lightwaverf 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/lightwaverf +3 -0
- data/lib/lightwaverf.rb +54 -0
- metadata +47 -0
data/bin/lightwaverf
ADDED
data/lib/lightwaverf.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
class LightWaveRF
|
2
|
+
def config
|
3
|
+
require 'yaml'
|
4
|
+
file = File.expand_path('~') + '/lightwaverf-config.yml'
|
5
|
+
if ! File.exists? file
|
6
|
+
File.open( file, 'w' ) do | handle |
|
7
|
+
handle.write YAML.dump( { 'host' => '192.168.0.14', 'room' => { 'our' => [ 'light', 'lights' ] } } )
|
8
|
+
end
|
9
|
+
end
|
10
|
+
YAML.load_file file
|
11
|
+
end
|
12
|
+
|
13
|
+
# Turn one of your devices on or off
|
14
|
+
#
|
15
|
+
# Example:
|
16
|
+
# >> LightWaveRF.go 'our', 'light', 'on'
|
17
|
+
#
|
18
|
+
# Arguments:
|
19
|
+
# room: (String)
|
20
|
+
# device: (String)
|
21
|
+
# state: (String)
|
22
|
+
def go room, device, state
|
23
|
+
require 'socket'
|
24
|
+
config = self.config
|
25
|
+
rooms = { }
|
26
|
+
r = 1
|
27
|
+
config['room'].each do | name, devices |
|
28
|
+
rooms[name] = {
|
29
|
+
'id' => 'R' + r.to_s,
|
30
|
+
'device' => { }
|
31
|
+
}
|
32
|
+
d = 1
|
33
|
+
devices.each do | device |
|
34
|
+
rooms[name]['device'][device] = 'D' + d.to_s
|
35
|
+
d += 1
|
36
|
+
end
|
37
|
+
r += 1
|
38
|
+
end
|
39
|
+
room = rooms[room]
|
40
|
+
state ||= 'on'
|
41
|
+
room && device && state && room['device'][device] || abort( "usage: #{__FILE__} [" + rooms.keys.join( "|" ) + "] light on" )
|
42
|
+
case state
|
43
|
+
when 'off'
|
44
|
+
state = 'F0'
|
45
|
+
when 'on'
|
46
|
+
state = 'F1'
|
47
|
+
when 'setup'
|
48
|
+
state = 'F1'
|
49
|
+
when 1..99
|
50
|
+
# @todo dimming etc
|
51
|
+
end
|
52
|
+
UDPSocket.new.send "666,!" + room['id'] + room['device'][device] + state + "|", 0, config['host'], 9760
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lightwaverf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Paul Clarke
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-27 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Interact with lightwaverf wifi link from the command line
|
15
|
+
email: pauly@clarkeology.com
|
16
|
+
executables:
|
17
|
+
- lightwaverf
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/lightwaverf.rb
|
22
|
+
- bin/lightwaverf
|
23
|
+
homepage: http://www.clarkeology.com/wiki/lightwaverf+ruby+gem
|
24
|
+
licenses: []
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.23
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: Home automation
|
47
|
+
test_files: []
|