netatmo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +169 -0
  4. data/lib/netatmo.rb +20 -0
  5. data/lib/netatmo/administrative.rb +23 -0
  6. data/lib/netatmo/air_care/home_coach.rb +25 -0
  7. data/lib/netatmo/battery_status/battery_status.rb +34 -0
  8. data/lib/netatmo/battery_status/indoor_battery_status.rb +16 -0
  9. data/lib/netatmo/battery_status/outdoor_battery_status.rb +16 -0
  10. data/lib/netatmo/battery_status/wind_gauge_battery_status.rb +16 -0
  11. data/lib/netatmo/client.rb +98 -0
  12. data/lib/netatmo/dashboard_data/co2.rb +29 -0
  13. data/lib/netatmo/dashboard_data/health_index.rb +34 -0
  14. data/lib/netatmo/dashboard_data/humidity.rb +29 -0
  15. data/lib/netatmo/dashboard_data/noise.rb +29 -0
  16. data/lib/netatmo/dashboard_data/pressure.rb +43 -0
  17. data/lib/netatmo/dashboard_data/rain.rb +35 -0
  18. data/lib/netatmo/dashboard_data/temperature.rb +35 -0
  19. data/lib/netatmo/dashboard_data/wind.rb +33 -0
  20. data/lib/netatmo/place.rb +21 -0
  21. data/lib/netatmo/user.rb +13 -0
  22. data/lib/netatmo/util/battery_status.rb +9 -0
  23. data/lib/netatmo/util/device_type.rb +14 -0
  24. data/lib/netatmo/util/feel_like.rb +9 -0
  25. data/lib/netatmo/util/health_index.rb +9 -0
  26. data/lib/netatmo/util/pressureunit.rb +9 -0
  27. data/lib/netatmo/util/temp_trend.rb +9 -0
  28. data/lib/netatmo/util/unit.rb +9 -0
  29. data/lib/netatmo/util/wifi_status.rb +9 -0
  30. data/lib/netatmo/util/windunit.rb +9 -0
  31. data/lib/netatmo/version.rb +5 -0
  32. data/lib/netatmo/weather/base_station.rb +61 -0
  33. data/lib/netatmo/weather/battery_device.rb +24 -0
  34. data/lib/netatmo/weather/device.rb +121 -0
  35. data/lib/netatmo/weather/indoor_module.rb +20 -0
  36. data/lib/netatmo/weather/outdoor_module.rb +19 -0
  37. data/lib/netatmo/weather/rain_gauge.rb +15 -0
  38. data/lib/netatmo/weather/station_data.rb +19 -0
  39. data/lib/netatmo/weather/wifi_status.rb +34 -0
  40. data/lib/netatmo/weather/wind_gauge.rb +15 -0
  41. data/lib/netatmo_inflector.rb +24 -0
  42. metadata +224 -0
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Weather
5
+ class BatteryDevice < Device
6
+ attr_accessor :battery_vp
7
+ attr_accessor :battery_percent
8
+ attr_accessor :battery_status
9
+
10
+ def initialize(data)
11
+ super(data)
12
+ self.battery_vp = data['battery_vp']
13
+ self.battery_percent = data['battery_percent']
14
+ if type.indoor_module?
15
+ self.battery_status = BatteryStatus::IndoorBatteryStatus.new(battery_vp)
16
+ elsif type.outdoor_module? || type.rain_gauge?
17
+ self.battery_status = BatteryStatus::OutdoorBatteryStatus.new(battery_vp)
18
+ elsif type.wind_gauge?
19
+ self.battery_status = BatteryStatus::WindGaugeBatteryStatus.new(battery_vp)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Weather
5
+ class Device
6
+ attr_accessor :id
7
+ attr_accessor :type
8
+ attr_accessor :data_types
9
+ attr_accessor :module_name
10
+ attr_accessor :code
11
+ attr_accessor :reachable
12
+ attr_accessor :dashboard_data
13
+ attr_accessor :firmware
14
+ attr_accessor :last_setup
15
+ attr_accessor :last_message
16
+ attr_accessor :last_seen
17
+ attr_accessor :rf_status
18
+
19
+ def self.parse(data)
20
+ type = Netatmo::Util::DeviceType.value(data['type'])
21
+
22
+ if type.base_station?
23
+ Netatmo::Weather::BaseStation.new(data)
24
+ elsif type.outdoor_module?
25
+ Netatmo::Weather::OutdoorModule.new(data)
26
+ elsif type.wind_gauge?
27
+ Netatmo::Weather::WindGauge.new(data)
28
+ elsif type.rain_gauge?
29
+ Netatmo::Weather::RainGauge.new(data)
30
+ elsif type.indoor_module?
31
+ Netatmo::Weather::IndoorModule.new(data)
32
+ elsif type.home_coach?
33
+ Netatmo::AirCare::HealthCoach.new(data)
34
+ else
35
+ Device.new(data)
36
+ end
37
+ end
38
+
39
+ def initialize(data)
40
+ self.id = data['_id']
41
+ self.type = Netatmo::Util::DeviceType.value(data['type'])
42
+ self.code = data['type']
43
+ self.data_types = data['data_type']
44
+ self.module_name = data['module_name']
45
+ self.reachable = data['reachable']
46
+ self.firmware = data['firmware']
47
+ self.last_setup = Time.at(data['last_setup']) if data['last_setup']
48
+ self.last_message = Time.at(data['last_message']) if data['last_message']
49
+ self.last_seen = Time.at(data['last_seen']) if data['last_seen']
50
+ self.rf_status = data['rf_status']
51
+ self.data_types = [] if data_types.nil?
52
+ end
53
+
54
+ def name
55
+ module_name
56
+ end
57
+
58
+ def co2?
59
+ respond_to?(:co2) && data_types.include?('CO2')
60
+ end
61
+
62
+ def humidity?
63
+ respond_to?(:humidity) && data_types.include?('Humidity')
64
+ end
65
+
66
+ def noise?
67
+ respond_to?(:noise) && data_types.include?('Noise')
68
+ end
69
+
70
+ def temperature?
71
+ respond_to?(:temperature) && data_types.include?('Temperature')
72
+ end
73
+
74
+ def pressure?
75
+ respond_to?(:pressure) && data_types.include?('Pressure')
76
+ end
77
+
78
+ def rain?
79
+ respond_to?(:rain) && data_types.include?('Rain')
80
+ end
81
+
82
+ def wind?
83
+ respond_to?(:wind) && data_types.include?('Wind')
84
+ end
85
+
86
+ def health_index?
87
+ respond_to?(:health_index) && data_types.include?('health_idx')
88
+ end
89
+
90
+ def battery?
91
+ respond_to? :battery_status
92
+ end
93
+
94
+ def data
95
+ d = []
96
+ d << co2 if co2?
97
+ d << humidity if humidity?
98
+ d << noise if noise?
99
+ d << temperature if temperature?
100
+ d << pressure if pressure?
101
+ d << wind if wind?
102
+ d << rain if rain?
103
+
104
+ d
105
+ end
106
+
107
+ def values
108
+ h = {}
109
+ h[:co2] = co2 if co2?
110
+ h[:humidity] = humidity if humidity?
111
+ h[:noise] = noise if noise?
112
+ h[:temperature] = temperature if temperature?
113
+ h[:pressure] = pressure if pressure?
114
+ h[:wind] = wind if wind?
115
+ h[:rain] = rain if rain?
116
+
117
+ h
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Weather
5
+ class IndoorModule < BatteryDevice
6
+ attr_accessor :temperature
7
+ attr_accessor :co2
8
+ attr_accessor :humidity
9
+
10
+ # DeviceType: NAModule4
11
+ def initialize(data)
12
+ super(data)
13
+
14
+ self.co2 = DashboardData::CO2.new(data['dashboard_data'])
15
+ self.humidity = DashboardData::Humidity.new(data['dashboard_data'])
16
+ self.temperature = DashboardData::Temperature.new(data['dashboard_data'])
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Weather
5
+ class OutdoorModule < BatteryDevice
6
+ attr_accessor :temperature
7
+ attr_accessor :humidity
8
+ attr_accessor :pressure
9
+
10
+ # DeviceType: NAModule1
11
+ def initialize(data)
12
+ super(data)
13
+ self.humidity = DashboardData::Humidity.new(data['dashboard_data'])
14
+ self.temperature = DashboardData::Temperature.new(data['dashboard_data'])
15
+ self.pressure = DashboardData::Pressure.new(data['dashboard_data']) if pressure?
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Weather
5
+ class RainGauge < BatteryDevice
6
+ attr_accessor :rain
7
+
8
+ # DeviceType: NAModule3
9
+ def initialize(data)
10
+ super(data)
11
+ self.rain = DashboardData::Rain.new(data['dashboard_data'])
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Weather
5
+ class StationData
6
+ attr_accessor :user
7
+ attr_accessor :devices
8
+
9
+ def initialize(response)
10
+ self.devices = []
11
+
12
+ response['devices'].each do |device|
13
+ devices << Device.parse(device)
14
+ end
15
+ self.user = Netatmo::User.new(response['user'])
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ module Netatmo
6
+ module Weather
7
+ class WifiStatus
8
+ extend Forwardable
9
+
10
+ attr_accessor :value
11
+
12
+ def initialize(value)
13
+ self.value = value
14
+ end
15
+
16
+ def to_s
17
+ status.to_s
18
+ end
19
+
20
+ def status
21
+ case value
22
+ when 0..56
23
+ Netatmo::Util::WifiStatus.good
24
+ when 57..71
25
+ Netatmo::Util::WifiStatus.average
26
+ when value > 72
27
+ Netatmo::Util::WifiStatus.bad
28
+ end
29
+ end
30
+
31
+ def_delegators :status, :good?, :average?, :bad?
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Weather
5
+ class WindGauge < BatteryDevice
6
+ attr_accessor :wind
7
+
8
+ # DeviceType: NAModule2
9
+ def initialize(data)
10
+ super(data)
11
+ self.wind = DashboardData::Wind.new(data['dashboard_data'])
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zeitwerk'
4
+
5
+ class NetatmoInflector < Zeitwerk::Inflector
6
+ def camelize(basename, _abspath)
7
+ case basename
8
+ when 'na_main'
9
+ 'NAMain'
10
+ when 'na_module1'
11
+ 'NAModule1'
12
+ when 'na_module2'
13
+ 'NAModule2'
14
+ when 'na_module3'
15
+ 'NAModule3'
16
+ when 'na_module4'
17
+ 'NAModule4'
18
+ when 'co2'
19
+ 'CO2'
20
+ else
21
+ super
22
+ end
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,224 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: netatmo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marco Roth
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: easy_enum
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: geocoder
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: zeitwerk
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '11.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '11.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: dotenv
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '5.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '5.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '13.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '13.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.79'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.79'
153
+ description: Ruby Wrapper for the Netatmo HTTP API
154
+ email:
155
+ - marco.roth@intergga.ch
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - LICENSE.txt
161
+ - README.md
162
+ - lib/netatmo.rb
163
+ - lib/netatmo/administrative.rb
164
+ - lib/netatmo/air_care/home_coach.rb
165
+ - lib/netatmo/battery_status/battery_status.rb
166
+ - lib/netatmo/battery_status/indoor_battery_status.rb
167
+ - lib/netatmo/battery_status/outdoor_battery_status.rb
168
+ - lib/netatmo/battery_status/wind_gauge_battery_status.rb
169
+ - lib/netatmo/client.rb
170
+ - lib/netatmo/dashboard_data/co2.rb
171
+ - lib/netatmo/dashboard_data/health_index.rb
172
+ - lib/netatmo/dashboard_data/humidity.rb
173
+ - lib/netatmo/dashboard_data/noise.rb
174
+ - lib/netatmo/dashboard_data/pressure.rb
175
+ - lib/netatmo/dashboard_data/rain.rb
176
+ - lib/netatmo/dashboard_data/temperature.rb
177
+ - lib/netatmo/dashboard_data/wind.rb
178
+ - lib/netatmo/place.rb
179
+ - lib/netatmo/user.rb
180
+ - lib/netatmo/util/battery_status.rb
181
+ - lib/netatmo/util/device_type.rb
182
+ - lib/netatmo/util/feel_like.rb
183
+ - lib/netatmo/util/health_index.rb
184
+ - lib/netatmo/util/pressureunit.rb
185
+ - lib/netatmo/util/temp_trend.rb
186
+ - lib/netatmo/util/unit.rb
187
+ - lib/netatmo/util/wifi_status.rb
188
+ - lib/netatmo/util/windunit.rb
189
+ - lib/netatmo/version.rb
190
+ - lib/netatmo/weather/base_station.rb
191
+ - lib/netatmo/weather/battery_device.rb
192
+ - lib/netatmo/weather/device.rb
193
+ - lib/netatmo/weather/indoor_module.rb
194
+ - lib/netatmo/weather/outdoor_module.rb
195
+ - lib/netatmo/weather/rain_gauge.rb
196
+ - lib/netatmo/weather/station_data.rb
197
+ - lib/netatmo/weather/wifi_status.rb
198
+ - lib/netatmo/weather/wind_gauge.rb
199
+ - lib/netatmo_inflector.rb
200
+ homepage: https://github.com/marcoroth/netatmo-ruby
201
+ licenses:
202
+ - MIT
203
+ metadata:
204
+ github_repo: https://github.com/marcoroth/netatmo-ruby
205
+ post_install_message:
206
+ rdoc_options: []
207
+ require_paths:
208
+ - lib
209
+ required_ruby_version: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ required_rubygems_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ version: '0'
219
+ requirements: []
220
+ rubygems_version: 3.0.3
221
+ signing_key:
222
+ specification_version: 4
223
+ summary: Netatmo Ruby Client
224
+ test_files: []