smart_energy_group 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 66afda4f4241fb3cf1a7b1f9e3e8f83da0f26de7
4
+ data.tar.gz: 6a01347689a74c65829b01a44a2c32e1bacd3eef
5
+ SHA512:
6
+ metadata.gz: 61f7bf4e66367770773b86e3d94ff0607ec46b6273d256f095fe75894ccde511e32e1b0f645491b794adf8e9e9b0a5cde55572bb81b9caa45b347055f78ca707
7
+ data.tar.gz: ad3a612446cb9ffb903bad1886051b4093cec4c66f3af0858bc903d95318364ba36e787df673c7f537f8e6aa7bd5c5c4e7f94964714277290c158bd8c473e607
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ /.bundle/
2
+ /Gemfile.lock
3
+ /coverage/
4
+ /pkg/
5
+ /spec/reports/
6
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ require: rubocop-rspec
2
+
3
+ HashSyntax:
4
+ EnforcedStyle: hash_rockets
5
+
6
+ Style/Documentation:
7
+ Enabled: false
8
+
9
+ Style/Lambda:
10
+ Enabled: false
11
+
12
+ Style/TrailingCommaInLiteral:
13
+ EnforcedStyleForMultiline: comma
14
+
15
+ Metrics/LineLength:
16
+ Max: 120
17
+
18
+ Style/ModuleFunction:
19
+ Enabled: false
20
+
21
+ AlignHash:
22
+ EnforcedHashRocketStyle: table
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.0.1 (2016-05-14)
4
+
5
+ * Initial Release (@johnf)
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behaviour by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behaviour may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 John Ferlito
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # Smart Energy Group
2
+
3
+ [![Circle CI](https://circleci.com/gh/johnf/smart_energy_group.svg?style=svg)](https://circleci.com/gh/johnf/smart_energy_group)
4
+ [![Coverage Status](https://coveralls.io/repos/johnf/smart_energy_group/badge.svg?branch=master&service=github)](https://coveralls.io/github/johnf/smart_energy_group?branch=master)
5
+
6
+ Ruby library for talking to the Smart Energy Group API.
7
+
8
+ Documentation for the API can be found at https://smartenergygroups.com/api
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ``` ruby
15
+ gem 'smart_energy_group'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install smart_energy_group
25
+
26
+ ## Usage
27
+
28
+ In order to use smart_energy_group in your application you need to use
29
+
30
+ ``` ruby
31
+ require 'smart_energy_group/client'
32
+ ```
33
+
34
+ First step is to create a Smart Energy Group client using your Smart Energy Group assigned site_token
35
+
36
+ ``` ruby
37
+ seg = SmartEnergyGroup::Client.new(site_token)
38
+ ```
39
+
40
+ You can then push data points
41
+
42
+ ``` ruby
43
+ seg.send_data(
44
+ 'home',
45
+ :temperature => [20.5, 60.0],
46
+ :power => [1023.6, 500.9]
47
+ )
48
+ ```
49
+
50
+ The send_data operation accepts the following options
51
+
52
+ | Option | Description |
53
+ | ----------- | ----------- |
54
+ | power | Power stream with the unit of watts |
55
+ | energy | Energy stream with the unit prefixed to kilowatt hours |
56
+ | amps | Current stream with the unit of amps |
57
+ | channel | Power stream identified with the Phase based on the channel number, with the same settings as a normal power stream |
58
+ | temperature | Temperature stream with default units of Celcius |
59
+ | voltage | Voltage stream with the units being volts |
60
+ | state | Switch state stream to determine if a switch is on or off |
61
+ | seconds | Seconds stream representitive of an elapsed time in seconds |
62
+ | heartbeat | Boot Event stream to determine if your device has booted and also records a heartbeat to check things are still ticking |
63
+ | pule | Count of pulses output from a device |
64
+
65
+ **Note::** The above will raise an error until you put the site into Discovery mode on the SEG website.
66
+
67
+ ## Development
68
+
69
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
70
+
71
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
72
+
73
+ ## Contributing
74
+
75
+ 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.
76
+
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new
7
+
8
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'smart_energy_group/client'
5
+
6
+ puts '# Example'
7
+ puts
8
+ puts 'site_token = \'1234\''
9
+ puts 'seg = SmartEnergyGroup::Client.new(site_token)'
10
+ puts 'seg.send_data(\'home\', :temperature => [1, 2, 3, 4])'
11
+ puts
12
+
13
+ require 'pry'
14
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/bin/bash
2
+
3
+ set -euo pipefail
4
+ IFS=$'\n\t'
5
+
6
+ bundle install
data/circle.yml ADDED
@@ -0,0 +1,9 @@
1
+ test:
2
+ post:
3
+ - bundle exec rubocop
4
+ machine:
5
+ ruby:
6
+ version: 2.3.1
7
+ dependencies:
8
+ pre:
9
+ - gem install bundler --pre
@@ -0,0 +1,49 @@
1
+ require 'httparty'
2
+
3
+ module SmartEnergyGroup
4
+ class Client
5
+ include HTTParty
6
+ base_uri 'api.smartenergygroups.com'
7
+ format :plain
8
+ # debug_output $stdout
9
+
10
+ def initialize(site_token)
11
+ @site_token = site_token
12
+ end
13
+
14
+ DATA_TYPES = {
15
+ :power => 'p',
16
+ :energy => 'e',
17
+ :amps => 'a',
18
+ :channel => 'c',
19
+ :temperature => 'temperature',
20
+ :voltage => 'v',
21
+ :state => 'state',
22
+ :seconds => 'seconds',
23
+ :heartbeat => 'heartbeat',
24
+ :pulse => 'pulse',
25
+ }.freeze
26
+
27
+ def send_data(node_name, options)
28
+ time = options[:when] || Time.now
29
+ time = time.strftime('%FT%T')
30
+
31
+ data = generate_data(options)
32
+ msg = "(site #{@site_token} (node #{node_name} #{time} #{data}))"
33
+
34
+ response = self.class.put('/api_sites/stream', :body => msg)
35
+
36
+ raise("Bad Post: #{response.body}") unless response.code == 200 && response.body == "(status ok)\n"
37
+ end
38
+
39
+ def generate_data(options)
40
+ data = []
41
+ DATA_TYPES.keys.each do |type|
42
+ next unless options[type]
43
+ data += options[type].map.with_index(1) { |value, i| "(#{DATA_TYPES[type]}_#{i} #{value})" }
44
+ end
45
+
46
+ data.join('')
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module SmartEnergyGroup
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'smart_energy_group/version'
2
+
3
+ module SmartEnergyGroup
4
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'smart_energy_group/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'smart_energy_group'
8
+ spec.version = SmartEnergyGroup::VERSION
9
+ spec.authors = ['John Ferlito']
10
+ spec.email = ['johnf@inodes.org']
11
+
12
+ spec.summary = 'Library to speak to the Smart Energy Group API'
13
+ spec.homepage = 'https://github.com/johnf/smart_energy_group'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.require_paths = ['lib']
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+
21
+ spec.add_dependency 'httparty'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.10'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'pry'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'webmock'
28
+ spec.add_development_dependency 'timecop'
29
+ spec.add_development_dependency 'rubocop'
30
+ spec.add_development_dependency 'rubocop-rspec'
31
+ spec.add_development_dependency 'rspec_junit_formatter'
32
+ spec.add_development_dependency 'coveralls'
33
+ end
metadata ADDED
@@ -0,0 +1,214 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_energy_group
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - John Ferlito
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: timecop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec_junit_formatter
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: coveralls
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description:
168
+ email:
169
+ - johnf@inodes.org
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".rubocop.yml"
177
+ - CHANGELOG.md
178
+ - CODE_OF_CONDUCT.md
179
+ - Gemfile
180
+ - LICENSE.txt
181
+ - README.md
182
+ - Rakefile
183
+ - bin/console
184
+ - bin/setup
185
+ - circle.yml
186
+ - lib/smart_energy_group.rb
187
+ - lib/smart_energy_group/client.rb
188
+ - lib/smart_energy_group/version.rb
189
+ - smart_energy_group.gemspec
190
+ homepage: https://github.com/johnf/smart_energy_group
191
+ licenses:
192
+ - MIT
193
+ metadata: {}
194
+ post_install_message:
195
+ rdoc_options: []
196
+ require_paths:
197
+ - lib
198
+ required_ruby_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ required_rubygems_version: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ requirements: []
209
+ rubyforge_project:
210
+ rubygems_version: 2.5.1
211
+ signing_key:
212
+ specification_version: 4
213
+ summary: Library to speak to the Smart Energy Group API
214
+ test_files: []