Class: EmuPower::Types::Notification
- Inherits:
-
Object
- Object
- EmuPower::Types::Notification
- Defined in:
- lib/emu_power/types.rb
Overview
Base class for notifications
Direct Known Subclasses
ConnectionStatus, CurrentPeriodUsage, CurrentSummationDelivered, DeviceInfo, InstantaneousDemand, LastPeriodUsage, MessageCluster, MeterInfo, MeterList, NetworkInfo, PriceCluster, ProfileData, ScheduleInfo, TimeCluster
Constant Summary collapse
- UNIX_TIME_OFFSET =
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
The EMU sets timestamps relative to Jan 1st 2000 UTC.
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_bool(prop) ⇒ Object
- #parse_hex(prop) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Notification
Returns a new instance of Notification.
15 16 17 18 19 20 |
# File 'lib/emu_power/types.rb', line 15 def initialize(hash) @raw = hash @device_mac = @raw['DeviceMacId'] @meter_mac = @raw['MeterMacId'] build(hash) end |
Instance Attribute Details
#device_mac ⇒ Object
Returns the value of attribute device_mac.
11 12 13 |
# File 'lib/emu_power/types.rb', line 11 def device_mac @device_mac end |
#meter_mac ⇒ Object
Returns the value of attribute meter_mac.
12 13 14 |
# File 'lib/emu_power/types.rb', line 12 def meter_mac @meter_mac end |
#raw ⇒ Object
Returns the value of attribute raw.
10 11 12 |
# File 'lib/emu_power/types.rb', line 10 def raw @raw end |
#timestamp ⇒ Object
The EMU sets timestamps relative to Jan 1st 2000 UTC. We convert these into more standard Unix epoch timestamps by adding the appropriate offset.
28 29 30 |
# File 'lib/emu_power/types.rb', line 28 def end |
Class Method Details
.root_name ⇒ Object
Name of the XML root object corresponding to this type
47 48 49 |
# File 'lib/emu_power/types.rb', line 47 def self.root_name return self.name.split('::').last end |
.subclasses ⇒ Object
51 52 53 54 55 |
# File 'lib/emu_power/types.rb', line 51 def self.subclasses return ObjectSpace.each_object(::Class).select do |k| k < self end end |
Instance Method Details
#build(hash) ⇒ Object
22 23 |
# File 'lib/emu_power/types.rb', line 22 def build(hash) end |
#parse_bool(prop) ⇒ Object
40 41 42 43 44 |
# File 'lib/emu_power/types.rb', line 40 def parse_bool(prop) v = @raw[prop] return nil if v.nil? return (@raw[prop] == 'Y') ? true : false end |
#parse_hex(prop) ⇒ Object
34 35 36 37 38 |
# File 'lib/emu_power/types.rb', line 34 def parse_hex(prop) v = @raw[prop] return nil if v.nil? return Integer(v) end |