alpha_ess 1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a773748c595dfdcf98ba7926107950335b88449a1b1900176d368fa7be3f14df
4
- data.tar.gz: '049f52e33928d370ebd5245da4a226c298f50fd18ace2c9af519837e02035dba'
3
+ metadata.gz: 3403efae3e758f4f8ef2593edc6bdf9d268a34367ff99ab93a78cc80d007828f
4
+ data.tar.gz: 54233da976a52b1dd3c6a46cdcec89932398f9272eeedc54fc384714d27d3afc
5
5
  SHA512:
6
- metadata.gz: f8aa05186e306f0372b60c99b20975b13987b6c3bca0a84790e4a7ef5fa2c4d07a6cd20c6dbe4245aaebc97dbf27a3a39367fe15ecddd3482b354abf288a6f6a
7
- data.tar.gz: e1613f50c9228a65edacc729cfa5c16320999916d446ee86681f46a41d0979e5f4ae957409e0fd87fab28279fd217838dad34c6169a6fe0610c47ad0dd1c5d33
6
+ metadata.gz: 0d985dbad128c6b41adf906cf41d0dfe8ffcbf2fbf9ece3bfa83d20cca55bc4a8168d47daf8db80607bf52c750d2b14450dabc0a2a0a3c3248fa94001b96f0f3
7
+ data.tar.gz: 92e0ae0059e060ac6ccb7a6546df84b57b246188b82192768a713c5d81a0a62639f49902f21be0a62a6b26aedb3ed533219c4cb7dd30b0a049a772b3b23fe9f3
data/README.md CHANGED
@@ -120,7 +120,6 @@ Hier die Ausgabe und der Vergleich zur Website:
120
120
 
121
121
  ![picture 1](images/b965404834760626afe73785811995faa1629d2ab66a53f966443fbf22463a67.png)
122
122
 
123
-
124
123
  ## pushover Alarm auslösen, wenn die PV-Anlage einen speziellen Status hat
125
124
 
126
125
  ```ruby
@@ -154,8 +153,14 @@ bat_min = ae.get_custom_use_ess_setting()["bat_use_cap"]
154
153
  puts "Batterie-Minimum neu: #{bat_min}"
155
154
  ```
156
155
 
157
- ## Statischtische Daten des letzten Monats abfragen
156
+ ## Statischtische Daten über einen Zeitraum abfragen
158
157
 
159
- ```
158
+ ```ruby
160
159
  require "alpha_ess"
161
160
  ae = AlphaEss.new
161
+ # aktueller Tag
162
+ ae.get_stics_by_period()
163
+ # letzte 3 Tage, ohne den aktuellen Tag
164
+ ae.get_stics_by_period( (Time.now-86400*3).strftime("%Y-%m-%d"), (Time.now-86400).strftime("%Y-%m-%d"))
165
+ ```
166
+
data/alpha_ess-1.1.gem ADDED
Binary file
data/alpha_ess.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'alpha_ess'
3
- spec.version = '1.1'
4
- spec.date = '2022-10-02'
3
+ spec.version = '1.2'
4
+ spec.date = '2022-10-31'
5
5
  spec.summary = "Alpha Ess API Calls"
6
6
  spec.description = "a Ruby class for Alpha-Ess-API-Calls"
7
7
  spec.authors = ["Oliver Gaida"]
@@ -10,6 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.homepage = 'https://github.com/ogaida/alpha_ess'
11
11
  #spec.executables = %w(rusdc)
12
12
  spec.add_runtime_dependency 'httparty'
13
+ spec.add_runtime_dependency 'digest'
13
14
  #spec.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0'
14
15
  spec.license = 'MIT'
15
16
  end
data/lib/alpha_ess.rb CHANGED
@@ -1,7 +1,12 @@
1
1
  require "httparty"
2
+ require "digest"
2
3
 
3
4
  class AlphaEss
4
5
 
6
+ AUTHPREFIX = "al8e4s"
7
+ AUTHCONSTANT = "LS885ZYDA95JVFQKUIUUUV7PQNODZRDZIS4ERREDS0EED8BCWSS"
8
+ AUTHSUFFIX = "ui893ed"
9
+
5
10
  def initialize(sn = ENV["ess_serial"], u = ENV["ess_username"], p = ENV["ess_password"])
6
11
  @serial, @username, @password = sn, u, p
7
12
  get_token()
@@ -71,7 +76,7 @@ class AlphaEss
71
76
  }, body: body.to_json)
72
77
  end
73
78
 
74
- private
79
+ private
75
80
 
76
81
  def get_token()
77
82
  Dir.mkdir "#{ENV["HOME"]}/.alpha_ess" if ! (Dir.exists?"#{ENV["HOME"]}/.alpha_ess")
@@ -100,21 +105,49 @@ class AlphaEss
100
105
  res = HTTParty.post(url, headers: {
101
106
  "Accept" => "application/json",
102
107
  "Content-Type" => "application/json;charset=UTF-8"
103
- }, body: body.to_json)
108
+ }.update(secure_header_addon()), body: body.to_json)
104
109
  @token = res.parsed_response["data"]["AccessToken"]
105
110
  @token_valid_to = Time.now.to_i+36000
106
111
  save_token()
107
112
  end
108
113
 
114
+ def secure_header_addon()
115
+ # thanks to https://github.com/CharlesGillanders
116
+ t = Time.now.to_i
117
+ {
118
+ "authtimestamp" => t,
119
+ "authsignature" => "#{AUTHPREFIX}#{Digest::SHA2.new(512).hexdigest("#{AUTHCONSTANT}#{t}")}#{AUTHSUFFIX}"
120
+ }
121
+ end
122
+
109
123
  def header(hash={})
110
124
  get_token()
111
- hash = {
125
+ {
112
126
  "Accept" => "application/json",
113
127
  "Content-Type" => "application/json;charset=UTF-8",
114
128
  "Authorization" => "Bearer #{@token}"
115
- }.update hash
116
- hash
129
+ }.update(hash).update(secure_header_addon())
130
+ end
131
+ end
132
+
133
+ # some extensions for easier visualise data in irb
134
+
135
+ module Jsonpretty
136
+ def jp
137
+ # return in json_pretty
138
+ JSON.pretty_generate(self)
117
139
  end
140
+ def jpp
141
+ # print in json_pretty
142
+ puts JSON.pretty_generate(self)
143
+ end
144
+ end
145
+
146
+ class Hash
147
+ include Jsonpretty
118
148
  end
119
149
 
150
+ class Array
151
+ include Jsonpretty
152
+ end
120
153
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alpha_ess
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Gaida
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-02 00:00:00.000000000 Z
11
+ date: 2022-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: digest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: a Ruby class for Alpha-Ess-API-Calls
28
42
  email: ogaida@t-online.de
29
43
  executables: []
@@ -32,6 +46,7 @@ extra_rdoc_files: []
32
46
  files:
33
47
  - LICENSE.md
34
48
  - README.md
49
+ - alpha_ess-1.1.gem
35
50
  - alpha_ess.gemspec
36
51
  - images/b965404834760626afe73785811995faa1629d2ab66a53f966443fbf22463a67.png
37
52
  - lib/alpha_ess.rb