pvoutput 0.1.0 → 0.5.0

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
- SHA1:
3
- metadata.gz: addc07d68f5896b569e08c0fff56515de4989add
4
- data.tar.gz: 1b857c2cb71269917d2b6636a32c2cfb19e02e16
2
+ SHA256:
3
+ metadata.gz: 5bae86d84185da437949075808498e10411e593feef84554670f6910b1136dd9
4
+ data.tar.gz: 0e8bdf41526686570b06714902f18ab63ab8f809a5d41c081f8e5299b1f380d5
5
5
  SHA512:
6
- metadata.gz: 369b0064aeacf2f2ed869298d33d1460177d3a76e130562d3ff069a87115d49782a62fce7d62952f591b2983508651deaf3b3f4ee81cc37eddec0d41de3a3d8c
7
- data.tar.gz: 246ad5582773fd4cc6b691b6ce9bbda18c1ec06d4fcd739733aabd4139d6cb30c8843128ce24e7dc45a326201d2bce5f520b7632e4bd3e150128ea3f528f026c
6
+ metadata.gz: 4a479f681ca96f0c22c5627f8c19d65ea285aa0ff6407af03a1e03cad6407e6ec3a00e5487b9068b41b065f4157fe49f86776cb2b26aa2eb55afc9db90091baa
7
+ data.tar.gz: 809acd85b1f998651ee3f669130a88d7e4b09c4245aa7bdf88006a6dc5e2f257c6791c0a1dc9935fc50ce7e65e9f0645323945da1dd73f588b8d8da4e2e44d4b
data/.gitignore CHANGED
@@ -4,3 +4,4 @@
4
4
  /pkg/
5
5
  /spec/reports/
6
6
  /tmp/
7
+ /vendor/bundle
@@ -9,12 +9,18 @@ Style/Documentation:
9
9
  Style/Lambda:
10
10
  Enabled: false
11
11
 
12
- Style/TrailingComma:
12
+ Style/TrailingCommaInLiteral:
13
13
  EnforcedStyleForMultiline: comma
14
14
 
15
+ Metrics/MethodLength:
16
+ Max: 20
17
+
15
18
  Metrics/LineLength:
16
19
  Max: 120
17
20
 
21
+ RSpec/ExampleLength:
22
+ Max: 15
23
+
18
24
  Style/ModuleFunction:
19
25
  Enabled: false
20
26
 
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ # 0.5.0 (2020-09-20)
4
+
5
+ * Add more detail to error messages (@jwillemsen)
6
+ * Support debugging (@johnf)
7
+
8
+ # 0.4.0 (20160911)
9
+
10
+ * Add retries to batch_output (@jwillemsen)
11
+
12
+ # 0.3.0 (20160229)
13
+
14
+ * Add donation mode (@jwillemsen)
15
+ * Add batch_output support (@jwillemsen)
16
+
17
+ # 0.2.0 (20160227)
18
+
19
+ * Fix typo in temperature (@jwillemsen)
20
+ * Add usage documentation (@jwillemsen)
21
+ * Add the add_ouput method for end of day reporting (@jwillemsen)
22
+ * Use latest bundler in CircleCI (@johnf)
23
+
24
+ # 0.1.1 (20151122)
25
+
26
+ * Convert the system id to a string (@johnf)
27
+
28
+ # 0.1.0 (20151122)
29
+
30
+ * Initial Release (@johnf)
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Circle CI](https://circleci.com/gh/johnf/pvoutput.svg?style=svg)](https://circleci.com/gh/johnf/pvoutput)
4
4
  [![Coverage Status](https://coveralls.io/repos/johnf/pvoutput/badge.svg?branch=master&service=github)](https://coveralls.io/github/johnf/pvoutput?branch=master)
5
+ [![Gem Version](https://badge.fury.io/rb/pvoutput.svg)](http://badge.fury.io/rb/pvoutput)
6
+
5
7
 
6
8
  Ruby library for talking to the PVOutput API.
7
9
 
@@ -23,7 +25,133 @@ Or install it yourself as:
23
25
 
24
26
  ## Usage
25
27
 
26
- TODO
28
+ In order to use pvoutput in your application you need to use
29
+
30
+ ```ruby
31
+ require 'pvoutput/client'
32
+ ```
33
+
34
+ First step is to create a PVOutput client using your PVOutput assigned system_id and api_key
35
+
36
+ ```ruby
37
+ pvoutput = PVOutput::Client.new(system_id, api_key)
38
+ ```
39
+
40
+ At the moment you [donate](http://pvoutput.org/donate.jsp) to PVOutput you can enable the donation mode by creating a PVOutput client using
41
+
42
+ ```ruby
43
+ pvoutput = PVOutput::Client.new(system_id, api_key, true)
44
+ ```
45
+
46
+ Now you can report your real time status to PVOutput using
47
+
48
+ ```ruby
49
+ pvoutput.add_status(
50
+ options
51
+ )
52
+ ```
53
+
54
+ The add_status operation accepts the following options
55
+
56
+ | Option | PVOutput Parameter |
57
+ | ---------------- | ------------------ |
58
+ | energy_generated | v1 |
59
+ | power_generated | v2 |
60
+ | energy_consumed | v3 |
61
+ | power_consumed | v4 |
62
+ | temperature | v5 |
63
+ | voltage | v6 |
64
+ | cumulative | c1 |
65
+ | net | n |
66
+
67
+ As example
68
+
69
+ ```ruby
70
+ client.add_status(
71
+ :energy_generated => 100,
72
+ :power_generated => 50,
73
+ :temperature => 30,
74
+ :voltage => 200,
75
+ )
76
+ ```
77
+
78
+ You can report your daily output to PVOutput using
79
+
80
+ ```ruby
81
+ pvoutput.add_output(
82
+ options
83
+ )
84
+ ```
85
+
86
+ The add_output operation accepts the following options
87
+
88
+ | Option | PVOutput Parameter |
89
+ | --------------------- | ------------------ |
90
+ | output_date | d |
91
+ | energy_generated | g |
92
+ | peak_power | pp |
93
+ | peak_time | pt |
94
+ | condition | cd |
95
+ | min_temp | tm |
96
+ | max_temp | tx |
97
+ | comments | cm |
98
+ | import_peak | ip |
99
+ | import_off_peak | io |
100
+ | import_shoulder | is |
101
+ | import_high_shoulder | ih |
102
+ | consumption | c |
103
+
104
+ As example
105
+
106
+ ```ruby
107
+ client.add_output(
108
+ :output_date => '20160228'
109
+ :energy_generated => 15000,
110
+ :max_temp => 30
111
+ )
112
+ ```
113
+
114
+ You can report also a batch of daily output values to PVOutput using
115
+
116
+ ```ruby
117
+ pvoutput.add_batch_output(
118
+ options
119
+ )
120
+ ```
121
+
122
+ The add_batch_output operation accepts a hash with the date as key and within that the following options
123
+
124
+ | Option | PVOutput Parameter |
125
+ | --------------------- | ------------------ |
126
+ | energy_generated | g |
127
+ | peak_power | pp |
128
+ | peak_time | pt |
129
+ | condition | cd |
130
+ | min_temp | tm |
131
+ | max_temp | tx |
132
+ | comments | cm |
133
+ | import_peak | ip |
134
+ | import_off_peak | io |
135
+ | import_shoulder | is |
136
+ | import_high_shoulder | ih |
137
+ | consumption | c |
138
+
139
+ As example
140
+
141
+ ```ruby
142
+ client.add_output(
143
+ :'20150101' => {
144
+ :energy_generated => 1239, },
145
+ :'20150102' => {
146
+ :energy_generated => 1523 },
147
+ :'20150103' => {
148
+ :energy_generated => 2190 },
149
+ )
150
+ ```
151
+
152
+ ## Debugging
153
+
154
+ You can able HTTParty debugging to see the requests by setting `PVOUTPUT_DEBUG=true`
27
155
 
28
156
  ## Development
29
157
 
@@ -33,7 +161,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
33
161
 
34
162
  ## Contributing
35
163
 
36
- Bug reports and pull requests are welcome on GitHub at https://github.com/johnf/pvoutput. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
164
+ Bug reports and pull requests are welcome on GitHub at https://github.com/johnf/pvoutput. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
37
165
 
38
166
 
39
167
  ## License
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bundler/setup'
4
- require 'jfy'
4
+ require 'pvoutput/client'
5
5
 
6
6
  require 'pry'
7
7
  Pry.start
data/circle.yml CHANGED
@@ -4,3 +4,6 @@ test:
4
4
  machine:
5
5
  ruby:
6
6
  version: 2.2.3
7
+ dependencies:
8
+ pre:
9
+ - gem install bundler --pre
@@ -4,16 +4,38 @@ module PVOutput
4
4
  class Client
5
5
  include HTTParty
6
6
  base_uri 'pvoutput.org'
7
- # debug_output $stdout
7
+ debug_output $stdout if ENV['PVOUTPUT_DEBUG']
8
8
 
9
- def initialize(system_id, api_key)
10
- @system_id = system_id
11
- @api_key = api_key
9
+ def initialize(system_id, api_key, donation_mode = false)
10
+ @system_id = system_id.to_s
11
+ @api_key = api_key.to_s
12
+ # The batch operations have default limit of 30 sets of data in one request, when you
13
+ # are using the donation mode the limit is 100 sets
14
+ @batch_size = 30
15
+ @batch_size = 100 if donation_mode
12
16
 
13
17
  self.class.headers 'X-Pvoutput-Apikey' => @api_key, 'X-Pvoutput-SystemId' => @system_id
14
18
  end
15
19
 
16
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
20
+ # Helper method to post batch request to pvoutput that retries at the moment we get
21
+ # a 400 error back with body containing 'Load in progress'
22
+ def post_request(path, options = {}, &block)
23
+ loop do
24
+ response = self.class.post(path, options, &block)
25
+
26
+ if response.code == 400 && response.body =~ /Load in progress/
27
+ # We can't send data too fast, when the previous request is still loaded we
28
+ # have to wait so sleep 10 seconds and try again
29
+ sleep(10)
30
+ elsif response.code == 200
31
+ return
32
+ else
33
+ raise("Bad Post: #{response.body}")
34
+ end
35
+ end
36
+ end
37
+
38
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
17
39
  def add_status(options)
18
40
  time = options[:when] || Time.now
19
41
 
@@ -26,15 +48,63 @@ module PVOutput
26
48
  params[:v2] = options[:power_generated] if options[:power_generated]
27
49
  params[:v3] = options[:energy_consumed] if options[:energy_consumed]
28
50
  params[:v4] = options[:power_consumed] if options[:power_consumed]
29
- params[:v5] = options[:temperature] if options[:temparature]
51
+ params[:v5] = options[:temperature] if options[:temperature]
30
52
  params[:v6] = options[:voltage] if options[:voltage]
31
53
  params[:c1] = 1 if options[:cumulative] == true
32
54
  params[:n] = 1 if options[:net] == true
33
55
 
34
56
  response = self.class.post('/service/r2/addstatus.jsp', :body => params)
35
57
 
36
- fail('Bad Post') unless response.code == 200
58
+ raise('Bad Post') unless response.code == 200
59
+ end
60
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
61
+
62
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
63
+ def add_output(options)
64
+ params = {
65
+ }
66
+
67
+ params[:d] = options[:output_date]
68
+ params[:g] = options[:energy_generated] if options[:energy_generated]
69
+ params[:pp] = options[:peak_power] if options[:peak_power]
70
+ params[:pt] = options[:peak_time] if options[:peak_time]
71
+ params[:cd] = options[:condition] if options[:condition]
72
+ params[:tm] = options[:min_temp] if options[:min_temp]
73
+ params[:tx] = options[:max_temp] if options[:max_temp]
74
+ params[:cm] = options[:comments] if options[:comments]
75
+ params[:ip] = options[:import_peak] if options[:import_peak]
76
+ params[:io] = options[:import_off_peak] if options[:import_off_peak]
77
+ params[:is] = options[:import_shoulder] if options[:import_shoulder]
78
+ params[:ih] = options[:import_high_shoulder] if options[:import_high_shoulder]
79
+ params[:c] = options[:consumption] if options[:consumption]
80
+
81
+ response = self.class.post('/service/r2/addoutput.jsp', :body => params)
82
+
83
+ raise('Bad Post') unless response.code == 200
84
+ end
85
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
86
+
87
+ # rubocop:disable Metrics/AbcSize
88
+ def add_batch_output(options)
89
+ keys = %i(energy_generated energy_export energy_used)
90
+ keys += %i(peak_power peak_time condition min_temp)
91
+ keys += %i(max_temp comments import_peak import_off_peak)
92
+ keys += %i(import_shoulder)
93
+
94
+ options.to_a.each_slice(@batch_size) do |slice|
95
+ data = ''
96
+ slice.each do |entry|
97
+ date, values = entry
98
+ data += "#{date}," + keys.map { |key| values[key] }.join(',') + ';'
99
+ end
100
+
101
+ params = {
102
+ :data => data.chop,
103
+ }
104
+
105
+ post_request('/service/r2/addbatchoutput.jsp', :body => params)
106
+ end
37
107
  end
38
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
108
+ # rubocop:enable Metrics/AbcSize
39
109
  end
40
110
  end
@@ -1,3 +1,3 @@
1
1
  module PVOutput
2
- VERSION = '0.1.0'
2
+ VERSION = '0.5.0'.freeze
3
3
  end
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency 'httparty'
22
22
 
23
- spec.add_development_dependency 'bundler', '~> 1.10'
24
- spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'bundler', '>= 2.1'
24
+ spec.add_development_dependency 'rake', '>= 12.3.3'
25
25
  spec.add_development_dependency 'pry'
26
26
  spec.add_development_dependency 'rspec'
27
27
  spec.add_development_dependency 'webmock'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pvoutput
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Ferlito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-22 00:00:00.000000000 Z
11
+ date: 2020-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -28,30 +28,30 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.10'
33
+ version: '2.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.10'
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: 12.3.3
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: 12.3.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -174,6 +174,7 @@ files:
174
174
  - ".gitignore"
175
175
  - ".rspec"
176
176
  - ".rubocop.yml"
177
+ - CHANGELOG.md
177
178
  - CODE_OF_CONDUCT.md
178
179
  - Gemfile
179
180
  - LICENSE.txt
@@ -205,8 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
206
  - !ruby/object:Gem::Version
206
207
  version: '0'
207
208
  requirements: []
208
- rubyforge_project:
209
- rubygems_version: 2.4.5.1
209
+ rubygems_version: 3.1.2
210
210
  signing_key:
211
211
  specification_version: 4
212
212
  summary: Library to speak to the PVOutput API