Class: EmuPower::Types::InstantaneousDemand

Inherits:
Notification show all
Defined in:
lib/emu_power/types.rb

Constant Summary

Constants inherited from Notification

Notification::UNIX_TIME_OFFSET

Instance Attribute Summary collapse

Attributes inherited from Notification

#device_mac, #meter_mac, #raw, #timestamp

Instance Method Summary collapse

Methods inherited from Notification

#initialize, #parse_bool, #parse_hex, root_name, subclasses

Constructor Details

This class inherits a constructor from EmuPower::Types::Notification

Instance Attribute Details

#digits_leftObject

Returns the value of attribute digits_left.



92
93
94
# File 'lib/emu_power/types.rb', line 92

def digits_left
  @digits_left
end

#digits_rightObject

Returns the value of attribute digits_right.



91
92
93
# File 'lib/emu_power/types.rb', line 91

def digits_right
  @digits_right
end

#divisorObject

Returns the value of attribute divisor.



90
91
92
# File 'lib/emu_power/types.rb', line 90

def divisor
  @divisor
end

#multiplierObject

Returns the value of attribute multiplier.



89
90
91
# File 'lib/emu_power/types.rb', line 89

def multiplier
  @multiplier
end

#raw_demandObject

Returns the value of attribute raw_demand.



88
89
90
# File 'lib/emu_power/types.rb', line 88

def raw_demand
  @raw_demand
end

#suppress_leading_zeroesObject

Returns the value of attribute suppress_leading_zeroes.



93
94
95
# File 'lib/emu_power/types.rb', line 93

def suppress_leading_zeroes
  @suppress_leading_zeroes
end

Instance Method Details

#build(hash) ⇒ Object



95
96
97
98
99
100
101
102
# File 'lib/emu_power/types.rb', line 95

def build(hash)
	self.raw_demand = parse_hex('Demand')
	self.multiplier = parse_hex('Multiplier')
	self.divisor = parse_hex('Divisor')
	self.digits_right = parse_hex('DigitsRight')
	self.digits_left = parse_hex('DigitsLeft')
	self.suppress_leading_zeroes = parse_bool('SuppressLeadingZero')
end

#demandObject

Return computed demand in KW. This may return nil if data is missing.



105
106
107
108
109
# File 'lib/emu_power/types.rb', line 105

def demand
	return 0 if self.divisor == 0
	return nil if self.multiplier.nil? || self.raw_demand.nil? || self.divisor.nil?
	return self.multiplier * self.raw_demand / Float(self.divisor)
end