lightwaverf 0.10.0 → 0.11.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 +38 -16
  2. metadata +2 -2
data/lib/lightwaverf.rb CHANGED
@@ -132,8 +132,8 @@ class LightWaveRF
132
132
  crontab << '# new crontab added by `' + executable + ' configure`'
133
133
 
134
134
  if config['monitor']
135
- crontab << '# ' + executable + ' energy monitor check ever 2 mins + summarise every 5'
136
- crontab << '*/2 * * * * ' + executable + ' energy > /tmp/lightwaverf_energy.out 2>&1'
135
+ crontab << '# ' + executable + ' energy monitor check ever minute + summarise every 5'
136
+ crontab << '* * * * * ' + executable + ' energy > /tmp/lightwaverf_energy.out 2>&1'
137
137
  crontab << '*/5 * * * * ' + executable + ' summarise 7 > /tmp/lightwaverf_summarise.out 2>&1'
138
138
  end
139
139
 
@@ -476,6 +476,18 @@ class LightWaveRF
476
476
  debug and ( p self.time 'send' )
477
477
  success = false
478
478
  debug and ( p 'Executing send on device: ' + device + ' in room: ' + room + ' with ' + ( state ? 'state ' + state : 'no state' ))
479
+
480
+
481
+ pythonFile = self.get_config['pywaverf']
482
+ if File.exist?( pythonFile )
483
+ cmd = "#{pythonFile} \"#{room}\" \"#{device}\" \"#{state}\" \"#{debug}\""
484
+ debug and ( p cmd )
485
+ p `#{cmd}`
486
+ debug and ( p self.time 'done python' )
487
+ return
488
+ end
489
+
490
+
479
491
  rooms = self.class.get_rooms self.get_config, debug
480
492
  debug and ( p self.time 'got rooms' )
481
493
 
@@ -621,16 +633,24 @@ class LightWaveRF
621
633
 
622
634
  def energy title = nil, text = nil, debug = false
623
635
  debug and text and ( p 'energy: ' + text )
624
- data = self.raw '666,@?', true
625
- # /W=(?<usage>\d+),(?<max>\d+),(?<today>\d+),(?<yesterday>\d+)/.match data # ruby 1.9 only?
626
- match = /W=(\d+),(\d+),(\d+),(\d+)/.match data
627
- debug and ( p match )
628
- if match
636
+ data = self.raw nil, true, debug
637
+ debug and ( p data )
638
+ match = false
639
+ # {"trans":17903,"mac":"03:0F:DA","time":1452531946,"prod":"pwrMtr","serial":"9EB3FE","router":"4F0500","type":"energy","cUse":1163,"todUse":4680,"yesUse":0}
640
+ begin
641
+ data = JSON.parse data[2, data.length]
642
+ debug and ( p data.inspect )
643
+ rescue
644
+ STDERR.puts 'cannot parse ' + data.to_s
645
+ data = nil
646
+ end
647
+ debug and ( p data )
648
+ if data
629
649
  data = {
630
650
  'message' => {
631
- 'usage' => match[1].to_i,
632
- 'max' => match[2].to_i,
633
- 'today' => match[3].to_i
651
+ 'usage' => data['cUse'],
652
+ # 'max' => 'unused now',
653
+ 'today' => data['todUse']
634
654
  }
635
655
  }
636
656
  data['timestamp'] = Time.now.to_s
@@ -682,7 +702,7 @@ class LightWaveRF
682
702
  end
683
703
 
684
704
  def raw command, listen = false, debug = false
685
- debug and ( p self.time + ' ' + __method__.to_s + ' ' + command )
705
+ debug and ( p self.time + ' ' + __method__.to_s + ' ' + command.to_s )
686
706
  response = nil
687
707
  # Get host address or broadcast address
688
708
  host = self.get_config['host'] || '255.255.255.255'
@@ -699,14 +719,16 @@ class LightWaveRF
699
719
  # Bind socket to listen for response
700
720
  begin
701
721
  listener.bind '0.0.0.0', 9761
702
- rescue
703
- response = "can't bind to listen for a reply"
722
+ rescue StandardError => e
723
+ response = "can't bind to listen for a reply; " + e.to_s
704
724
  end
705
725
  end
706
726
  # Broadcast command to server
707
- debug and ( p self.time 'sending...' )
708
- listener.send command, 0, host, 9760
709
- debug and ( p self.time 'sent' )
727
+ if command
728
+ debug and ( p self.time 'sending...' )
729
+ listener.send command, 0, host, 9760
730
+ debug and ( p self.time 'sent' )
731
+ end
710
732
  # Receive response
711
733
  if listen and ! response
712
734
  debug and ( p self.time 'receiving...' )
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.10.0
4
+ version: 0.11.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-11-20 00:00:00.000000000 Z
14
+ date: 2016-01-11 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: htmlentities