class WeatherLink::Client

Attributes

api[R]

Public Class Methods

new(api_key:, api_secret:, station_units: IMPERIAL_WEATHER_UNITS, desired_units: METRIC_WEATHER_UNITS) click to toggle source
# File lib/weatherlink/client.rb, line 7
def initialize(api_key:, api_secret:, station_units: IMPERIAL_WEATHER_UNITS, desired_units: METRIC_WEATHER_UNITS)
  @api = APIv2.new(api_key: api_key, api_secret: api_secret, units: station_units)
  @desired_units = desired_units
end

Public Instance Methods

attach_units(data) click to toggle source
# File lib/weatherlink/client.rb, line 12
def attach_units(data)
  data.map do |field, value|
    unit = api.unit_for(field)
    [field, unit ? Unit.new("#{value} #{unit}") : value]
  end.to_h
end
convert(field, value) click to toggle source
# File lib/weatherlink/client.rb, line 23
def convert(field, value)
  desired_unit = desired_unit_for(field)
  return value unless desired_unit

  value.convert_to(desired_unit)
end
desired_unit_for(field) click to toggle source
# File lib/weatherlink/client.rb, line 19
def desired_unit_for(field)
  desired_units.fetch(api.type_for(field))
end
node_by_device_id_hex(device_id_hex) click to toggle source
# File lib/weatherlink/client.rb, line 50
def node_by_device_id_hex(device_id_hex)
  nodes.select { |n| n.device_id_hex == device_id_hex }.first
end
nodes() click to toggle source
# File lib/weatherlink/client.rb, line 44
def nodes
  @nodes ||= api.nodes['nodes'].map do |data|
    Node.new(self, data)
  end
end
sensor_by_lsid(lsid) click to toggle source
# File lib/weatherlink/client.rb, line 60
def sensor_by_lsid(lsid)
  sensors.select { |s| s.lsid == lsid }.first
end
sensors() click to toggle source
# File lib/weatherlink/client.rb, line 54
def sensors
  @sensors ||= api.sensors['sensors'].map do |data|
    Sensor.new(self, data)
  end
end
station() click to toggle source
# File lib/weatherlink/client.rb, line 36
def station
  stations.first
end
stations() click to toggle source
# File lib/weatherlink/client.rb, line 30
def stations
  @stations ||= api.station['stations'].map do |data|
    Station.new(self, data) if data
  end
end
stations_by_device_id_hex(device_id_hex) click to toggle source
# File lib/weatherlink/client.rb, line 40
def stations_by_device_id_hex(device_id_hex)
  stations.select { |s| s.gateway_id_hex == device_id_hex }.first
end