lightwaverf 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/lightwaverf.rb +16 -28
- metadata +18 -2
data/lib/lightwaverf.rb
CHANGED
@@ -136,7 +136,7 @@ class LightWaveRF
|
|
136
136
|
|
137
137
|
if config['calendar']
|
138
138
|
crontab << '# ' + executable + ' cache timed events 1 hour back 4 hours ahead'
|
139
|
-
crontab << '
|
139
|
+
crontab << '56 * * * * ' + executable + ' update_timers 60 240 > /tmp/lightwaverf_update_timers.out 2>&1'
|
140
140
|
crontab << '# ' + executable + ' update_timers on reboot (works for me on raspbian)'
|
141
141
|
crontab << '@reboot ' + executable + ' update_timers 60 240 > /tmp/lightwaverf_update_timers.out 2>&1'
|
142
142
|
crontab << '# ' + executable + ' timer every 10 mins off peak'
|
@@ -184,7 +184,7 @@ class LightWaveRF
|
|
184
184
|
when 'update'
|
185
185
|
message = '### Updated timer cache'
|
186
186
|
when 'run'
|
187
|
-
message = '*** Ran timers'
|
187
|
+
# message = '*** Ran timers'
|
188
188
|
when 'sequence'
|
189
189
|
message = 'Ran sequence: ' + state
|
190
190
|
when 'mood'
|
@@ -500,7 +500,7 @@ class LightWaveRF
|
|
500
500
|
end
|
501
501
|
|
502
502
|
def update_state room, device, state, debug
|
503
|
-
update = false
|
503
|
+
update = false
|
504
504
|
config = self.get_config
|
505
505
|
config['room'].each do | r |
|
506
506
|
next unless r['name'] == room
|
@@ -924,8 +924,7 @@ class LightWaveRF
|
|
924
924
|
end
|
925
925
|
|
926
926
|
def run_timers interval = 5, debug = false
|
927
|
-
p '
|
928
|
-
p 'Running timers...'
|
927
|
+
p '-- Running timers...'
|
929
928
|
get_timer_cache
|
930
929
|
debug and ( p 'Timer list is: ' + YAML.dump( @timers ))
|
931
930
|
|
@@ -937,8 +936,7 @@ class LightWaveRF
|
|
937
936
|
# convert to datetimes
|
938
937
|
start_horizon = DateTime.parse start_tm.to_s
|
939
938
|
end_horizon = DateTime.parse end_tm.to_s
|
940
|
-
p '
|
941
|
-
p 'Start horizon is: ' + start_horizon.to_s
|
939
|
+
p '-- Start horizon is: ' + start_horizon.to_s
|
942
940
|
p 'End horizon is: ' + end_horizon.to_s
|
943
941
|
|
944
942
|
# sort the events and states (to guarantee order if longer intervals are used)
|
@@ -950,17 +948,14 @@ class LightWaveRF
|
|
950
948
|
|
951
949
|
# process each event
|
952
950
|
@timers['events'].each do | event |
|
953
|
-
debug and ( p '
|
954
|
-
debug and ( p 'Processing event: ' + event.to_s )
|
951
|
+
debug and ( p '-- Processing event: ' + event.to_s )
|
955
952
|
debug and ( p 'Event time is: ' + event['date'].to_s )
|
956
953
|
|
957
954
|
# first, assume we'll not be running the event
|
958
955
|
run_now = false
|
959
956
|
|
960
957
|
# check that it is in the horizon time
|
961
|
-
|
962
|
-
debug and ( p 'Event is NOT in horizon...ignoring')
|
963
|
-
else
|
958
|
+
if event['date'] >= start_horizon and event['date'] < end_horizon
|
964
959
|
debug and ( p 'Event is in horizon...')
|
965
960
|
run_now = true
|
966
961
|
|
@@ -1004,8 +999,7 @@ class LightWaveRF
|
|
1004
999
|
end
|
1005
1000
|
|
1006
1001
|
# process the run list
|
1007
|
-
p '
|
1008
|
-
p 'Events to execute this run are: ' + run_list.to_s
|
1002
|
+
p '-- Events to execute this run are: ' + run_list.to_s
|
1009
1003
|
|
1010
1004
|
triggered = [ ]
|
1011
1005
|
|
@@ -1020,9 +1014,8 @@ class LightWaveRF
|
|
1020
1014
|
p 'Executing sequence. Sequence: ' + event['state']
|
1021
1015
|
result = self.sequence event['state'], debug
|
1022
1016
|
else
|
1023
|
-
p '
|
1024
|
-
|
1025
|
-
result = self.send event['room'], event['device'].to_s, event['state'], debug # is this right?
|
1017
|
+
p 'send ' + event['room'].to_s + ' ' + event['device'].to_s + ' ' + event['state'].to_s + ' ' + debug.to_s
|
1018
|
+
result = self.send event['room'], event['device'], event['state'], debug
|
1026
1019
|
end
|
1027
1020
|
sleep 1
|
1028
1021
|
triggered << [ event['room'], event['device'].to_s, event['state'] ]
|
@@ -1143,8 +1136,9 @@ class LightWaveRF
|
|
1143
1136
|
daily = self.class.get_json file
|
1144
1137
|
start_date = 0
|
1145
1138
|
d = nil
|
1146
|
-
last =
|
1147
|
-
prev =
|
1139
|
+
last = 0
|
1140
|
+
prev = 0
|
1141
|
+
cut_off_date = ( DateTime.now - days ).to_s
|
1148
1142
|
File.open( self.get_log_file, 'r' ).each_line do | line |
|
1149
1143
|
begin
|
1150
1144
|
line = JSON.parse line
|
@@ -1152,6 +1146,7 @@ class LightWaveRF
|
|
1152
1146
|
line = nil
|
1153
1147
|
end
|
1154
1148
|
if line and line['timestamp'] and ( last != line['message']['usage'] )
|
1149
|
+
next if ( cut_off_date > line['timestamp'] )
|
1155
1150
|
new_line = []
|
1156
1151
|
d = line['timestamp'][2..3] + line['timestamp'][5..6] + line['timestamp'][8..9] # compact version of date
|
1157
1152
|
ts = Time.parse( line['timestamp'] ).strftime '%s'
|
@@ -1162,7 +1157,7 @@ class LightWaveRF
|
|
1162
1157
|
end
|
1163
1158
|
new_line << ts
|
1164
1159
|
smoothedUsage = line['message']['usage'].to_i
|
1165
|
-
if last
|
1160
|
+
if last != 0 and prev != 0
|
1166
1161
|
smoothedUsage = ( smoothedUsage + last + prev ) / 3 # average of last 3 readings
|
1167
1162
|
end
|
1168
1163
|
new_line << smoothedUsage / 10
|
@@ -1179,22 +1174,15 @@ class LightWaveRF
|
|
1179
1174
|
last = line['message']['usage'].to_i
|
1180
1175
|
end
|
1181
1176
|
end
|
1182
|
-
debug and ( puts 'got ' + data.length.to_s + ' lines in the log' )
|
1183
|
-
data = data.last 60 * 24 * days
|
1184
|
-
debug and ( puts 'now got ' + data.length.to_s + ' lines in the log ( 60 * 24 * ' + days.to_s + ' = ' + ( 60 * 24 * days ).to_s + ' )' )
|
1185
1177
|
if data and data.first
|
1186
|
-
debug and ( puts 'data.first is ' + data.first.to_s )
|
1187
1178
|
if data.first.first != start_date
|
1188
|
-
data.first
|
1179
|
+
data.first[0] += start_date
|
1189
1180
|
end
|
1190
1181
|
end
|
1191
1182
|
summary_file = self.get_summary_file
|
1192
1183
|
File.open( summary_file, 'w' ) do |file|
|
1193
|
-
# file.write data.to_s
|
1194
1184
|
file.write( JSON.pretty_generate( data ))
|
1195
1185
|
end
|
1196
|
-
# @todo fix the daily stats, every night it reverts to the minimum value because the timezones are different
|
1197
|
-
# so 1am on the wifi-link looks midnight on the server
|
1198
1186
|
File.open( summary_file.gsub( 'summary', 'daily' ), 'w' ) do | file |
|
1199
1187
|
file.write daily.to_json.to_s
|
1200
1188
|
end
|
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.
|
4
|
+
version: 0.9.2
|
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-22 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: htmlentities
|
@@ -29,6 +29,22 @@ dependencies:
|
|
29
29
|
- - ! '>='
|
30
30
|
- !ruby/object:Gem::Version
|
31
31
|
version: '0'
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: ri_cal
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
32
48
|
- !ruby/object:Gem::Dependency
|
33
49
|
name: json
|
34
50
|
requirement: !ruby/object:Gem::Requirement
|