Class: Netatmo::Weather::Device
- Inherits:
-
Object
- Object
- Netatmo::Weather::Device
- Extended by:
- Forwardable
- Defined in:
- lib/netatmo/weather/device.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#dashboard_data ⇒ Object
Returns the value of attribute dashboard_data.
-
#data_types ⇒ Object
Returns the value of attribute data_types.
-
#firmware ⇒ Object
Returns the value of attribute firmware.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_message ⇒ Object
Returns the value of attribute last_message.
-
#last_seen ⇒ Object
Returns the value of attribute last_seen.
-
#last_setup ⇒ Object
Returns the value of attribute last_setup.
-
#module_name ⇒ Object
Returns the value of attribute module_name.
-
#reachable ⇒ Object
Returns the value of attribute reachable.
-
#rf_status ⇒ Object
Returns the value of attribute rf_status.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #battery? ⇒ Boolean
- #co2? ⇒ Boolean
- #data ⇒ Object
- #health_index? ⇒ Boolean
- #humidity? ⇒ Boolean
-
#initialize(data) ⇒ Device
constructor
A new instance of Device.
- #name ⇒ Object
- #noise? ⇒ Boolean
- #pressure? ⇒ Boolean
- #rain? ⇒ Boolean
- #temperature? ⇒ Boolean
-
#values ⇒ Object
REWORK.
- #wind? ⇒ Boolean
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. = 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
#code ⇒ Object
Returns the value of attribute code.
10 11 12 |
# File 'lib/netatmo/weather/device.rb', line 10 def code @code end |
#dashboard_data ⇒ Object
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_types ⇒ Object
Returns the value of attribute data_types.
10 11 12 |
# File 'lib/netatmo/weather/device.rb', line 10 def data_types @data_types end |
#firmware ⇒ Object
Returns the value of attribute firmware.
10 11 12 |
# File 'lib/netatmo/weather/device.rb', line 10 def firmware @firmware end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/netatmo/weather/device.rb', line 10 def id @id end |
#last_message ⇒ Object
Returns the value of attribute last_message.
10 11 12 |
# File 'lib/netatmo/weather/device.rb', line 10 def @last_message end |
#last_seen ⇒ Object
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_setup ⇒ Object
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_name ⇒ Object
Returns the value of attribute module_name.
10 11 12 |
# File 'lib/netatmo/weather/device.rb', line 10 def module_name @module_name end |
#reachable ⇒ Object
Returns the value of attribute reachable.
10 11 12 |
# File 'lib/netatmo/weather/device.rb', line 10 def reachable @reachable end |
#rf_status ⇒ Object
Returns the value of attribute rf_status.
10 11 12 |
# File 'lib/netatmo/weather/device.rb', line 10 def rf_status @rf_status end |
#type ⇒ Object
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
85 86 87 |
# File 'lib/netatmo/weather/device.rb', line 85 def battery? respond_to?(:battery_status) end |
#co2? ⇒ Boolean
53 54 55 |
# File 'lib/netatmo/weather/device.rb', line 53 def co2? respond_to?(:co2) && data_types.include?('CO2') end |
#data ⇒ Object
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
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
57 58 59 |
# File 'lib/netatmo/weather/device.rb', line 57 def humidity? respond_to?(:humidity) && data_types.include?('Humidity') end |
#name ⇒ Object
49 50 51 |
# File 'lib/netatmo/weather/device.rb', line 49 def name module_name end |
#noise? ⇒ Boolean
61 62 63 |
# File 'lib/netatmo/weather/device.rb', line 61 def noise? respond_to?(:noise) && data_types.include?('Noise') end |
#pressure? ⇒ Boolean
69 70 71 |
# File 'lib/netatmo/weather/device.rb', line 69 def pressure? respond_to?(:pressure) && data_types.include?('Pressure') end |
#rain? ⇒ Boolean
73 74 75 |
# File 'lib/netatmo/weather/device.rb', line 73 def rain? respond_to?(:rain) && data_types.include?('Rain') end |
#temperature? ⇒ Boolean
65 66 67 |
# File 'lib/netatmo/weather/device.rb', line 65 def temperature? respond_to?(:temperature) && data_types.include?('Temperature') end |
#values ⇒ Object
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
77 78 79 |
# File 'lib/netatmo/weather/device.rb', line 77 def wind? respond_to?(:wind) && data_types.include?('Wind') end |