weatherlink 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WeatherLink
4
+ class SensorRecord < HashWrapper
5
+ attr_reader :client
6
+
7
+ def initialize(client, data)
8
+ @client = client
9
+ super(data)
10
+ end
11
+
12
+ def to_s
13
+ "#<#{self.class.name} time='#{time}' (#{data.size} values)>"
14
+ end
15
+
16
+ def inspect
17
+ to_s
18
+ end
19
+
20
+ def time
21
+ Time.at(ts)
22
+ end
23
+
24
+ private
25
+
26
+ def method_missing(symbol, *args)
27
+ return Time.at(data[symbol.to_s]) if symbol == :ts || symbol.to_s.end_with?('_at')
28
+ return client.convert(symbol, super) if data.include?(symbol.to_s)
29
+
30
+ super
31
+ end
32
+
33
+ def respond_to_missing?(symbol, include_private = false)
34
+ return true if symbol == :ts || symbol.to_s.end_with?('_at')
35
+
36
+ super
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WeatherLink
4
+ class Station < HashWrapper
5
+ LocalSensor = Struct.new(:device, :host, keyword_init: true) do
6
+ def client
7
+ @client ||= LocalClient.new(host: host)
8
+ end
9
+
10
+ def current_conditions
11
+ client.current_conditions
12
+ end
13
+ end
14
+
15
+ attr_reader :client
16
+
17
+ def initialize(client, data)
18
+ @client = client
19
+ super(data)
20
+ end
21
+
22
+ def to_s
23
+ "#<#{self.class.name} station_id=#{station_id} gateway_id_hex=#{gateway_id_hex} (#{station_name})>"
24
+ end
25
+
26
+ def inspect
27
+ to_s
28
+ end
29
+
30
+ def sensors
31
+ @sensors ||= client.sensors.select { |sensor| sensor.station_id == station_id }
32
+ end
33
+
34
+ def sensor(lsid)
35
+ sensors.select { |sensor| sensor.lsid == lsid }.first
36
+ end
37
+
38
+ def current
39
+ sensors = client.api.current(station_id)['sensors'].map do |sensor|
40
+ SensorData.new(client, sensor)
41
+ end
42
+
43
+ SensorDataCollection.new(client, sensors)
44
+ end
45
+
46
+ def last_seconds(seconds)
47
+ sensors = client.api.last_seconds(station_id, seconds)['sensors'].map do |sensor|
48
+ SensorData.new(client, sensor)
49
+ end
50
+
51
+ SensorDataCollection.new(client, sensors)
52
+ end
53
+
54
+ def last_hour
55
+ last_seconds(3600)
56
+ end
57
+
58
+ def last_day
59
+ last_seconds(86_400)
60
+ end
61
+
62
+ def local_sensors
63
+ @local_sensors ||= current.health.select { |s| s.include?('ip_v4_address') }.map do |health|
64
+ sensor = client.sensor_by_lsid(health.lsid)
65
+ device_id_hex = sensor.parent_device_id_hex
66
+ device = client.node_by_device_id_hex(device_id_hex) || client.stations_by_device_id_hex(device_id_hex)
67
+ LocalSensor.new(device: device, host: health.fetch('ip_v4_address'))
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WeatherLink
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/weatherlink/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'weatherlink'
7
+ spec.version = WeatherLink::VERSION
8
+ spec.authors = ['Jeremy Cole']
9
+ spec.email = ['jeremy@jcole.us']
10
+
11
+ spec.summary = 'Unofficial Davis Instruments WeatherLink/AirLink API in Ruby'
12
+ spec.description = %{
13
+ This is an unofficial implementation of the Davis Instruments WeatherLink API, including both
14
+ the Local API (v1) and the web API (v2).
15
+ }
16
+ spec.homepage = 'http://github.com/jeremycole/weatherlink'
17
+ spec.license = 'MIT'
18
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = spec.homepage
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_dependency('ruby-units', '~> 2.3')
34
+
35
+ spec.add_development_dependency('rake', '~> 12.0')
36
+ spec.add_development_dependency('rspec', '~> 3.0')
37
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weatherlink
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Cole
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-units
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: "\n This is an unofficial implementation of the Davis Instruments
56
+ WeatherLink API, including both\n the Local API (v1) and the web API (v2).\n
57
+ \ "
58
+ email:
59
+ - jeremy@jcole.us
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".rubocop.yml"
67
+ - ".travis.yml"
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - bin/console
74
+ - bin/setup
75
+ - lib/weatherlink.rb
76
+ - lib/weatherlink/api_v2.rb
77
+ - lib/weatherlink/client.rb
78
+ - lib/weatherlink/data_record.rb
79
+ - lib/weatherlink/hash_wrapper.rb
80
+ - lib/weatherlink/local_api_v1.rb
81
+ - lib/weatherlink/local_client.rb
82
+ - lib/weatherlink/node.rb
83
+ - lib/weatherlink/sensor.rb
84
+ - lib/weatherlink/sensor_data.rb
85
+ - lib/weatherlink/sensor_data_collection.rb
86
+ - lib/weatherlink/sensor_record.rb
87
+ - lib/weatherlink/station.rb
88
+ - lib/weatherlink/version.rb
89
+ - weatherlink.gemspec
90
+ homepage: http://github.com/jeremycole/weatherlink
91
+ licenses:
92
+ - MIT
93
+ metadata:
94
+ homepage_uri: http://github.com/jeremycole/weatherlink
95
+ source_code_uri: http://github.com/jeremycole/weatherlink
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 2.6.0
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubygems_version: 3.0.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Unofficial Davis Instruments WeatherLink/AirLink API in Ruby
115
+ test_files: []