Class: MFi::MPower
- Inherits:
-
Object
- Object
- MFi::MPower
- Defined in:
- lib/mpower.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#connect! ⇒ Object
Connect to the remote MPower device.
-
#disable(port = -1) ⇒ Object
Write disable port, disabling relay toggling
port
the port option, default is all. -
#enable(port = -1) ⇒ Object
Write enable port, allowing relay toggling
port
the port option, default is all. -
#initialize(opts) ⇒ MPower
constructor
Create MPower instance.
-
#sample(port = -1) ⇒ Object
Sample all metrics from the mPower device
port
the port option, default is all. -
#switch_off(port = -1) ⇒ Object
Switch off, or disable power on a given port
port
the port option, default is all. -
#switch_on(port = -1) ⇒ Object
Switch on, or enable power on a given port
port
the port option, default is all.
Constructor Details
#initialize(opts) ⇒ MPower
Create MPower instance
opts
connection options host, pass and user are required for SSH
38 39 40 41 42 |
# File 'lib/mpower.rb', line 38 def initialize opts @host = opts[:host] @pass = opts[:pass] @user = opts[:user] end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
30 31 32 |
# File 'lib/mpower.rb', line 30 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
30 31 32 |
# File 'lib/mpower.rb', line 30 def port @port end |
#user ⇒ Object
Returns the value of attribute user.
30 31 32 |
# File 'lib/mpower.rb', line 30 def user @user end |
Instance Method Details
#connect! ⇒ Object
Connect to the remote MPower device
45 46 47 |
# File 'lib/mpower.rb', line 45 def connect! @ssh = Net::SSH.start(@host, @user, :password => @pass) end |
#disable(port = -1) ⇒ Object
Write disable port, disabling relay toggling port
the port option, default is all
70 71 72 |
# File 'lib/mpower.rb', line 70 def disable port=-1 run(:func => "enableRead", :port => port) end |
#enable(port = -1) ⇒ Object
Write enable port, allowing relay toggling port
the port option, default is all
64 65 66 |
# File 'lib/mpower.rb', line 64 def enable port=-1 run(:func => "enableWrite", :port => port) end |
#sample(port = -1) ⇒ Object
Sample all metrics from the mPower device port
the port option, default is all
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mpower.rb', line 51 def sample port=-1 data = run(:func => "powerList", :port => port) unless data.key?("value") raise "No data available" end data["value"].shift number = 0 data["value"].map { |value| MPowerReading.new(number += 1, value) } end |
#switch_off(port = -1) ⇒ Object
Switch off, or disable power on a given port port
the port option, default is all
76 77 78 |
# File 'lib/mpower.rb', line 76 def switch_off port=-1 run(:func => "relayWrite", :port => port, :value => 0) end |
#switch_on(port = -1) ⇒ Object
Switch on, or enable power on a given port port
the port option, default is all
82 83 84 |
# File 'lib/mpower.rb', line 82 def switch_on port=-1 run(:func => "relayWrite", :port => port, :value => 1) end |