Class: EmuPower::Types::Notification

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

Overview

Base class for notifications

Constant Summary collapse

UNIX_TIME_OFFSET =
946684800

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_macObject

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_macObject

Returns the value of attribute meter_mac.



12
13
14
# File 'lib/emu_power/types.rb', line 12

def meter_mac
  @meter_mac
end

#rawObject

Returns the value of attribute raw.



10
11
12
# File 'lib/emu_power/types.rb', line 10

def raw
  @raw
end

#timestampObject

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 timestamp
  @timestamp
end

Class Method Details

.root_nameObject

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

.subclassesObject



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