solaredge 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +24 -0
- data/lib/solar_edge/client.rb +71 -0
- data/lib/solar_edge/inverter.rb +32 -0
- data/lib/solar_edge/site.rb +71 -0
- data/lib/solar_edge/sites.rb +36 -0
- data/lib/solar_edge/version.rb +3 -0
- data/lib/solaredge.rb +1 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fa7343187ab4b5ba7127ceaed020c9e25cc5ea56
|
4
|
+
data.tar.gz: 196ec1eb598270e502e773f2f8cff18f6839355f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bc78b99da9a1b489fd1fb0b8e250d6adaefec23fe7504a9bae8b358d9f94cc216d24c04ce25a83ac3de63b1117205ac38246cfd5fc3b7609d0845f6655096a24
|
7
|
+
data.tar.gz: 2129a85b70b5148106a6b4f13c8649a219930793083e5904fb641c2f22a0a2b520e82cd9854521db34ff73c027eefba18d77f18d23668597ab9734c4f77704c5
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'The Energy Detective'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
20
|
+
end
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
task :default => :rdoc
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
require 'openssl'
|
5
|
+
|
6
|
+
require 'solar_edge/sites'
|
7
|
+
|
8
|
+
module SolarEdge
|
9
|
+
class Client
|
10
|
+
def initialize(api_key)
|
11
|
+
@api_key = api_key
|
12
|
+
@host = URI.parse('https://monitoringapi.solaredge.com/')
|
13
|
+
@http = Net::HTTP.new(@host.host, @host.port)
|
14
|
+
@http.use_ssl = (@host.scheme == 'https')
|
15
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
16
|
+
end
|
17
|
+
|
18
|
+
def sites(search_text: nil, sort_by: nil, sort_order: nil)
|
19
|
+
raise ArgumentError, "invalid sort_by" if sort_by && !VALID_SORT_PROPERTIES.include?(sort_by)
|
20
|
+
raise ArgumentError, "sort_order must be specific with sort_by" if sort_order && !sort_by
|
21
|
+
raise ArgumentError, "sort_order must be :asc or :desc" if sort_order && !%i{asc desc}.include?(sort_order)
|
22
|
+
|
23
|
+
params = {}
|
24
|
+
params[:search_text] = search_text if search_text
|
25
|
+
params[:sort_property] = sort_by if sort_by
|
26
|
+
params[:sort_order] = sort_order if sort_order
|
27
|
+
|
28
|
+
# we cache the "all sites" query
|
29
|
+
if params.empty?
|
30
|
+
@sites ||= Sites.new(self, params)
|
31
|
+
else
|
32
|
+
Sites.new(self, params)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
VALID_SORT_PROPERTIES = %i{
|
39
|
+
Name
|
40
|
+
Country
|
41
|
+
State
|
42
|
+
City
|
43
|
+
Address
|
44
|
+
Zip
|
45
|
+
Status
|
46
|
+
PeakPower
|
47
|
+
InstallationDate
|
48
|
+
Amount
|
49
|
+
MaxSeverity
|
50
|
+
CreationTime
|
51
|
+
}.freeze
|
52
|
+
private_constant :VALID_SORT_PROPERTIES
|
53
|
+
|
54
|
+
def query(path, params = {})
|
55
|
+
params = params.merge(api_key: @api_key)
|
56
|
+
|
57
|
+
uri = @host.merge(path)
|
58
|
+
uri.query = self.class.hash_to_query(params)
|
59
|
+
|
60
|
+
puts uri
|
61
|
+
get = Net::HTTP::Get.new(uri)
|
62
|
+
response = @http.request(get)
|
63
|
+
response.body
|
64
|
+
JSON.load(response.body)
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.hash_to_query(hash)
|
68
|
+
hash.map{|k,v| "#{k}=#{v}" }.join("&")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module SolarEdge
|
2
|
+
class Inverter
|
3
|
+
attr_reader :name, :manufacturer, :model, :serial_number
|
4
|
+
|
5
|
+
def initialize(site, name, manufacturer, model, serial_number)
|
6
|
+
@site, @name, @manufacturer, @model, @serial_number = site, name, manufacturer, model, serial_number
|
7
|
+
end
|
8
|
+
|
9
|
+
def data(start_time: @site.time_zone.now.beginning_of_day, end_time: @site.time_zone.now)
|
10
|
+
params = {}
|
11
|
+
params[:startTime] = start_time.in_time_zone(@site.time_zone).strftime('%Y-%m-%d %H:%M:%S')
|
12
|
+
params[:endTime] = end_time.in_time_zone(@site.time_zone).strftime('%Y-%m-%d %H:%M:%S')
|
13
|
+
|
14
|
+
@site.instance_variable_get(:@client).send(:query,
|
15
|
+
"/equipment/#{@site.id}/#{serial_number}/data", params)['data']['telemetries'].map do |value|
|
16
|
+
{
|
17
|
+
timestamp: @site.time_zone.parse(value['date']),
|
18
|
+
total_active_power: value['totalActivePower'],
|
19
|
+
dc_voltage: value['dcVoltage'],
|
20
|
+
ground_fault_resistance: value['groundFaultResistance'],
|
21
|
+
total_energy: value['totalEnergy'],
|
22
|
+
temperature: value['temperature'],
|
23
|
+
inverter_mode: value['inverterMode'].to_sym
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
"#<SolarEdge::Inverter:#{serial_number} #{manufacturer} #{model} - #{name}>"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'active_support/time'
|
2
|
+
|
3
|
+
require 'solar_edge/inverter'
|
4
|
+
|
5
|
+
module SolarEdge
|
6
|
+
class Site
|
7
|
+
attr_reader :id
|
8
|
+
|
9
|
+
def initialize(client, id_or_details)
|
10
|
+
@client = client
|
11
|
+
if id_or_details.is_a?(Hash)
|
12
|
+
@details = id_or_details
|
13
|
+
@id = @details['id']
|
14
|
+
else
|
15
|
+
@id = id
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def time_zone
|
20
|
+
@time_zone ||= ActiveSupport::TimeZone.new(details['location']['timeZone'])
|
21
|
+
end
|
22
|
+
|
23
|
+
def data_period
|
24
|
+
response = @client.send(:query, "/site/#{id}/dataPeriod")['dataPeriod']
|
25
|
+
time_zone.parse(response['startDate'])..time_zone.parse(response['endDate'])
|
26
|
+
end
|
27
|
+
|
28
|
+
def energy(resolution: :quarter_of_an_hour, start_date: time_zone.now, end_date: time_zone.now)
|
29
|
+
raise ArgumentError, "invalid resolution" unless %i{quarter_of_an_hour hour day week month year}.include?(resolution)
|
30
|
+
params = {}
|
31
|
+
params[:timeUnit] = resolution.to_s.upcase
|
32
|
+
params[:startDate] = start_date.to_date
|
33
|
+
params[:endDate] = end_date.to_date
|
34
|
+
|
35
|
+
@client.send(:query, "/site/#{id}/energy", params)['energy']['values'].map do |value|
|
36
|
+
{
|
37
|
+
timestamp: time_zone.parse(value['date']),
|
38
|
+
value: value['value']
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def power(start_time: time_zone.now.beginning_of_day, end_time: time_zone.now)
|
44
|
+
params = {}
|
45
|
+
params[:startTime] = start_time.in_time_zone(time_zone).strftime('%Y-%m-%d %H:%M:%S')
|
46
|
+
params[:endTime] = end_time.in_time_zone(time_zone).strftime('%Y-%m-%d %H:%M:%S')
|
47
|
+
|
48
|
+
@client.send(:query, "/site/#{id}/power", params)['power']['values'].map do |value|
|
49
|
+
{
|
50
|
+
timestamp: time_zone.parse(value['date']),
|
51
|
+
value: value['value']
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def inverters
|
57
|
+
@inverters ||= @client.send(:query, "/equipment/#{id}/list")['reporters']['list'].map do |inverter|
|
58
|
+
Inverter.new(self,
|
59
|
+
inverter['name'],
|
60
|
+
inverter['manufacturer'],
|
61
|
+
inverter['model'],
|
62
|
+
inverter['serialNumber'])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
private
|
66
|
+
|
67
|
+
def details
|
68
|
+
@details ||= @client.send(:query, "/site/#{id}/details")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'solar_edge/site'
|
2
|
+
|
3
|
+
module SolarEdge
|
4
|
+
class Sites
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize(client, params)
|
8
|
+
@client, @params = client, params
|
9
|
+
end
|
10
|
+
|
11
|
+
def find(id)
|
12
|
+
Site.new(client, id)
|
13
|
+
end
|
14
|
+
|
15
|
+
def size
|
16
|
+
params = @params.dup
|
17
|
+
params[:size] = 1
|
18
|
+
@client.send(:query, '/sites/list', params)['sites']['count']
|
19
|
+
end
|
20
|
+
|
21
|
+
def each
|
22
|
+
params = @params.dup
|
23
|
+
params[:size] = 100
|
24
|
+
params[:startIndex] = 0
|
25
|
+
while true
|
26
|
+
sites = @client.send(:query, '/sites/list', params)['sites']
|
27
|
+
sites['site'].each do |site|
|
28
|
+
yield Site.new(@client, site)
|
29
|
+
end
|
30
|
+
break if sites['site'].length < params[:size] ||
|
31
|
+
params[:startIndex] + sites['site'].length == sites['count']
|
32
|
+
params[:startIndex] += sites['site'].length
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/solaredge.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'solar_edge/client'
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: solaredge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cody Cutrer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 10.4.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 10.4.2
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- cody@cutrer.us
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- Rakefile
|
49
|
+
- lib/solar_edge/client.rb
|
50
|
+
- lib/solar_edge/inverter.rb
|
51
|
+
- lib/solar_edge/site.rb
|
52
|
+
- lib/solar_edge/sites.rb
|
53
|
+
- lib/solar_edge/version.rb
|
54
|
+
- lib/solaredge.rb
|
55
|
+
homepage: http://www.solaredge.com/
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.1'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.4.5
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Client library for talking to the SolarEdge monitoring API
|
79
|
+
test_files: []
|