solarium 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/solarium-collect +55 -0
- data/lib/solarium/collector.rb +48 -0
- data/lib/solarium/database.rb +49 -0
- data/lib/solarium/version.rb +23 -0
- data/lib/solarium.rb +10 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d0c5c4f5db3d02c348ed02e9b9ba42629372c598
|
4
|
+
data.tar.gz: 437ee53bb835aa18834057fc8ca2f0ba72ed52bd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8ca7ba6a541d4ee16612e006ef10f4df1f047bf93bf74761042b5ca738891c3821d07732aba4d85d35fc93b48943ac58e285170f48fadabb2d4e42123179ff6f
|
7
|
+
data.tar.gz: 7f4d02d5ed1658045d82cadbf07b20efcbf3c3c27810e31b046b07479075fbaee2c9c730ade15517c2a83f0c409285bc30e45eb1894e906d4684e0aeca42584a
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Solarium (C) 2017 Peter "SaberUK" Powell <petpow@saberuk.com>
|
3
|
+
|
4
|
+
APP_ROOT = File.dirname __dir__
|
5
|
+
if Dir.exist? "#{APP_ROOT}/.git"
|
6
|
+
$LOAD_PATH.unshift "#{APP_ROOT}/lib"
|
7
|
+
end
|
8
|
+
|
9
|
+
%w(solarium trollop).each do |lib|
|
10
|
+
begin
|
11
|
+
require lib
|
12
|
+
rescue ::Exception => error
|
13
|
+
STDERR.puts "A fatal error was encountered whilst loading #{lib}:"
|
14
|
+
STDERR.puts "#{error.class}: #{error.message}"
|
15
|
+
exit 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
APP_NAME = File.basename $PROGRAM_NAME
|
20
|
+
options = Trollop::options do
|
21
|
+
banner "Usage: #{APP_NAME} [OPTIONS]"
|
22
|
+
version Solarium::VERSION
|
23
|
+
|
24
|
+
opt :database_url, 'The URL for connecting to the SQL database', default: 'sqlite://production.sq3'
|
25
|
+
opt :envoy_url, 'The URL of the Envoy web interface', default: 'http://192.168.1.200/'
|
26
|
+
opt :print_stats, 'Print generation statistics after collection', default: false
|
27
|
+
end
|
28
|
+
|
29
|
+
Trollop::die :database_url, 'is not a valid URL' unless options[:database_url] =~ /^#{URI.regexp}$/
|
30
|
+
Trollop::die :envoy_url, 'is not a valid URL' unless options[:envoy_url] =~ /^#{URI.regexp}$/
|
31
|
+
|
32
|
+
collector = Solarium::Collector.new options[:envoy_url]
|
33
|
+
unless collector.error.nil?
|
34
|
+
STDERR.puts "A fatal error was encountered whilst collecting data:"
|
35
|
+
STDERR.puts "#{collector.error.class}: #{collector.error.message}"
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
|
39
|
+
if options[:print_stats]
|
40
|
+
puts <<~STATISTICS
|
41
|
+
== Generation Statistics ==
|
42
|
+
Currently: #{collector.now} watts
|
43
|
+
Today: #{collector.today} watt hours
|
44
|
+
Past Week: #{collector.week} watt hours
|
45
|
+
Since Installation: #{collector.lifetime} watt hours
|
46
|
+
STATISTICS
|
47
|
+
end
|
48
|
+
|
49
|
+
database = Solarium::Database.new options[:database_url]
|
50
|
+
unless database.error.nil?
|
51
|
+
STDERR.puts "A fatal error was encountered whilst connecting to the database:"
|
52
|
+
STDERR.puts "#{database.error.class}: #{database.error.message}"
|
53
|
+
exit 1
|
54
|
+
end
|
55
|
+
database.insert collector
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Solarium (C) 2017 Peter "SaberUK" Powell <petpow@saberuk.com>
|
2
|
+
|
3
|
+
module Solarium
|
4
|
+
|
5
|
+
# Public: Collects generation information from the Envoy API.
|
6
|
+
class Collector
|
7
|
+
|
8
|
+
# Public: Either an exception that was thrown during collection or nil.
|
9
|
+
attr_reader :error
|
10
|
+
|
11
|
+
# Public: The number of watt hours which have been generated since the system was installed.
|
12
|
+
attr_reader :lifetime
|
13
|
+
|
14
|
+
# Public: The number of watts currently being generated.
|
15
|
+
attr_reader :now
|
16
|
+
|
17
|
+
# Public: The number of watt hours which have been generated today.
|
18
|
+
attr_reader :today
|
19
|
+
|
20
|
+
# Public: The number of watt hours which have been generated in the last week.
|
21
|
+
attr_reader :week
|
22
|
+
|
23
|
+
# Public: Initializes a new instance of the Solarium::Collector class.
|
24
|
+
#
|
25
|
+
# url - The URL of the Envoy web interface.
|
26
|
+
def initialize url
|
27
|
+
collect url
|
28
|
+
rescue ::Exception => error
|
29
|
+
@error = error
|
30
|
+
end
|
31
|
+
|
32
|
+
# Internal: Collects generation information from the Envoy API.
|
33
|
+
#
|
34
|
+
# url - The URL of the Envoy web interface.
|
35
|
+
private def collect url
|
36
|
+
uri = URI.parse url
|
37
|
+
uri.path = '/api/v1/production'
|
38
|
+
|
39
|
+
body = open(uri).read
|
40
|
+
json = JSON.parse body
|
41
|
+
|
42
|
+
@now = json['wattsNow']
|
43
|
+
@today = json['wattHoursToday']
|
44
|
+
@week = json['wattHoursSevenDays']
|
45
|
+
@lifetime = json['wattHoursLifetime']
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Solarium (C) 2017 Peter "SaberUK" Powell <petpow@saberuk.com>
|
2
|
+
|
3
|
+
module Solarium
|
4
|
+
|
5
|
+
# Public: Implements logic for interacting with the Solarium database.
|
6
|
+
class Database
|
7
|
+
|
8
|
+
# Public: Either an exception that was thrown during database connection or nil.
|
9
|
+
attr_reader :error
|
10
|
+
|
11
|
+
# Public: Initializes a new instance of the Solarium::Database class.
|
12
|
+
#
|
13
|
+
# url - The URL for connecting to the SQL database.
|
14
|
+
def initialize url
|
15
|
+
connect url
|
16
|
+
rescue ::Exception => error
|
17
|
+
@error = error
|
18
|
+
end
|
19
|
+
|
20
|
+
# Public: Stores the information provided by a Solarium::Collector in the database.
|
21
|
+
#
|
22
|
+
# collector - An instance of the Solarium::Collector class containing information to store.
|
23
|
+
def insert collector
|
24
|
+
row = {
|
25
|
+
time: DateTime.now,
|
26
|
+
now: collector.now,
|
27
|
+
today: collector.today,
|
28
|
+
week: collector.week,
|
29
|
+
lifetime: collector.lifetime
|
30
|
+
}
|
31
|
+
@connection[:solarium].insert row
|
32
|
+
end
|
33
|
+
|
34
|
+
# Internal: Connects to the database and creates the table if required.
|
35
|
+
#
|
36
|
+
# url - The URL for connecting to the SQL database.
|
37
|
+
private def connect url
|
38
|
+
@connection = Sequel.connect url
|
39
|
+
@connection.create_table? :solarium do
|
40
|
+
column :time, DateTime, primary_key: true
|
41
|
+
column :now, Integer, null: false
|
42
|
+
column :today, Integer, null: false
|
43
|
+
column :week, Integer, null: false
|
44
|
+
column :lifetime, Integer, null: false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Solarium (C) 2017 Peter "SaberUK" Powell <petpow@saberuk.com>
|
2
|
+
|
3
|
+
module Solarium
|
4
|
+
|
5
|
+
# Public: The version number which is incremented when compatibility is broken.
|
6
|
+
VERSION_MAJOR = 0
|
7
|
+
|
8
|
+
# Public: The version number which is incremented when new features are added.
|
9
|
+
VERSION_MINOR = 1
|
10
|
+
|
11
|
+
# Public: The version number which is incremented when bugs are fixed.
|
12
|
+
VERSION_PATCH = 0
|
13
|
+
|
14
|
+
# Public: The version label which describes the status of the build.
|
15
|
+
VERSION_LABEL = nil
|
16
|
+
|
17
|
+
# Public: A string which contains the current version.
|
18
|
+
VERSION = if VERSION_LABEL.nil?
|
19
|
+
"#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}"
|
20
|
+
else
|
21
|
+
"#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}-#{VERSION_LABEL}"
|
22
|
+
end
|
23
|
+
end
|
data/lib/solarium.rb
ADDED
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: solarium
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter "SaberUK" Powell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.1.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.1.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: sequel
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '5.1'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 5.1.0
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '5.1'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 5.1.0
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: trollop
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '2.1'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.1.2
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.1'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 2.1.2
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: rdoc
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '5.1'
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 5.1.0
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.1'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 5.1.0
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: tomdoc
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 0.2.5
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - "~>"
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 0.2.5
|
107
|
+
description: A tool for working with generation data collected from the Enphase Envoy
|
108
|
+
solar panel management system.
|
109
|
+
email: petpow@saberuk.com
|
110
|
+
executables:
|
111
|
+
- solarium-collect
|
112
|
+
extensions: []
|
113
|
+
extra_rdoc_files: []
|
114
|
+
files:
|
115
|
+
- bin/solarium-collect
|
116
|
+
- lib/solarium.rb
|
117
|
+
- lib/solarium/collector.rb
|
118
|
+
- lib/solarium/database.rb
|
119
|
+
- lib/solarium/version.rb
|
120
|
+
homepage: https://github.com/SaberUK/solarium
|
121
|
+
licenses:
|
122
|
+
- Apache-2.0
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 2.1.0
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.6.13
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Enphase Envoy generation data manipulation tool.
|
144
|
+
test_files: []
|