lightwaverf 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/lightwaverf-config-json +1 -1
- data/lib/lightwaverf.rb +30 -11
- metadata +2 -2
    
        data/bin/lightwaverf-config-json
    CHANGED
    
    
    
        data/lib/lightwaverf.rb
    CHANGED
    
    | @@ -20,7 +20,8 @@ class LightWaveRF | |
| 20 20 |  | 
| 21 21 | 
             
              def config_json
         | 
| 22 22 | 
             
                require 'json'
         | 
| 23 | 
            -
                 | 
| 23 | 
            +
                require 'pp'
         | 
| 24 | 
            +
                JSON.generate self.get_config
         | 
| 24 25 | 
             
              end
         | 
| 25 26 |  | 
| 26 27 | 
             
              def set_config_file file
         | 
| @@ -47,9 +48,10 @@ class LightWaveRF | |
| 47 48 | 
             
                rooms = { }
         | 
| 48 49 | 
             
                r = 1
         | 
| 49 50 | 
             
                config['room'].each do | name, devices |
         | 
| 50 | 
            -
                  rooms[name] = { 'id' => 'R' + r.to_s, 'device' => { }}
         | 
| 51 | 
            +
                  rooms[name] = { 'id' => 'R' + r.to_s, 'name' => name, 'device' => { }}
         | 
| 51 52 | 
             
                  d = 1
         | 
| 52 53 | 
             
                  devices.each do | device |
         | 
| 54 | 
            +
                    # @todo possibly need to complicate this to get a device name back in here
         | 
| 53 55 | 
             
                    rooms[name]['device'][device] = 'D' + d.to_s
         | 
| 54 56 | 
             
                    d += 1
         | 
| 55 57 | 
             
                  end
         | 
| @@ -64,7 +66,7 @@ class LightWaveRF | |
| 64 66 | 
             
                    state = 'F0'
         | 
| 65 67 | 
             
                  when 'on'
         | 
| 66 68 | 
             
                    state = 'F1'
         | 
| 67 | 
            -
                  when 1.. | 
| 69 | 
            +
                  when 1..100
         | 
| 68 70 | 
             
                    state = 'FdP' + ( state * 0.32 ).round.to_s
         | 
| 69 71 | 
             
                end
         | 
| 70 72 | 
             
                state
         | 
| @@ -80,7 +82,8 @@ class LightWaveRF | |
| 80 82 | 
             
              #   device: (String)
         | 
| 81 83 | 
             
              #   state: (String)
         | 
| 82 84 | 
             
              def command room, device, state
         | 
| 83 | 
            -
                 | 
| 85 | 
            +
                # @todo get the device name in here...
         | 
| 86 | 
            +
               '666,!' + room['id'] + room['device'][device] + state + '|' + room['name'] + ' ' + room['id'] + '|via @pauly'
         | 
| 84 87 | 
             
              end
         | 
| 85 88 |  | 
| 86 89 | 
             
              # Turn one of your devices on or off
         | 
| @@ -99,7 +102,7 @@ class LightWaveRF | |
| 99 102 | 
             
                if rooms[room] && device && state && rooms[room]['device'][device]
         | 
| 100 103 | 
             
                  command = self.command rooms[room], device, state
         | 
| 101 104 | 
             
                  debug && ( p 'command is ' + command )
         | 
| 102 | 
            -
                   | 
| 105 | 
            +
                  self.raw command
         | 
| 103 106 | 
             
                else
         | 
| 104 107 | 
             
                  STDERR.puts self.usage
         | 
| 105 108 | 
             
                end
         | 
| @@ -115,12 +118,28 @@ class LightWaveRF | |
| 115 118 | 
             
              end
         | 
| 116 119 |  | 
| 117 120 | 
             
              def energy
         | 
| 118 | 
            -
                 | 
| 119 | 
            -
                 | 
| 120 | 
            -
             | 
| 121 | 
            -
                 | 
| 122 | 
            -
             | 
| 123 | 
            -
                 | 
| 121 | 
            +
                data = self.raw '666,@?'
         | 
| 122 | 
            +
                begin
         | 
| 123 | 
            +
                  /W=(?<usage>\d+),(?<max>\d+),(?<today>\d+),(?<yesterday>\d+)/.match( data )
         | 
| 124 | 
            +
                rescue
         | 
| 125 | 
            +
                  data
         | 
| 126 | 
            +
                end
         | 
| 127 | 
            +
              end
         | 
| 128 | 
            +
             | 
| 129 | 
            +
              def raw command
         | 
| 130 | 
            +
                response = nil
         | 
| 131 | 
            +
                begin
         | 
| 132 | 
            +
                  listener = UDPSocket.new
         | 
| 133 | 
            +
                  listener.bind '0.0.0.0', 9761
         | 
| 134 | 
            +
                rescue
         | 
| 135 | 
            +
                  response = "can't bind to listen for a reply"
         | 
| 136 | 
            +
                end
         | 
| 137 | 
            +
                UDPSocket.new.send command, 0, self.get_config['host'], 9760
         | 
| 138 | 
            +
                if ! response
         | 
| 139 | 
            +
                  response, addr = listener.recvfrom 200
         | 
| 140 | 
            +
                  listener.close
         | 
| 141 | 
            +
                end
         | 
| 142 | 
            +
                response
         | 
| 124 143 | 
             
              end
         | 
| 125 144 |  | 
| 126 145 | 
             
            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.0. | 
| 4 | 
            +
              version: 0.0.6
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2012-12- | 
| 12 | 
            +
            date: 2012-12-30 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies: []
         | 
| 14 14 | 
             
            description: Interact with lightwaverf wifi link from the command line
         | 
| 15 15 | 
             
            email: pauly@clarkeology.com
         |