lightwaverf 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/lightwaverf.rb +22 -13
  2. metadata +2 -2
@@ -26,14 +26,21 @@ class LightWaveRF
26
26
  @timers = nil
27
27
  @time = nil
28
28
 
29
+ def quote name = ''
30
+ name = '"' + name + '"' if name.include? ' '
31
+ name
32
+ end
33
+
29
34
  def usage room = nil
30
35
  rooms = self.class.get_rooms self.get_config
31
- config = 'usage: lightwaverf ' + rooms.values.first['name'].to_s + ' ' + rooms.values.first['device'].keys.first.to_s + ' on'
32
- config += ' # where "' + rooms.keys.first.to_s + '" is a room in ' + self.get_config_file.to_s
36
+ roomName = self.quote( rooms.values.first['name'].to_s )
37
+ config = 'usage: lightwaverf ' + roomName + ' ' + rooms.values.first['device'].keys.first.to_s + ' on'
38
+ config += ' # where ' + roomName + ' is a room in ' + self.get_config_file.to_s
33
39
  if room and rooms[room]
34
- config += "\ntry: lightwaverf " + rooms[room]['name'].to_s + ' all on'
40
+ roomName = self.quote( rooms[room]['name'].to_s )
41
+ config += "\ntry: lightwaverf " + roomName + ' all on'
35
42
  rooms[room]['device'].each do | device |
36
- config += "\ntry: lightwaverf " + rooms[room]['name'].to_s + ' ' + device.first.to_s + ' on'
43
+ config += "\ntry: lightwaverf " + roomName + ' ' + device.first.to_s + ' on'
37
44
  end
38
45
  end
39
46
  config
@@ -52,7 +59,7 @@ class LightWaveRF
52
59
  help += YAML.dump self.get_config['room']
53
60
  room = self.get_config['room'].first['name'].to_s
54
61
  device = self.get_config['room'].first['device'].first['name'].to_s
55
- help += "\n\nso to turn on " + room + " " + device + " type \"lightwaverf " + room + " " + device + " on\"\n"
62
+ help += "\n\nso to turn on " + room + " " + device + " type 'lightwaverf " + self.quote( room ) + " " + self.quote( device ) + " on'\n"
56
63
  end
57
64
 
58
65
  # Configure, build config file. Interactive command line stuff
@@ -89,6 +96,7 @@ class LightWaveRF
89
96
  device = 'x'
90
97
  while ! device.to_s.empty?
91
98
  puts 'Enter the name of a room and its devices, space separated. For example "lounge light socket tv". Enter a blank line to finish.'
99
+ puts 'If you want spaces in room or device name, wrap them in quotes. For example "\'living room' 'tv' 'table lamp\'"'
92
100
  puts 'If you already have rooms and devices set up on another lightwaverf app then hit enter here, and "lightwaverf update" first.'
93
101
  if device = STDIN.gets.chomp
94
102
  parts = device.split ' '
@@ -135,10 +143,10 @@ class LightWaveRF
135
143
  end
136
144
 
137
145
  if config['calendar']
138
- crontab << '# ' + executable + ' cache timed events 1 hour back 4 hours ahead'
139
- crontab << '56 * * * * ' + executable + ' update_timers 60 240 > /tmp/lightwaverf_update_timers.out 2>&1'
146
+ crontab << '# ' + executable + ' cache timed events 2 hours back 6 hours ahead'
147
+ crontab << '56 * * * * ' + executable + ' update_timers 120 360 > /tmp/lightwaverf_update_timers.out 2>&1'
140
148
  crontab << '# ' + executable + ' update_timers on reboot (works for me on raspbian)'
141
- crontab << '@reboot ' + executable + ' update_timers 60 240 > /tmp/lightwaverf_update_timers.out 2>&1'
149
+ crontab << '@reboot ' + executable + ' update_timers 120 360 > /tmp/lightwaverf_update_timers.out 2>&1'
142
150
  crontab << '# ' + executable + ' timer every 10 mins off peak'
143
151
  crontab << '*/10 0-6,9-16,23 * * * ' + executable + ' timer 10 > /tmp/lightwaverf_timer.out 2>&1'
144
152
  crontab << '# ' + executable + ' timer every 2 minutes peak'
@@ -178,7 +186,6 @@ class LightWaveRF
178
186
  end
179
187
 
180
188
  def log_timer_event type, room = nil, device = nil, state = nil, result = false
181
- # create log message
182
189
  message = nil
183
190
  case type
184
191
  when 'update'
@@ -234,7 +241,7 @@ class LightWaveRF
234
241
  def get_config
235
242
  if ! @config
236
243
  if ! File.exists? self.get_config_file
237
- puts self.get_config_file + ' does not exist - copy lightwaverf-configy.yml from https://github.com/pauly/lightwaverf to your home directory or type lightwaverf configure'
244
+ puts self.get_config_file + ' does not exist - copy lightwaverf-configy.yml from https://github.com/pauly/lightwaverf to your home directory or type "lightwaverf configure"'
238
245
  self.put_config
239
246
  end
240
247
  @config = YAML.load_file self.get_config_file
@@ -263,9 +270,13 @@ class LightWaveRF
263
270
  end
264
271
 
265
272
  # Login to LightWaveRF Host server
266
- uri = URI.parse 'https://www.lightwaverfhost.co.uk/manager/index.php'
273
+ uri = URI.parse 'https://lightwaverfhost.co.uk/manager/index.php'
267
274
  http = Net::HTTP.new uri.host, uri.port
268
275
  http.use_ssl = true if uri.scheme == 'https'
276
+
277
+ # Thanks Fitz http://lightwaverfcommunity.org.uk/forums/topic/pauly-lightwaverf-command-line-not-working/
278
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
279
+
269
280
  data = 'pin=' + pin + '&email=' + email
270
281
  headers = { 'Content-Type'=> 'application/x-www-form-urlencoded' }
271
282
  resp, data = http.post uri.request_uri, data, headers
@@ -273,8 +284,6 @@ class LightWaveRF
273
284
  if resp and resp.body
274
285
  rooms = self.get_rooms_from resp.body, debug
275
286
  # Update 'room' element in LightWaveRF Gem config file
276
- # config['room'] is an array of hashes containing the room name and device names
277
- # in the format { 'name' => 'Room Name', 'device' => ['Device 1', Device 2'] }
278
287
  if rooms.any?
279
288
  config = self.get_config
280
289
  config['room'] = rooms
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.9.2
4
+ version: 0.10.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-10-22 00:00:00.000000000 Z
14
+ date: 2015-11-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: htmlentities