Class: Insnergy::Power

Inherits:
Object
  • Object
show all
Defined in:
lib/insnergy-api-ruby-client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Power

Returns a new instance of Power.



67
68
69
70
71
72
73
74
75
# File 'lib/insnergy-api-ruby-client.rb', line 67

def initialize(opts = {})
  @device_type_pointer = opts['devices'][0].keys.include? 'sub_dev_id'
  case device_type_pointer
  when true
    device_is_multiple_hole(opts)
  when false
    device_is_single_hole(opts)
  end
end

Instance Attribute Details

#aliasObject (readonly)

Returns the value of attribute alias.



65
66
67
# File 'lib/insnergy-api-ruby-client.rb', line 65

def alias
  @alias
end

#device_type_pointerObject (readonly)

Returns the value of attribute device_type_pointer.



65
66
67
# File 'lib/insnergy-api-ruby-client.rb', line 65

def device_type_pointer
  @device_type_pointer
end

#month_total_power_valueObject (readonly)

Returns the value of attribute month_total_power_value.



65
66
67
# File 'lib/insnergy-api-ruby-client.rb', line 65

def month_total_power_value
  @month_total_power_value
end

#typeObject (readonly)

Returns the value of attribute type.



65
66
67
# File 'lib/insnergy-api-ruby-client.rb', line 65

def type
  @type
end

Instance Method Details

#device_is_multiple_hole(opts) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/insnergy-api-ruby-client.rb', line 77

def device_is_multiple_hole(opts)
  @type = "multiple hole"
  holes = opts['devices'][0]['data'][0]['value'].split(';')
  names = opts['devices'][0]['sub_alias'].to_s.split(';') 
  for i in 1..holes.size 
    self.class.send(:attr_reader, "hole_#{i}_power_value", "hole_#{i}_alias")  
    instance_variable_set("@hole_#{i}_power_value", holes[i - 1].to_f)
    instance_variable_set("@hole_#{i}_alias", names[i - 1].split('|')[1].split(':')[1])  
  end
end

#device_is_single_hole(opts) ⇒ Object



88
89
90
91
92
# File 'lib/insnergy-api-ruby-client.rb', line 88

def device_is_single_hole(opts)
  @type = "single hole"
  @power_value = opts['devices'][0]['data'][0]['value'].to_f
  @alias = opts['devices'][0]['alias']
end