lightwaverf 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/lightwaverf.rb +19 -11
- metadata +1 -1
data/lib/lightwaverf.rb
CHANGED
@@ -7,11 +7,13 @@ class LightWaveRF
|
|
7
7
|
@config_file = nil
|
8
8
|
@config = nil
|
9
9
|
|
10
|
+
# Display usage info
|
10
11
|
def usage
|
11
12
|
rooms = self.class.get_rooms self.get_config
|
12
13
|
'usage: lightwaverf ' + rooms.keys.first + ' ' + rooms.values.first['device'].keys.first.to_s + ' on # where "' + rooms.keys.first + '" is a room in ' + self.get_config_file
|
13
14
|
end
|
14
15
|
|
16
|
+
# Display help
|
15
17
|
def help
|
16
18
|
help = self.usage + "\n"
|
17
19
|
help += "your rooms, devices, and sequences, as defined in " + self.get_config_file + ":\n\n"
|
@@ -21,14 +23,17 @@ class LightWaveRF
|
|
21
23
|
help += "\n\nso to turn on " + room + " " + device + " type \"lightwaverf " + room + " " + device + " on\"\n"
|
22
24
|
end
|
23
25
|
|
26
|
+
# Config file setter
|
24
27
|
def set_config_file file
|
25
28
|
@config_file = file
|
26
29
|
end
|
27
30
|
|
31
|
+
# Config file getter
|
28
32
|
def get_config_file
|
29
33
|
@config_file || File.expand_path('~') + '/lightwaverf-config.yml'
|
30
34
|
end
|
31
35
|
|
36
|
+
# Get the config file, create it if it does not exist
|
32
37
|
def get_config
|
33
38
|
if ! @config
|
34
39
|
if ! File.exists? self.get_config_file
|
@@ -41,6 +46,7 @@ class LightWaveRF
|
|
41
46
|
@config
|
42
47
|
end
|
43
48
|
|
49
|
+
# Get a cleaned up version of the rooms and devices from the config file
|
44
50
|
def self.get_rooms config = { 'room' => { }}
|
45
51
|
rooms = { }
|
46
52
|
r = 1
|
@@ -160,7 +166,6 @@ class LightWaveRF
|
|
160
166
|
|
161
167
|
# Use a google calendar as a timer?
|
162
168
|
# Needs a google calendar, with its url in your config file, with events like "lounge light on" etc
|
163
|
-
# Only the start time of the event is used right now.
|
164
169
|
#
|
165
170
|
# Run this as a cron job every 5 mins, ie
|
166
171
|
# */5 * * * * /usr/local/bin/lightwaverf timer 5 > /tmp/timer.out 2>&1
|
@@ -177,7 +182,6 @@ class LightWaveRF
|
|
177
182
|
# interval: (Integer)
|
178
183
|
# debug: (Boolean)
|
179
184
|
#
|
180
|
-
# @todo actually use the interval we said...
|
181
185
|
def timer interval = 5, debug = false
|
182
186
|
require 'net/http'
|
183
187
|
require 'rexml/document'
|
@@ -205,16 +209,20 @@ class LightWaveRF
|
|
205
209
|
else
|
206
210
|
STDERR.puts 'did not get When: in ' + e.elements['summary'].text
|
207
211
|
end
|
208
|
-
|
209
|
-
|
210
|
-
|
212
|
+
# @todo fix events that start and end in this period
|
213
|
+
if status
|
214
|
+
event_times = { event_time => status }
|
215
|
+
else
|
216
|
+
event_times = { event_time => 'on', event_end_time => 'off' }
|
211
217
|
end
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
+
event_times.each do | t, s |
|
219
|
+
debug && ( p e.elements['title'].text + ' - ' + now + ' < ' + t + ' < ' + interval_end_time + ' ?' )
|
220
|
+
if t >= now && t < interval_end_time
|
221
|
+
debug && ( p 'so going to turn the ' + room + ' ' + device + ' ' + s.to_s + ' now!' )
|
222
|
+
self.send room, device, s.to_s
|
223
|
+
sleep 1
|
224
|
+
triggered += 1
|
225
|
+
end
|
218
226
|
end
|
219
227
|
end
|
220
228
|
end
|