class WeatherLink::Station

Constants

LocalSensor

Attributes

client[R]

Public Class Methods

new(client, data) click to toggle source
Calls superclass method WeatherLink::HashWrapper::new
# File lib/weatherlink/station.rb, line 17
def initialize(client, data)
  @client = client
  super(data)
end

Public Instance Methods

current() click to toggle source
# File lib/weatherlink/station.rb, line 38
def current
  sensors = client.api.current(station_id)['sensors'].map do |sensor|
    SensorData.new(client, sensor)
  end

  SensorDataCollection.new(client, sensors)
end
inspect() click to toggle source
# File lib/weatherlink/station.rb, line 26
def inspect
  to_s
end
last_day() click to toggle source
# File lib/weatherlink/station.rb, line 58
def last_day
  last_seconds(86_400)
end
last_hour() click to toggle source
# File lib/weatherlink/station.rb, line 54
def last_hour
  last_seconds(3600)
end
last_seconds(seconds) click to toggle source
# File lib/weatherlink/station.rb, line 46
def last_seconds(seconds)
  sensors = client.api.last_seconds(station_id, seconds)['sensors'].map do |sensor|
    SensorData.new(client, sensor)
  end

  SensorDataCollection.new(client, sensors)
end
local_sensors() click to toggle source
# File lib/weatherlink/station.rb, line 62
def local_sensors
  @local_sensors ||= current.health.select { |s| s.include?('ip_v4_address') }.map do |health|
    sensor = client.sensor_by_lsid(health.lsid)
    device_id_hex = sensor.parent_device_id_hex
    device = client.node_by_device_id_hex(device_id_hex) || client.stations_by_device_id_hex(device_id_hex)
    LocalSensor.new(device: device, host: health.fetch('ip_v4_address'))
  end
end
sensor(lsid) click to toggle source
# File lib/weatherlink/station.rb, line 34
def sensor(lsid)
  sensors.select { |sensor| sensor.lsid == lsid }.first
end
sensors() click to toggle source
# File lib/weatherlink/station.rb, line 30
def sensors
  @sensors ||= client.sensors.select { |sensor| sensor.station_id == station_id }
end
to_s() click to toggle source
# File lib/weatherlink/station.rb, line 22
def to_s
  "#<#{self.class.name} station_id=#{station_id} gateway_id_hex=#{gateway_id_hex} (#{station_name})>"
end