alpha_ess 1.1 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -4
  3. data/alpha_ess.gemspec +3 -2
  4. data/lib/alpha_ess.rb +47 -12
  5. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a773748c595dfdcf98ba7926107950335b88449a1b1900176d368fa7be3f14df
4
- data.tar.gz: '049f52e33928d370ebd5245da4a226c298f50fd18ace2c9af519837e02035dba'
3
+ metadata.gz: fed25ff583048344b8da4a15dcd92510abf9d69d5adec2e0da030bf23478ef35
4
+ data.tar.gz: b2cba2ad069290c82b1e4849ac4c1ce588c19abca72a62fcdf4458033e36f365
5
5
  SHA512:
6
- metadata.gz: f8aa05186e306f0372b60c99b20975b13987b6c3bca0a84790e4a7ef5fa2c4d07a6cd20c6dbe4245aaebc97dbf27a3a39367fe15ecddd3482b354abf288a6f6a
7
- data.tar.gz: e1613f50c9228a65edacc729cfa5c16320999916d446ee86681f46a41d0979e5f4ae957409e0fd87fab28279fd217838dad34c6169a6fe0610c47ad0dd1c5d33
6
+ metadata.gz: 86208124094f59312e88bf877c29b946da0fbc0b865a77e3d1948c110d832de8712b3a420d08e499bfc615ab38ab20c41d970825d1194efa01a0c29b22ae6cf5
7
+ data.tar.gz: cf071266cb4443e6f83918a0b936c5f6d269fb20d796578782b064d3d73b13b802ef19a5dad6bdab45edbf2ccea88e83f25488b644c45006abbcf89922d29a09
data/README.md CHANGED
@@ -112,7 +112,6 @@ puts "
112
112
  Batteriebezug / Ladung: #{data["pbat"]}
113
113
  Verbrauch: #{data["pbat"] + data["ppv1"].to_f + netz}
114
114
 
115
-
116
115
  "
117
116
  ```
118
117
 
@@ -120,7 +119,6 @@ Hier die Ausgabe und der Vergleich zur Website:
120
119
 
121
120
  ![picture 1](images/b965404834760626afe73785811995faa1629d2ab66a53f966443fbf22463a67.png)
122
121
 
123
-
124
122
  ## pushover Alarm auslösen, wenn die PV-Anlage einen speziellen Status hat
125
123
 
126
124
  ```ruby
@@ -154,8 +152,14 @@ bat_min = ae.get_custom_use_ess_setting()["bat_use_cap"]
154
152
  puts "Batterie-Minimum neu: #{bat_min}"
155
153
  ```
156
154
 
157
- ## Statischtische Daten des letzten Monats abfragen
155
+ ## Statischtische Daten über einen Zeitraum abfragen
158
156
 
159
- ```
157
+ ```ruby
160
158
  require "alpha_ess"
161
159
  ae = AlphaEss.new
160
+ # aktueller Tag
161
+ ae.get_stics_by_period()
162
+ # letzte 3 Tage, ohne den aktuellen Tag
163
+ ae.get_stics_by_period( (Time.now-86400*3).strftime("%Y-%m-%d"), (Time.now-86400).strftime("%Y-%m-%d"))
164
+ ```
165
+
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.1'
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()
@@ -21,12 +26,13 @@ class AlphaEss
21
26
  end
22
27
 
23
28
  def get_last_power_data()
24
- body = {
25
- "sys_sn" => @serial,
26
- "noLoading" => true
27
- }
28
- url = "https://cloud.alphaess.com/api/ESS/GetLastPowerDataBySN"
29
- res = HTTParty.post(url, headers: header(), body: body.to_json)
29
+ #body = {
30
+ # "sys_sn" => @serial,
31
+ # "noLoading" => true
32
+ #}
33
+ url = "https://cloud.alphaess.com/api/ESS/GetLastPowerDataBySN?sys_sn=#{@serial}&noLoading=true"
34
+ #res = HTTParty.post(url, headers: header(), body: body.to_json)
35
+ res = HTTParty.get(url, headers: header())
30
36
  res.parsed_response["data"]
31
37
  end
32
38
 
@@ -71,7 +77,7 @@ class AlphaEss
71
77
  }, body: body.to_json)
72
78
  end
73
79
 
74
- private
80
+ private
75
81
 
76
82
  def get_token()
77
83
  Dir.mkdir "#{ENV["HOME"]}/.alpha_ess" if ! (Dir.exists?"#{ENV["HOME"]}/.alpha_ess")
@@ -97,24 +103,53 @@ class AlphaEss
97
103
  "username" => @username,
98
104
  "password" => @password
99
105
  }
100
- res = HTTParty.post(url, headers: {
106
+ header = {
101
107
  "Accept" => "application/json",
102
108
  "Content-Type" => "application/json;charset=UTF-8"
103
- }, body: body.to_json)
109
+ }.update(secure_header_addon())
110
+ res = HTTParty.post(url, headers: header, body: body.to_json)
104
111
  @token = res.parsed_response["data"]["AccessToken"]
105
112
  @token_valid_to = Time.now.to_i+36000
106
113
  save_token()
107
114
  end
108
115
 
116
+ def secure_header_addon()
117
+ # thanks to https://github.com/CharlesGillanders
118
+ t = Time.now.to_i
119
+ {
120
+ "authtimestamp" => t.to_s,
121
+ "authsignature" => "#{AUTHPREFIX}#{Digest::SHA2.new(512).hexdigest("#{AUTHCONSTANT}#{t}")}#{AUTHSUFFIX}"
122
+ }
123
+ end
124
+
109
125
  def header(hash={})
110
126
  get_token()
111
- hash = {
127
+ {
112
128
  "Accept" => "application/json",
113
129
  "Content-Type" => "application/json;charset=UTF-8",
114
130
  "Authorization" => "Bearer #{@token}"
115
- }.update hash
116
- hash
131
+ }.update(hash).update(secure_header_addon())
117
132
  end
118
133
  end
119
134
 
135
+ # some extensions for easier visualise data in irb
136
+
137
+ module Jsonpretty
138
+ def jp
139
+ # return in json_pretty
140
+ JSON.pretty_generate(self)
141
+ end
142
+ def jpp
143
+ # print in json_pretty
144
+ puts JSON.pretty_generate(self)
145
+ end
146
+ end
147
+
148
+ class Hash
149
+ include Jsonpretty
150
+ end
151
+
152
+ class Array
153
+ include Jsonpretty
154
+ end
120
155
 
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.1
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: []