Class: MFi::MPowerReading

Inherits:
Object
  • Object
show all
Defined in:
lib/mpower.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port, opts) ⇒ MPowerReading

Returns a new instance of MPowerReading.



7
8
9
10
11
12
13
14
15
16
# File 'lib/mpower.rb', line 7

def initialize port, opts
  @port = port
  @enable = opts["enable"].to_i
  @relay = opts["relay"].to_i
  @power = opts["power"].to_f
  @energy = opts["energy"].to_f
  @current = opts["current"].to_f
  @voltage = opts["voltage"].to_f
  @powerfactor = opts["powerfactor"].to_f
end

Instance Attribute Details

#currentObject

Returns the value of attribute current.



5
6
7
# File 'lib/mpower.rb', line 5

def current
  @current
end

#enableObject

Returns the value of attribute enable.



5
6
7
# File 'lib/mpower.rb', line 5

def enable
  @enable
end

#energyObject

Returns the value of attribute energy.



5
6
7
# File 'lib/mpower.rb', line 5

def energy
  @energy
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/mpower.rb', line 5

def port
  @port
end

#powerObject

Returns the value of attribute power.



5
6
7
# File 'lib/mpower.rb', line 5

def power
  @power
end

#powerfactorObject

Returns the value of attribute powerfactor.



5
6
7
# File 'lib/mpower.rb', line 5

def powerfactor
  @powerfactor
end

#relayObject

Returns the value of attribute relay.



5
6
7
# File 'lib/mpower.rb', line 5

def relay
  @relay
end

#voltageObject

Returns the value of attribute voltage.



5
6
7
# File 'lib/mpower.rb', line 5

def voltage
  @voltage
end

Instance Method Details

#fmt(v) ⇒ Object



22
23
24
# File 'lib/mpower.rb', line 22

def fmt v
  "%5.1f" % v
end

#to_sObject



18
19
20
# File 'lib/mpower.rb', line 18

def to_s
  "Port #{@port}: #{fmt(@power)}W (#{fmt(@powerfactor)}pf #{fmt(@current)}A #{fmt(@voltage)}V)"
end