lightwaverf 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/lightwaverf.rb +26 -18
- metadata +2 -2
data/lib/lightwaverf.rb
CHANGED
@@ -61,7 +61,8 @@ class LightWaveRF
|
|
61
61
|
# debug: (Boolean)
|
62
62
|
def configure debug = false
|
63
63
|
config = self.get_config
|
64
|
-
puts 'What is the ip address of your wifi link? (currently "' + self.get_config['host'].to_s + '").
|
64
|
+
puts 'What is the ip address of your wifi link? (currently "' + self.get_config['host'].to_s + '").'
|
65
|
+
puts 'Enter a blank line to broadcast UDP commands (ok to just hit enter here).'
|
65
66
|
host = STDIN.gets.chomp
|
66
67
|
config['host'] = host if ! host.to_s.empty?
|
67
68
|
puts 'What is the address of your calendar ics file? (currently "' + self.get_config['calendar'].to_s + '")'
|
@@ -91,7 +92,7 @@ class LightWaveRF
|
|
91
92
|
puts 'If you already have rooms and devices set up on another lightwaverf app then hit enter here, and "lightwaverf update" first.'
|
92
93
|
if device = STDIN.gets.chomp
|
93
94
|
parts = device.split ' '
|
94
|
-
if !parts
|
95
|
+
if !parts.first.to_s.empty? and !parts[1].to_s.empty?
|
95
96
|
new_room = parts.shift
|
96
97
|
config['room'] ||= [ ]
|
97
98
|
found = false
|
@@ -157,10 +158,6 @@ class LightWaveRF
|
|
157
158
|
'Saved config file ' + file
|
158
159
|
end
|
159
160
|
|
160
|
-
def set_config_file file
|
161
|
-
@config_file = file
|
162
|
-
end
|
163
|
-
|
164
161
|
def get_config_file
|
165
162
|
@config_file || File.expand_path('~') + '/lightwaverf-config.yml'
|
166
163
|
end
|
@@ -330,7 +327,6 @@ class LightWaveRF
|
|
330
327
|
|
331
328
|
# Get variables from the source of lightwaverfhost.co.uk
|
332
329
|
# Separated out so it can be tested
|
333
|
-
#
|
334
330
|
def get_variables_from body = '', debug = nil
|
335
331
|
# debug and ( p '[Info - LightWaveRF Gem] body was ' + body.to_s )
|
336
332
|
variables = { }
|
@@ -467,7 +463,7 @@ class LightWaveRF
|
|
467
463
|
def send room = nil, device = nil, state = 'on', debug = false
|
468
464
|
debug and ( p self.time 'send' )
|
469
465
|
success = false
|
470
|
-
debug and ( p 'Executing send on device: ' + device + ' in room: ' + room + ' with state
|
466
|
+
debug and ( p 'Executing send on device: ' + device + ' in room: ' + room + ' with ' + ( state ? 'state ' + state : 'no state' ))
|
471
467
|
rooms = self.class.get_rooms self.get_config, debug
|
472
468
|
debug and ( p self.time 'got rooms' )
|
473
469
|
|
@@ -492,6 +488,7 @@ class LightWaveRF
|
|
492
488
|
data = self.raw command
|
493
489
|
debug and ( p self.time 'response is ' + data.to_s )
|
494
490
|
success = true
|
491
|
+
data = self.update_state room, device, state, debug
|
495
492
|
else
|
496
493
|
STDERR.puts self.usage( room );
|
497
494
|
end
|
@@ -499,6 +496,18 @@ class LightWaveRF
|
|
499
496
|
success
|
500
497
|
end
|
501
498
|
|
499
|
+
def update_state room, device, state, debug
|
500
|
+
config = self.get_config
|
501
|
+
config['room'].each do | r |
|
502
|
+
next unless r['name'] == room
|
503
|
+
r['device'].each do | d |
|
504
|
+
next unless d['name'] == device
|
505
|
+
d['state'] = state
|
506
|
+
end
|
507
|
+
end
|
508
|
+
self.put_config config
|
509
|
+
end
|
510
|
+
|
502
511
|
# A sequence of events
|
503
512
|
# maybe I really mean a "mood" here?
|
504
513
|
#
|
@@ -705,9 +714,10 @@ class LightWaveRF
|
|
705
714
|
STDERR.puts 'This contains my test events, not yours! Add your ical url to your config file'
|
706
715
|
url = 'https://www.google.com/calendar/ical/aar79qh62fej54nprq6334s7ck%40group.calendar.google.com/public/basic.ics'
|
707
716
|
end
|
717
|
+
url
|
708
718
|
end
|
709
719
|
|
710
|
-
def request url
|
720
|
+
def request url, debug = false
|
711
721
|
parsed_url = URI.parse url
|
712
722
|
http = Net::HTTP.new parsed_url.host, parsed_url.port
|
713
723
|
begin
|
@@ -817,7 +827,7 @@ class LightWaveRF
|
|
817
827
|
|
818
828
|
url = self.get_calendar_url debug
|
819
829
|
debug and ( p url )
|
820
|
-
response = self.request url
|
830
|
+
response = self.request url, debug
|
821
831
|
if response.code != '200'
|
822
832
|
debug and ( p "Response code is: " + response.code)
|
823
833
|
return self.log_timer_event 'update', nil, nil, nil, false
|
@@ -825,9 +835,7 @@ class LightWaveRF
|
|
825
835
|
|
826
836
|
cals = RiCal.parse_string( response.body )
|
827
837
|
|
828
|
-
timers = { }
|
829
|
-
timers['events'] = [ ]
|
830
|
-
timers['states'] = [ ]
|
838
|
+
timers = { 'events' => [ ], 'states' => [ ] }
|
831
839
|
|
832
840
|
cals.first.events.each do | e |
|
833
841
|
occurs = e.occurrences( :overlapping => [ query_start, query_end ] )
|
@@ -847,8 +855,8 @@ class LightWaveRF
|
|
847
855
|
# fix this with something like
|
848
856
|
# if self.get_state event['state'] ! starts with F
|
849
857
|
|
850
|
-
if event['type'] == 'device' and event['state'] != '
|
851
|
-
debug and ( p 'Duplicating ' + event['summary'] + ' with state ' + event['state']
|
858
|
+
if event['type'] == 'device' and event['state'].first != 'o'
|
859
|
+
debug and ( p 'Duplicating ' + event['summary'] + ' with ' + ( event['state'] ? 'state ' + event['state'] : 'no state' ))
|
852
860
|
event['state'] = 'on' if event['state'].nil?
|
853
861
|
end_event = event.dup # duplicate event for start and end
|
854
862
|
end_event['date'] = event['end']
|
@@ -872,7 +880,7 @@ class LightWaveRF
|
|
872
880
|
else
|
873
881
|
timers['events'].push event
|
874
882
|
end
|
875
|
-
|
883
|
+
|
876
884
|
end
|
877
885
|
|
878
886
|
end
|
@@ -1171,8 +1179,8 @@ class LightWaveRF
|
|
1171
1179
|
debug and ( puts 'now got ' + data.length.to_s + ' lines in the log ( 60 * 24 * ' + days.to_s + ' = ' + ( 60 * 24 * days ).to_s + ' )' )
|
1172
1180
|
if data and data.first
|
1173
1181
|
debug and ( puts 'data.first is ' + data.first.to_s )
|
1174
|
-
if data.first
|
1175
|
-
data
|
1182
|
+
if data.first.first != start_date
|
1183
|
+
data.first.first += start_date
|
1176
1184
|
end
|
1177
1185
|
end
|
1178
1186
|
summary_file = self.get_summary_file
|
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.
|
4
|
+
version: 0.9.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-
|
14
|
+
date: 2015-10-05 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: htmlentities
|