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,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module DashboardData
5
+ class CO2
6
+ attr_accessor :time
7
+ attr_accessor :value
8
+ attr_accessor :unit
9
+
10
+ def initialize(data)
11
+ self.time = Time.at(data['time_utc'])
12
+ self.value = data['CO2'].to_f
13
+ self.unit = 'ppm'
14
+ end
15
+
16
+ def to_s
17
+ "#{value} #{unit}"
18
+ end
19
+
20
+ def co2
21
+ value
22
+ end
23
+
24
+ def status
25
+ # TODO: calculate status
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ module Netatmo
6
+ module DashboardData
7
+ class HealthIndex
8
+ extend Forwardable
9
+
10
+ attr_accessor :time
11
+ attr_accessor :value
12
+ attr_accessor :unit
13
+
14
+ def initialize(data)
15
+ self.time = Time.at(data['time_utc'])
16
+ self.value = data['health_idx'].to_i
17
+ end
18
+
19
+ def status
20
+ Netatmo::Util::HealthIndex.value(value)
21
+ end
22
+
23
+ def_delegators :status, :healthy?, :fine?, :fair?, :poor?, :unhealthy?
24
+
25
+ def health_idx
26
+ value
27
+ end
28
+
29
+ def health_index
30
+ value
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module DashboardData
5
+ class Humidity
6
+ attr_accessor :time
7
+ attr_accessor :value
8
+ attr_accessor :unit
9
+
10
+ def initialize(data)
11
+ self.time = Time.at(data['time_utc'])
12
+ self.value = data['Humidity'].to_f
13
+ self.unit = '%'
14
+ end
15
+
16
+ def to_s
17
+ "#{value}#{unit}"
18
+ end
19
+
20
+ def humidity
21
+ value
22
+ end
23
+
24
+ def status
25
+ # TODO: calculate status (green/yellow/red)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module DashboardData
5
+ class Noise
6
+ attr_accessor :time
7
+ attr_accessor :value
8
+ attr_accessor :unit
9
+
10
+ def initialize(data)
11
+ self.time = Time.at(data['time_utc'])
12
+ self.value = data['Noise'].to_f
13
+ self.unit = 'dB'
14
+ end
15
+
16
+ def to_s
17
+ "#{value} #{unit}"
18
+ end
19
+
20
+ def noise
21
+ value
22
+ end
23
+
24
+ def status
25
+ # TODO: calculate status (quiet/load/...)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ module Netatmo
6
+ module DashboardData
7
+ class Pressure
8
+ extend Forwardable
9
+
10
+ attr_accessor :time
11
+ attr_accessor :value
12
+ attr_accessor :absolute_pressure
13
+ attr_accessor :trend
14
+ attr_accessor :unit
15
+
16
+ def initialize(data)
17
+ self.time = Time.at(data['time_utc'])
18
+ self.value = data['Pressure'].to_f
19
+ self.absolute_pressure = data['AbsolutePressure'].to_f
20
+ self.trend = Netatmo::Util::TempTrend.key(data['pressure_trend'].to_sym)
21
+ self.unit = 'mbar'
22
+ end
23
+
24
+ def to_s
25
+ "#{value} #{unit}"
26
+ end
27
+
28
+ def_delegators :trend, :stable?, :down?, :up?
29
+
30
+ def pressure
31
+ value
32
+ end
33
+
34
+ def abs
35
+ absolute_pressure
36
+ end
37
+
38
+ def absolute
39
+ absolute_pressure
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module DashboardData
5
+ class Rain
6
+ attr_accessor :time
7
+ attr_accessor :value
8
+ attr_accessor :sum_rain_1
9
+ attr_accessor :sum_rain_24
10
+
11
+ def initialize(data)
12
+ self.time = Time.at(data['time_utc'])
13
+ self.value = data['Rain'].to_f
14
+ self.sum_rain_1 = data['sum_rain_1'].to_f
15
+ self.sum_rain_24 = data['sum_rain_24'].to_f
16
+ end
17
+
18
+ def to_s
19
+ value
20
+ end
21
+
22
+ def rain
23
+ value
24
+ end
25
+
26
+ def last_hour
27
+ sum_rain_1
28
+ end
29
+
30
+ def last_day
31
+ sum_rain_24
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module DashboardData
5
+ class Temperature
6
+ attr_accessor :time
7
+ attr_accessor :value
8
+ attr_accessor :min
9
+ attr_accessor :max
10
+ attr_accessor :min_date
11
+ attr_accessor :max_date
12
+ attr_accessor :trend
13
+ attr_accessor :unit
14
+
15
+ def initialize(data)
16
+ self.time = Time.at(data['time_utc'])
17
+ self.value = data['Temperature'].to_f
18
+ self.min = data['min_temp'].to_f
19
+ self.max = data['max_temp'].to_f
20
+ self.min_date = Time.at(data['date_min_temp'])
21
+ self.max_date = Time.at(data['date_max_temp'])
22
+ self.trend = Netatmo::Util::TempTrend.key(data['temp_trend'].to_sym)
23
+ self.unit = '°C'
24
+ end
25
+
26
+ def to_s
27
+ "#{value} #{unit}"
28
+ end
29
+
30
+ def temperature
31
+ value
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module DashboardData
5
+ class Wind
6
+ attr_accessor :time
7
+ attr_accessor :wind_strength
8
+ attr_accessor :max_wind_strength
9
+ attr_accessor :max_wind_strength_date
10
+ attr_accessor :wind_angle
11
+ attr_accessor :gust_strength
12
+ attr_accessor :gust_angle
13
+ attr_accessor :wind_historic
14
+ attr_accessor :unit
15
+
16
+ def initialize(data)
17
+ self.time = Time.at(data['time_utc'])
18
+ self.wind_strength = data['WindStrength'].to_f
19
+ self.max_wind_strength = data['max_wind_str'].to_f
20
+ self.max_wind_strength_date = Time.at(data['date_max_wind_str'])
21
+ self.wind_angle = data['WindAngle'].to_f
22
+ self.gust_strength = data['Guststrength'].to_f
23
+ self.gust_angle = data['GustAngle'].to_f
24
+ self.wind_historic = data['WindHistoric']
25
+ self.unit = 'km/h'
26
+ end
27
+
28
+ def to_s
29
+ "#{wind_strength} #{unit}"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'geocoder'
4
+
5
+ module Netatmo
6
+ class Place
7
+ attr_accessor :altitude
8
+ attr_accessor :city
9
+ attr_accessor :country
10
+ attr_accessor :location
11
+ attr_accessor :timezone
12
+
13
+ def initialize(data)
14
+ self.altitude = data['altitude']
15
+ self.city = data['city']
16
+ self.country = data['country']
17
+ self.timezone = data['timezone']
18
+ self.location = ::Geocoder.search(data['location'].reverse)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ class User
5
+ attr_accessor :mail
6
+ attr_accessor :administrative
7
+
8
+ def initialize(data)
9
+ self.mail = data['mail']
10
+ self.administrative = Netatmo::Administrative.new(data['administrative'])
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Util
5
+ class BatteryStatus < EasyEnum::EasyEnum
6
+ easy_enum max: 0, full: 1, high: 2, medium: 3, low: 4, very_low: 5
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Util
5
+ class DeviceType < EasyEnum::EasyEnum
6
+ easy_enum base_station: 'NAMain',
7
+ outdoor_module: 'NAModule1',
8
+ wind_gauge: 'NAModule2',
9
+ rain_gauge: 'NAModule3',
10
+ indoor_module: 'NAModule4',
11
+ health_coach: 'NHC'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Util
5
+ class FeelLike < EasyEnum::EasyEnum
6
+ easy_enum hum_index: 0, heat_index: 1
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Util
5
+ class HealthIndex < EasyEnum::EasyEnum
6
+ easy_enum healthy: 0, fine: 1, fair: 2, poor: 3, unhealthy: 4
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Util
5
+ class Pressureunit < EasyEnum::EasyEnum
6
+ easy_enum mbar: 0, inHg: 1, mmHg: 2
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Util
5
+ class TempTrend < EasyEnum::EasyEnum
6
+ easy_enum stable: 0, down: -1, up: 1
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Util
5
+ class Unit < EasyEnum::EasyEnum
6
+ easy_enum metric: 0, imperial: 1
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Util
5
+ class WifiStatus < EasyEnum::EasyEnum
6
+ easy_enum bad: 0, average: 1, good: 2
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Util
5
+ class Windunit < EasyEnum::EasyEnum
6
+ easy_enum kph: 0, mph: 1, ms: 2, beaufort: 3, knot: 4
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Netatmo
4
+ module Weather
5
+ class BaseStation < Device
6
+ attr_accessor :cipher_id
7
+ attr_accessor :date_setup
8
+ attr_accessor :last_status_store
9
+ attr_accessor :last_upgrade
10
+ attr_accessor :co2_calibrating
11
+ attr_accessor :station_name
12
+ attr_accessor :friend_users
13
+ attr_accessor :read_only
14
+
15
+ attr_accessor :temperature
16
+ attr_accessor :co2
17
+ attr_accessor :humidity
18
+ attr_accessor :noise
19
+ attr_accessor :pressure
20
+
21
+ attr_accessor :wifi_status
22
+ attr_accessor :place
23
+
24
+ attr_accessor :modules
25
+
26
+ # DeviceType: NAMain
27
+ def initialize(data)
28
+ super(data)
29
+
30
+ self.cipher_id = data['cipher_id']
31
+ self.date_setup = Time.at(data['date_setup']) if data['date_setup']
32
+ self.last_status_store = Time.at(data['last_status_store']) if data['last_status_store']
33
+ self.last_upgrade = Time.at(data['last_upgrade']) if data['last_upgrade']
34
+ self.co2_calibrating = data['co2_calibrating']
35
+ self.station_name = data['station_name']
36
+ self.friend_users = data['friend_users']
37
+ self.read_only = data['read_only']
38
+
39
+ self.modules = []
40
+
41
+ data['modules']&.each do |module_data|
42
+ modules << Device.parse(module_data)
43
+ end
44
+
45
+ if data['dashboard_data']
46
+ self.co2 = DashboardData::CO2.new(data['dashboard_data'])
47
+ self.humidity = DashboardData::Humidity.new(data['dashboard_data'])
48
+ self.temperature = DashboardData::Temperature.new(data['dashboard_data'])
49
+ self.noise = DashboardData::Temperature.new(data['dashboard_data'])
50
+ self.pressure = DashboardData::Pressure.new(data['dashboard_data']) if pressure?
51
+ end
52
+ self.wifi_status = WifiStatus.new(data['wifi_status'])
53
+ self.place = Netatmo::Place.new(data['place'])
54
+ end
55
+
56
+ def name
57
+ station_name
58
+ end
59
+ end
60
+ end
61
+ end