Class: WeatherLink::Station
Defined Under Namespace
Classes: LocalSensor
Instance Attribute Summary collapse
Attributes inherited from HashWrapper
#data
Instance Method Summary
collapse
Constructor Details
#initialize(client, data) ⇒ Station
Returns a new instance of Station.
17
18
19
20
|
# File 'lib/weatherlink/station.rb', line 17
def initialize(client, data)
@client = client
super(data)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class WeatherLink::HashWrapper
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
15
16
17
|
# File 'lib/weatherlink/station.rb', line 15
def client
@client
end
|
Instance Method Details
#current ⇒ Object
38
39
40
41
42
43
44
|
# 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 ⇒ Object
26
27
28
|
# File 'lib/weatherlink/station.rb', line 26
def inspect
to_s
end
|
#last_day ⇒ Object
58
59
60
|
# File 'lib/weatherlink/station.rb', line 58
def last_day
last_seconds(86_400)
end
|
#last_hour ⇒ Object
54
55
56
|
# File 'lib/weatherlink/station.rb', line 54
def last_hour
last_seconds(3600)
end
|
#last_seconds(seconds) ⇒ Object
46
47
48
49
50
51
52
|
# 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 ⇒ Object
62
63
64
65
66
67
68
69
|
# 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) ⇒ Object
34
35
36
|
# File 'lib/weatherlink/station.rb', line 34
def sensor(lsid)
sensors.select { |sensor| sensor.lsid == lsid }.first
end
|
#sensors ⇒ Object
30
31
32
|
# File 'lib/weatherlink/station.rb', line 30
def sensors
@sensors ||= client.sensors.select { |sensor| sensor.station_id == station_id }
end
|
#to_s ⇒ Object
22
23
24
|
# 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
|