Skip to content

Commit 3853ca5

Browse files
committed
Use PvOutputWrapper for requests.
1 parent 8868a78 commit 3853ca5

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

app/models/pv_output.rb

+10-6
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def output_pa
6161
# Find date exactly n years before date_to.
6262
year_count = (entries_period / 365).to_i
6363
start_date = (date_to - year_count.years).strftime('%Y%m%d')
64-
query_params = { :sid1 => self.id, :date_from => start_date, :date_to => self.date_to }
64+
query_params = { :sid1 => self.id, :df => start_date, :dt => self.date_to }
6565
stats = PvOutputWrapper::Request.get_statistic(query_params)
6666
stats['total_output'].to_i / year_count
6767
end
@@ -116,9 +116,8 @@ def self.search(query)
116116
params = { :q => query,
117117
:country => 'Australia' }
118118
request = PvOutputWrapper::Request.new(Rails.application.secrets.pvo_api_key,
119-
Rails.application.secrets.pvo_system_id)
119+
Rails.application.secrets.pvo_system_id)
120120
response = request.search(params).body
121-
# response = self.request('search', params)
122121
response.chomp!
123122
results = []
124123
keys = ['name', 'system_watts', 'postcode', 'orientation', 'entries', 'last_entry', 'id', 'panel', 'inverter', 'distance', 'latitude', 'longitude']
@@ -138,10 +137,12 @@ def self.search(query)
138137
end
139138

140139
# @param [Fixnum]
141-
# TODO handle nil/empty resultset
140+
# TODO: handle nil/empty resultset
142141
# @return [Hash] of system info data.
143142
def self.get_system(id)
144-
response = self.request('getsystem', {:sid1 => id})
143+
request = PvOutputWrapper::Request.new(Rails.application.secrets.pvo_api_key,
144+
Rails.application.secrets.pvo_system_id)
145+
response = request.get_system({:sid1 => id}).body
145146
keys = %w(system_watts panel_count panel_watts orientation tilt shade install_date sec_panel_count sec_panel_watts sec_bearing sec_tilt)
146147
results_array = response.split(/,/)
147148
selected_results = results_array.values_at(1, 3, 4, 9, 10, 11, 12, 16, 17, 18, 19)
@@ -168,10 +169,13 @@ def get_output
168169
results
169170
end
170171

172+
# @arg [Hash]
171173
# @return [Hash<String, >] system data or nil values upon failure.
172174
# Keep as class method for flexibility.
173175
def self.get_statistic(query_params={})
174-
response = self.request('getstatistic', query_params)
176+
request = PvOutputWrapper::Request.new(Rails.application.secrets.pvo_api_key,
177+
Rails.application.secrets.pvo_system_id)
178+
response = request.get_statistic(query_params).body
175179
# total_output is in watt hours
176180
keys = ['total_output', 'efficiency', 'date_from', 'date_to']
177181
results_array = response.split(/,/)

0 commit comments

Comments
 (0)