class Netatmo::Weather::Device

Attributes

code[RW]
dashboard_data[RW]
data_types[RW]
firmware[RW]
id[RW]
last_message[RW]
last_seen[RW]
last_setup[RW]
module_name[RW]
reachable[RW]
rf_status[RW]
type[RW]

Public Class Methods

new(data) click to toggle source
# File lib/netatmo/weather/device.rb, line 34
def initialize(data)
  self.id = data['_id']
  self.type = Netatmo::Util::DeviceType.value(data['type'])
  self.code = data['type']
  self.data_types = data['data_type']
  self.module_name = data['module_name']
  self.reachable = data['reachable']
  self.firmware = data['firmware']
  self.last_setup = Time.at(data['last_setup']) if data['last_setup']
  self.last_message = Time.at(data['last_message']) if data['last_message']
  self.last_seen = Time.at(data['last_seen']) if data['last_seen']
  self.rf_status = data['rf_status']
  self.data_types = [] if data_types.nil?
end
parse(data) click to toggle source
# File lib/netatmo/weather/device.rb, line 14
def self.parse(data)
  type = Netatmo::Util::DeviceType.value(data['type'])

  if type.base_station?
    Netatmo::Weather::BaseStation.new(data)
  elsif type.outdoor_module?
    Netatmo::Weather::OutdoorModule.new(data)
  elsif type.wind_gauge?
    Netatmo::Weather::WindGauge.new(data)
  elsif type.rain_gauge?
    Netatmo::Weather::RainGauge.new(data)
  elsif type.indoor_module?
    Netatmo::Weather::IndoorModule.new(data)
  elsif type.home_coach?
    Netatmo::AirCare::HealthCoach.new(data)
  else
    Device.new(data)
  end
end

Public Instance Methods

battery?() click to toggle source
# File lib/netatmo/weather/device.rb, line 85
def battery?
  respond_to?(:battery_status)
end
co2?() click to toggle source
# File lib/netatmo/weather/device.rb, line 53
def co2?
  respond_to?(:co2) && data_types.include?('CO2')
end
data() click to toggle source
# File lib/netatmo/weather/device.rb, line 89
def data
  d = []
  d << co2 if co2?
  d << humidity if humidity?
  d << noise if noise?
  d << temperature if temperature?
  d << pressure if pressure?
  d << wind if wind?
  d << rain if rain?

  d
end
health_index?() click to toggle source
# File lib/netatmo/weather/device.rb, line 81
def health_index?
  respond_to?(:health_index) && data_types.include?('health_idx')
end
humidity?() click to toggle source
# File lib/netatmo/weather/device.rb, line 57
def humidity?
  respond_to?(:humidity) && data_types.include?('Humidity')
end
name() click to toggle source
# File lib/netatmo/weather/device.rb, line 49
def name
  module_name
end
noise?() click to toggle source
# File lib/netatmo/weather/device.rb, line 61
def noise?
  respond_to?(:noise) && data_types.include?('Noise')
end
pressure?() click to toggle source
# File lib/netatmo/weather/device.rb, line 69
def pressure?
  respond_to?(:pressure) && data_types.include?('Pressure')
end
rain?() click to toggle source
# File lib/netatmo/weather/device.rb, line 73
def rain?
  respond_to?(:rain) && data_types.include?('Rain')
end
temperature?() click to toggle source
# File lib/netatmo/weather/device.rb, line 65
def temperature?
  respond_to?(:temperature) && data_types.include?('Temperature')
end
values() click to toggle source

REWORK

# File lib/netatmo/weather/device.rb, line 103
def values
  h = {}
  h[:co2] = co2 if co2?
  h[:humidity] = humidity if humidity?
  h[:noise] = noise if noise?
  h[:temperature] = temperature if temperature?
  h[:pressure] = pressure if pressure?
  h[:wind] = wind if wind?
  h[:rain] = rain if rain?

  h
end
wind?() click to toggle source
# File lib/netatmo/weather/device.rb, line 77
def wind?
  respond_to?(:wind) && data_types.include?('Wind')
end