senec 0.20.0 → 0.21.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.
Binary file
@@ -55,19 +55,23 @@ module Senec
55
55
  end
56
56
 
57
57
  def systems
58
- fetch_payload "#{SYSTEMS_HOST}/v1/systems"
58
+ get "#{SYSTEMS_HOST}/v1/systems"
59
59
  end
60
60
 
61
61
  def system_details(system_id)
62
- fetch_payload "#{SYSTEMS_HOST}/systems/#{system_id}/details"
62
+ get "#{SYSTEMS_HOST}/systems/#{system_id}/details"
63
63
  end
64
64
 
65
65
  def dashboard(system_id)
66
- fetch_payload "#{MEASUREMENTS_HOST}/v1/systems/#{system_id}/dashboard"
66
+ get "#{MEASUREMENTS_HOST}/v1/systems/#{system_id}/dashboard"
67
67
  end
68
68
 
69
69
  def wallbox(system_id, wallbox_id)
70
- fetch_payload "#{WALLBOX_HOST}/v1/systems/#{system_id}/wallboxes/#{wallbox_id}"
70
+ get "#{WALLBOX_HOST}/v1/systems/#{system_id}/wallboxes/#{wallbox_id}"
71
+ end
72
+
73
+ def wallbox_search(system_id)
74
+ post "#{WALLBOX_HOST}/v1/systems/wallboxes/search", { systemIds: [system_id] }
71
75
  end
72
76
 
73
77
  private
@@ -125,7 +129,7 @@ module Senec
125
129
  # :nocov:
126
130
  end
127
131
 
128
- def fetch_payload(url, default = nil)
132
+ def get(url, default: nil)
129
133
  return default unless ensure_token_valid
130
134
 
131
135
  response = oauth_token.get(url)
@@ -139,6 +143,24 @@ module Senec
139
143
  # :nocov:
140
144
  end
141
145
 
146
+ def post(url, data, default: nil)
147
+ return default unless ensure_token_valid
148
+
149
+ response = oauth_token.post(
150
+ url,
151
+ body: data.to_json,
152
+ headers: { 'Content-Type' => 'application/json' },
153
+ )
154
+ return default unless response.status == 200
155
+
156
+ JSON.parse(response.body)
157
+ rescue StandardError => e
158
+ # :nocov:
159
+ warn "API error: #{e.message}"
160
+ default
161
+ # :nocov:
162
+ end
163
+
142
164
  def http_request(method, url, data: nil)
143
165
  Faraday
144
166
  .new
data/lib/senec/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Senec
2
- VERSION = '0.20.0'.freeze
2
+ VERSION = '0.21.0'.freeze
3
3
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: senec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georg Ledermann
@@ -126,6 +126,7 @@ files:
126
126
  - coverage/index.html
127
127
  - lib/.DS_Store
128
128
  - lib/senec.rb
129
+ - lib/senec/.DS_Store
129
130
  - lib/senec/cloud/connection.rb
130
131
  - lib/senec/cloud/error.rb
131
132
  - lib/senec/local/connection.rb
@@ -148,6 +149,7 @@ files:
148
149
  - pkg/senec-0.18.0.gem
149
150
  - pkg/senec-0.19.0.gem
150
151
  - pkg/senec-0.2.0.gem
152
+ - pkg/senec-0.20.0.gem
151
153
  - pkg/senec-0.3.0.gem
152
154
  - pkg/senec-0.4.0.gem
153
155
  - pkg/senec-0.5.0.gem