class NatureRemoE::Client

Public Class Methods

new(token) click to toggle source
# File lib/nature_remo_e/client.rb, line 8
def initialize(token)
  @token = token
end

Public Instance Methods

coefficient() click to toggle source
# File lib/nature_remo_e/client.rb, line 18
def coefficient
  echonetlite_properties[:coefficient]
end
cumulative_electric_energy_effective_digits() click to toggle source
# File lib/nature_remo_e/client.rb, line 22
def cumulative_electric_energy_effective_digits
  echonetlite_properties[:cumulative_electric_energy_effective_digits]
end
cumulative_electric_energy_unit() click to toggle source
# File lib/nature_remo_e/client.rb, line 30
def cumulative_electric_energy_unit
  echonetlite_properties[:cumulative_electric_energy_unit]
end
echonetlite_properties() click to toggle source
# File lib/nature_remo_e/client.rb, line 12
def echonetlite_properties
  device[:smart_meter][:echonetlite_properties].map do |echonetlite_property|
    [echonetlite_property[:name].to_sym, echonetlite_property[:val].to_i]
  end.to_h
end
measured_instantaneous() click to toggle source
# File lib/nature_remo_e/client.rb, line 38
def measured_instantaneous
  echonetlite_properties[:measured_instantaneous]
end
normal_direction_cumulative_electric_energy() click to toggle source
# File lib/nature_remo_e/client.rb, line 26
def normal_direction_cumulative_electric_energy
  echonetlite_properties[:normal_direction_cumulative_electric_energy]
end
reverse_direction_cumulative_electric_energy() click to toggle source
# File lib/nature_remo_e/client.rb, line 34
def reverse_direction_cumulative_electric_energy
  echonetlite_properties[:reverse_direction_cumulative_electric_energy]
end

Private Instance Methods

appliances() click to toggle source
# File lib/nature_remo_e/client.rb, line 51
def appliances
  response = client.get do |req|
    req.url '/1/appliances'
  end

  raise NatureRemoE::Error, JSON.parse(response.body, symbolize_names: true)[:message] if response.status != 200

  JSON.parse(response.body, symbolize_names: true)
end
client() click to toggle source
# File lib/nature_remo_e/client.rb, line 44
def client
  @client ||= Faraday.new(
    url: 'https://api.nature.global',
    headers: { Authorization: "Bearer #{@token}" }
  )
end
device() click to toggle source
# File lib/nature_remo_e/client.rb, line 61
def device
  appliance = appliances.find { |appliance| appliance[:type] == 'EL_SMART_METER' }

  raise NatureRemoE::Error, 'Device not found' if appliance.nil?

  appliance
end