class EmuPower::Notifications::Notification
Base class for notifications
Constants
- UNIX_TIME_OFFSET
Timestamp of Jan 1st 2000. Used to shift epoch to standard timestamp.
Attributes
device_mac[RW]
meter_mac[RW]
raw[RW]
timestamp[RW]
Public Class Methods
new(hash)
click to toggle source
# File lib/emu_power/notifications.rb, line 19 def initialize(hash) @raw = hash # All messages may contain this metadata @device_mac = @raw['DeviceMacId'] @meter_mac = @raw['MeterMacId'] # The EMU sets timestamps relative to Jan 1st 2000 UTC. We convert # these into more standard Unix epoch timestamps by adding the # appropriate offset. @timestamp = parse_timestamp('TimeStamp') # Build out type-specific fields build(hash) end
root_name()
click to toggle source
Name of the XML root object corresponding to this type
# File lib/emu_power/notifications.rb, line 76 def self.root_name return self.name.split('::').last end
subclasses()
click to toggle source
# File lib/emu_power/notifications.rb, line 80 def self.subclasses return ObjectSpace.each_object(::Class).select do |k| k < self end end
Public Instance Methods
build(hash)
click to toggle source
# File lib/emu_power/notifications.rb, line 37 def build(hash) # Overridden by subclasses end
parse_amount(prop, mul_prop = 'Multiplier', div_prop = 'Divisor')
click to toggle source
Calculate real total from divisors and multipliers
# File lib/emu_power/notifications.rb, line 60 def parse_amount(prop, mul_prop = 'Multiplier', div_prop = 'Divisor') multiplier = parse_hex(mul_prop) divisor = parse_hex(div_prop) v = parse_hex(prop) return 0.0 if v.nil? || multiplier.nil? || divisor.nil? return multiplier * v / Float(divisor) end
parse_bool(prop)
click to toggle source
# File lib/emu_power/notifications.rb, line 53 def parse_bool(prop) v = @raw[prop] return nil if v.nil? return (@raw[prop] == 'Y') ? true : false end
parse_hex(prop)
click to toggle source
# File lib/emu_power/notifications.rb, line 47 def parse_hex(prop) v = @raw[prop] return nil if v.nil? return Integer(v) end
parse_timestamp(prop)
click to toggle source
# File lib/emu_power/notifications.rb, line 41 def parse_timestamp(prop) v = @raw[prop] return nil if v == nil return Integer(v) + 946684800 end
to_s()
click to toggle source
# File lib/emu_power/notifications.rb, line 71 def to_s "#{self.class.root_name} Notification: #{@raw.to_s}" end