class WeatherLink::LocalClient
Constants
- META_KEYS
Attributes
api[R]
desired_units[R]
Public Class Methods
new(host:, station_units: IMPERIAL_WEATHER_UNITS, desired_units: METRIC_WEATHER_UNITS)
click to toggle source
# File lib/weatherlink/local_client.rb, line 9 def initialize(host:, station_units: IMPERIAL_WEATHER_UNITS, desired_units: METRIC_WEATHER_UNITS) @api = LocalAPIv1.new(host: host, units: station_units) @desired_units = desired_units end
Public Instance Methods
attach_units(data)
click to toggle source
# File lib/weatherlink/local_client.rb, line 22 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/local_client.rb, line 33 def convert(field, value) desired_unit = desired_unit_for(field) return value unless desired_unit value.convert_to(desired_unit) end
current_conditions()
click to toggle source
# File lib/weatherlink/local_client.rb, line 40 def current_conditions sensors = api.current_conditions['conditions'].map do |conditions| SensorData.new(self, transform_like_api_v2(conditions)) end SensorDataCollection.new(self, sensors) end
desired_unit_for(field)
click to toggle source
# File lib/weatherlink/local_client.rb, line 29 def desired_unit_for(field) desired_units.fetch(api.type_for(field)) end
sensors()
click to toggle source
# File lib/weatherlink/local_client.rb, line 54 def sensors @sensors ||= api.sensors['sensors'].map do |data| Sensor.new(self, data) end end
stations()
click to toggle source
# File lib/weatherlink/local_client.rb, line 48 def stations @stations ||= api.station['stations'].map do |data| Station.new(self, data) if data end end
transform_like_api_v2(hash)
click to toggle source
# File lib/weatherlink/local_client.rb, line 16 def transform_like_api_v2(hash) hash.select { |k, _| META_KEYS.include?(k) }.merge('data' => [{ 'ts' => Time.now.to_i, }.merge(hash.reject { |k, _| META_KEYS.include?(k) })]) end