lightwaverf 0.3.0 → 0.3.2
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/bin/lightwaverf +2 -0
- data/lib/lightwaverf.rb +61 -21
- metadata +2 -2
data/bin/lightwaverf
CHANGED
data/lib/lightwaverf.rb
CHANGED
@@ -24,27 +24,29 @@ class LightWaveRF
|
|
24
24
|
help += "\n\nso to turn on " + room + " " + device + " type \"lightwaverf " + room + " " + device + " on\"\n"
|
25
25
|
end
|
26
26
|
|
27
|
-
# Configure, build config file
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
# Configure, build config file. Interactive command line stuff
|
28
|
+
#
|
29
|
+
# Arguments:
|
30
|
+
# debug: (Boolean
|
31
|
+
def configure debug = false
|
32
|
+
config = self.get_config
|
33
|
+
puts 'What is the ip address of your wifi link? (' + self.get_config['host'] + '). Enter a blank line to broadcast UDP commands.'
|
31
34
|
host = STDIN.gets.chomp
|
32
35
|
if ! host.to_s.empty?
|
33
36
|
config['host'] = host
|
34
37
|
end
|
35
|
-
puts 'What is the address of your google calendar? (' + self.get_config['calendar'] + ')'
|
38
|
+
puts 'What is the address of your google calendar? (' + self.get_config['calendar'] + '). Optional!'
|
36
39
|
calendar = STDIN.gets.chomp
|
37
40
|
if ! calendar.to_s.empty?
|
38
41
|
config['calendar'] = calendar
|
39
42
|
end
|
40
43
|
device = 'x'
|
41
44
|
while ! device.to_s.empty?
|
42
|
-
puts '
|
45
|
+
puts 'Enter the name of a room and its devices, space separated. For example "lounge light socket tv". Enter a blank line to finish.'
|
43
46
|
if device = STDIN.gets.chomp
|
44
47
|
parts = device.split ' '
|
45
48
|
if !parts[0].to_s.empty? and !parts[1].to_s.empty?
|
46
49
|
new_room = parts.shift
|
47
|
-
puts 'got ' + device + ' todo: to split this up... new room is ' + new_room
|
48
50
|
if ! config['room']
|
49
51
|
config['room'] = [ ]
|
50
52
|
end
|
@@ -54,15 +56,16 @@ class LightWaveRF
|
|
54
56
|
room['device'] = parts
|
55
57
|
found = true
|
56
58
|
end
|
57
|
-
p 'so now room is ' + room.to_s
|
59
|
+
debug and ( p 'so now room is ' + room.to_s )
|
58
60
|
end
|
59
61
|
if ! found
|
60
62
|
config['room'].push 'name' => new_room, 'device' => parts
|
61
63
|
end
|
64
|
+
debug and ( p 'added ' + parts.to_s + ' to ' + new_room )
|
62
65
|
end
|
63
66
|
end
|
64
67
|
end
|
65
|
-
|
68
|
+
debug and ( p 'end of configure, config is now ' + config.to_s )
|
66
69
|
self.put_config config
|
67
70
|
end
|
68
71
|
|
@@ -81,7 +84,7 @@ class LightWaveRF
|
|
81
84
|
@log_file || File.expand_path('~') + '/lightwaverf.log'
|
82
85
|
end
|
83
86
|
|
84
|
-
def put_config config = { '
|
87
|
+
def put_config config = { 'room' => [ { 'name' => 'our', 'device' => [ 'light', 'lights' ] } ] }
|
85
88
|
puts 'put_config got ' + config.to_s
|
86
89
|
puts 'so writing ' + YAML.dump( config )
|
87
90
|
File.open( self.get_config_file, 'w' ) do | handle |
|
@@ -217,6 +220,7 @@ class LightWaveRF
|
|
217
220
|
# Example:
|
218
221
|
# >> LightWaveRF.new.state 'on' # 'F1'
|
219
222
|
# >> LightWaveRF.new.state 'off' # 'F0'
|
223
|
+
# >> LightWaveRF.new.state 'alloff' # 'Fa'
|
220
224
|
#
|
221
225
|
# Arguments:
|
222
226
|
# state: (String)
|
@@ -227,6 +231,8 @@ class LightWaveRF
|
|
227
231
|
case state
|
228
232
|
when 'off'
|
229
233
|
state = 'F0'
|
234
|
+
when 'alloff'
|
235
|
+
state = 'Fa'
|
230
236
|
when 'on'
|
231
237
|
state = 'F1'
|
232
238
|
when 1..100
|
@@ -250,13 +256,34 @@ class LightWaveRF
|
|
250
256
|
# state: (String)
|
251
257
|
def command room, device, state
|
252
258
|
# @todo get the device name in here...
|
253
|
-
|
259
|
+
# Command structure is <transaction number>,<Command>|<Action>|<State><cr>
|
260
|
+
if room and device and !device.empty? and state
|
261
|
+
'666,!' + room['id'] + room['device'][device] + state + '|Turn ' + room['name'] + ' ' + device + '|' + state + ' via @pauly'
|
262
|
+
else
|
263
|
+
'666,!' + room['id'] + state + '|Turn ' + room['name'] + '|' + state + ' via @pauly'
|
264
|
+
end
|
254
265
|
end
|
255
266
|
|
256
|
-
#
|
267
|
+
# Set the Time Zone on the LightWaveRF WiFi Link
|
268
|
+
#
|
269
|
+
# Example:
|
270
|
+
# >> LightWaveRF.new.timezone
|
271
|
+
#
|
272
|
+
# Arguments:
|
273
|
+
# debug: (Boolean)
|
274
|
+
def timezone debug = false
|
275
|
+
command = '666,!FzP' + (Time.now.gmt_offset/60/60).to_s
|
276
|
+
debug and ( puts '[Info - LightWaveRF] timezone: command is ' + command )
|
277
|
+
data = self.raw command
|
278
|
+
debug and ( puts '[Info - LightWaveRF] timezone: response is ' + data )
|
279
|
+
return (data == "666,OK\r\n")
|
280
|
+
end
|
281
|
+
|
282
|
+
# Turn one of your devices on or off or all devices in a room off
|
257
283
|
#
|
258
284
|
# Example:
|
259
285
|
# >> LightWaveRF.new.send 'our', 'light', 'on'
|
286
|
+
# >> LightWaveRF.new.send 'our', '', 'off'
|
260
287
|
#
|
261
288
|
# Arguments:
|
262
289
|
# room: (String)
|
@@ -265,8 +292,9 @@ class LightWaveRF
|
|
265
292
|
def send room = nil, device = nil, state = 'on', debug = false
|
266
293
|
debug and ( puts 'config is ' + self.get_config.to_s )
|
267
294
|
rooms = self.class.get_rooms self.get_config, debug
|
295
|
+
state = 'alloff' if (device.empty? and state == 'off')
|
268
296
|
state = self.class.get_state state
|
269
|
-
if rooms[room] and
|
297
|
+
if rooms[room] and state and (state == 'Fa' || (device and rooms[room]['device'][device]))
|
270
298
|
command = self.command rooms[room], device, state
|
271
299
|
debug and ( p 'command is ' + command )
|
272
300
|
data = self.raw command
|
@@ -318,15 +346,27 @@ class LightWaveRF
|
|
318
346
|
|
319
347
|
def raw command
|
320
348
|
response = nil
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
349
|
+
# Get host address or broadcast address
|
350
|
+
host = self.get_config['host'] || '255.255.255.255'
|
351
|
+
# Create socket
|
352
|
+
listener = UDPSocket.new
|
353
|
+
# Add broadcast socket options if necessary
|
354
|
+
if (host == '255.255.255.255')
|
355
|
+
listener.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
|
326
356
|
end
|
327
|
-
|
328
|
-
|
329
|
-
|
357
|
+
if listener
|
358
|
+
# Bind socket to listen for response
|
359
|
+
begin
|
360
|
+
listener.bind '0.0.0.0',9761
|
361
|
+
rescue
|
362
|
+
response = "can't bind to listen for a reply"
|
363
|
+
end
|
364
|
+
# Broadcast command to server
|
365
|
+
listener.send(command, 0, host, 9760)
|
366
|
+
# Receive response
|
367
|
+
if ! response
|
368
|
+
response, addr = listener.recvfrom 200
|
369
|
+
end
|
330
370
|
listener.close
|
331
371
|
end
|
332
372
|
response
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lightwaverf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-03-09 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Interact with lightwaverf wifi link from code or the command line. Control
|
16
16
|
your lights, heating, sockets etc. Also set up timers using a google calendar and
|