Class: Netatmo::Weather::Device

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/netatmo/weather/device.rb

Direct Known Subclasses

BaseStation, BatteryDevice

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Device

Returns a new instance of Device.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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

Instance Attribute Details

#codeObject

Returns the value of attribute code.



10
11
12
# File 'lib/netatmo/weather/device.rb', line 10

def code
  @code
end

#dashboard_dataObject

Returns the value of attribute dashboard_data.



10
11
12
# File 'lib/netatmo/weather/device.rb', line 10

def dashboard_data
  @dashboard_data
end

#data_typesObject

Returns the value of attribute data_types.



10
11
12
# File 'lib/netatmo/weather/device.rb', line 10

def data_types
  @data_types
end

#firmwareObject

Returns the value of attribute firmware.



10
11
12
# File 'lib/netatmo/weather/device.rb', line 10

def firmware
  @firmware
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/netatmo/weather/device.rb', line 10

def id
  @id
end

#last_messageObject

Returns the value of attribute last_message.



10
11
12
# File 'lib/netatmo/weather/device.rb', line 10

def last_message
  @last_message
end

#last_seenObject

Returns the value of attribute last_seen.



10
11
12
# File 'lib/netatmo/weather/device.rb', line 10

def last_seen
  @last_seen
end

#last_setupObject

Returns the value of attribute last_setup.



10
11
12
# File 'lib/netatmo/weather/device.rb', line 10

def last_setup
  @last_setup
end

#module_nameObject

Returns the value of attribute module_name.



10
11
12
# File 'lib/netatmo/weather/device.rb', line 10

def module_name
  @module_name
end

#reachableObject

Returns the value of attribute reachable.



10
11
12
# File 'lib/netatmo/weather/device.rb', line 10

def reachable
  @reachable
end

#rf_statusObject

Returns the value of attribute rf_status.



10
11
12
# File 'lib/netatmo/weather/device.rb', line 10

def rf_status
  @rf_status
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/netatmo/weather/device.rb', line 10

def type
  @type
end

Class Method Details

.parse(data) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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

Instance Method Details

#battery?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/netatmo/weather/device.rb', line 85

def battery?
  respond_to?(:battery_status)
end

#co2?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/netatmo/weather/device.rb', line 53

def co2?
  respond_to?(:co2) && data_types.include?('CO2')
end

#dataObject



89
90
91
92
93
94
95
96
97
98
99
100
# 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?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/netatmo/weather/device.rb', line 81

def health_index?
  respond_to?(:health_index) && data_types.include?('health_idx')
end

#humidity?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/netatmo/weather/device.rb', line 57

def humidity?
  respond_to?(:humidity) && data_types.include?('Humidity')
end

#nameObject



49
50
51
# File 'lib/netatmo/weather/device.rb', line 49

def name
  module_name
end

#noise?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/netatmo/weather/device.rb', line 61

def noise?
  respond_to?(:noise) && data_types.include?('Noise')
end

#pressure?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/netatmo/weather/device.rb', line 69

def pressure?
  respond_to?(:pressure) && data_types.include?('Pressure')
end

#rain?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/netatmo/weather/device.rb', line 73

def rain?
  respond_to?(:rain) && data_types.include?('Rain')
end

#temperature?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/netatmo/weather/device.rb', line 65

def temperature?
  respond_to?(:temperature) && data_types.include?('Temperature')
end

#valuesObject

REWORK



103
104
105
106
107
108
109
110
111
112
113
114
# 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?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/netatmo/weather/device.rb', line 77

def wind?
  respond_to?(:wind) && data_types.include?('Wind')
end