Class: EmuPower::Notifications::Notification
- Inherits:
-
Object
- Object
- EmuPower::Notifications::Notification
- Defined in:
- lib/emu_power/notifications.rb
Overview
Base class for notifications
Direct Known Subclasses
BlockPriceDetail, ConnectionStatus, CurrentPeriodUsage, CurrentSummationDelivered, DeviceInfo, FastPollStatus, InstantaneousDemand, LastPeriodUsage, MessageCluster, MeterInfo, MeterList, NetworkInfo, PriceCluster, ScheduleInfo, TimeCluster
Constant Summary collapse
- UNIX_TIME_OFFSET =
Timestamp of Jan 1st 2000. Used to shift epoch to standard timestamp.
946684800
Instance Attribute Summary collapse
-
#device_mac ⇒ Object
Returns the value of attribute device_mac.
-
#meter_mac ⇒ Object
Returns the value of attribute meter_mac.
-
#raw ⇒ Object
Returns the value of attribute raw.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Class Method Summary collapse
-
.root_name ⇒ Object
Name of the XML root object corresponding to this type.
- .subclasses ⇒ Object
Instance Method Summary collapse
- #build(hash) ⇒ Object
-
#initialize(hash) ⇒ Notification
constructor
A new instance of Notification.
-
#parse_amount(prop, mul_prop = 'Multiplier', div_prop = 'Divisor') ⇒ Object
Calculate real total from divisors and multipliers.
- #parse_bool(prop) ⇒ Object
- #parse_hex(prop) ⇒ Object
- #parse_timestamp(prop) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(hash) ⇒ Notification
Returns a new instance of Notification.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 = ('TimeStamp') # Build out type-specific fields build(hash) end |
Instance Attribute Details
#device_mac ⇒ Object
Returns the value of attribute device_mac.
15 16 17 |
# File 'lib/emu_power/notifications.rb', line 15 def device_mac @device_mac end |
#meter_mac ⇒ Object
Returns the value of attribute meter_mac.
16 17 18 |
# File 'lib/emu_power/notifications.rb', line 16 def meter_mac @meter_mac end |
#raw ⇒ Object
Returns the value of attribute raw.
14 15 16 |
# File 'lib/emu_power/notifications.rb', line 14 def raw @raw end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
17 18 19 |
# File 'lib/emu_power/notifications.rb', line 17 def @timestamp end |
Class Method Details
.root_name ⇒ Object
Name of the XML root object corresponding to this type
76 77 78 |
# File 'lib/emu_power/notifications.rb', line 76 def self.root_name return self.name.split('::').last end |
.subclasses ⇒ Object
80 81 82 83 84 |
# File 'lib/emu_power/notifications.rb', line 80 def self.subclasses return ObjectSpace.each_object(::Class).select do |k| k < self end end |
Instance Method Details
#build(hash) ⇒ Object
37 38 39 |
# File 'lib/emu_power/notifications.rb', line 37 def build(hash) # Overridden by subclasses end |
#parse_amount(prop, mul_prop = 'Multiplier', div_prop = 'Divisor') ⇒ Object
Calculate real total from divisors and multipliers
60 61 62 63 64 65 66 67 68 69 |
# 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) ⇒ Object
53 54 55 56 57 |
# 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) ⇒ Object
47 48 49 50 51 |
# 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) ⇒ Object
41 42 43 44 45 |
# File 'lib/emu_power/notifications.rb', line 41 def (prop) v = @raw[prop] return nil if v == nil return Integer(v) + 946684800 end |
#to_s ⇒ Object
71 72 73 |
# File 'lib/emu_power/notifications.rb', line 71 def to_s "#{self.class.root_name} Notification: #{@raw.to_s}" end |