WinkerAI 0.0.01

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ade891c4682adec3edc24e9c211c989ca1175268
4
+ data.tar.gz: 331ef19377d698de633fc45ba05bda9d99cb634e
5
+ SHA512:
6
+ metadata.gz: bab793b9c88414e516ef2bdef9e11e05571d147eb113b80e3b5d5618df5bb5bd50f356d2264255132e55ef2035ec9f96321a4ba74d40e798ce43e1ea954bc178
7
+ data.tar.gz: 353090b39beaadccf2d55f02bdc5eb0d626d3dde5ad139dc4b92aba3a68ec2ebb05674ecc8b9625087ac6f6e5f387af4867e88c993076c9ece0f06f7fcaf9b8b
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .gems/
16
+ .rbenv-gemsets
17
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in AmazonEchoJS.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Kelly Mahan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ # WinkerAI
2
+
3
+ WinkerAI is an AI approach to controlling Wink hub components by making use of the Winker gem and Wink API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'WinkerAI'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install winker_ai
20
+
21
+ ## Associated Gems
22
+
23
+ Winker
24
+ AmazonEchoJS
25
+
26
+ ## Usage
27
+
28
+ This gem was intended to be used with my AmazonEchoJS gem, but I made it modular enough that any text input should work.
29
+
30
+ First you will need to configure some ENV variables
31
+
32
+ ENV['WINK_CLIENT_ID']
33
+ ENV['WINK_CLIENT_SECRET']
34
+ ENV['WINK_ACCESS_TOKEN']
35
+ ENV['WINK_REFRESH_TOKEN']
36
+ ENV['WINK_USERNAME']
37
+ ENV['WINK_PASSWORD']
38
+ ENV['WINK_ENDPOINT']
39
+
40
+ to run winker_ai server
41
+
42
+ winker_ai_start
43
+
44
+ This starts up a sinatra server that listens on port 4567 for the /command?q=string and parses it for Winker commands.
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it ( https://github.com/[my-github-username]/AmazonEchoJS/fork )
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'winker_ai'
5
+ require 'sinatra'
6
+
7
+ #start up sinatra listener
8
+
9
+ WinkerAI.setup
10
+
11
+ get '/command' do
12
+ # matches "GET /hello/foo" and "GET /hello/bar"
13
+ # params['name'] is 'foo' or 'bar'
14
+ puts params[:q]
15
+ WinkerAI.check_for_trigger(params[:q])
16
+ "success"
17
+ end
@@ -0,0 +1,8 @@
1
+ require 'winker'
2
+ module WinkerAI
3
+
4
+ end
5
+
6
+
7
+ require "winker_ai/version"
8
+ require "winker_ai/triggers"
@@ -0,0 +1,5 @@
1
+ class Hash
2
+ def +(value)
3
+ self.merge(value)
4
+ end
5
+ end
@@ -0,0 +1,178 @@
1
+
2
+ module WinkerAI
3
+
4
+ # ON_OFF = {on: /on/, off: /off/}
5
+ # UP_DOWN = {down: /down/, up: /up/}
6
+ # BRIGHTNESS = {percent: /\d{1,3}( percent){0,1}/}+UP_DOWN
7
+ #
8
+ # AIGROUPS = {
9
+ # name: "Lights",
10
+ # triggers: [
11
+ # {
12
+ # regex: /(dim|raise|lower).*lights{0,1}/,
13
+ # methods: [:brightness],
14
+ # values: BRIGHTNESS_VALUES
15
+ # },
16
+ # {
17
+ # regex: /turn.*lights{0,1}/,
18
+ # methods: [:on, :off, :brightness]
19
+ # values: UP_DOWN+ON_OFF
20
+ # },
21
+ # {
22
+ # regex: /shut.*lights{0,1}/
23
+ # }
24
+ # ]
25
+ # }
26
+
27
+ LIGHT_TRIGGERS = %w(dim raise lower shut turn)
28
+
29
+ NUMBERS_MODIFIER = {
30
+ "twenty" => 20,
31
+ "thirty" => 30,
32
+ "fourty" => 40,
33
+ "fifty" => 50,
34
+ "sixty" => 60,
35
+ "seventy" => 70,
36
+ "eighty" => 80,
37
+ "ninety" => 90
38
+ }
39
+
40
+ NUMBERS_MATCH = {
41
+ "zero" => 0,
42
+ "half" => 50,
43
+ "ten" => 10,
44
+ "eleven" => 11,
45
+ "twelve" => 12,
46
+ "thirteen" => 13,
47
+ "fourteen" => 14,
48
+ "fifteen" => 15,
49
+ "sixteen" => 16,
50
+ "seventeen" => 17,
51
+ "eighteen" => 18,
52
+ "nineteen" => 19,
53
+ "one hundred" => 100
54
+ }
55
+
56
+ NUMBERS_ADD = {
57
+ "one" => 1,
58
+ "two" => 2,
59
+ "three" => 3,
60
+ "four" => 4,
61
+ "five" => 5,
62
+ "six" => 6,
63
+ "seven" => 7,
64
+ "eight" => 8,
65
+ "nine" => 9
66
+ }
67
+
68
+ LIGHT_TYPES = %w(light_bulb)
69
+
70
+ def self.check_for_trigger(string)
71
+ case string
72
+ when /(#{LIGHT_TRIGGERS.join("|")}).*lights{0,1}/
73
+ puts "handling lights"
74
+ handle_lights(string)
75
+ else
76
+ #do nothing
77
+ end
78
+ end
79
+
80
+ def self.handle_lights(string)
81
+ number = find_number(string)
82
+ devices = $wink_groups.select{|d| string.match(/#{d.name}/i)}
83
+ devices = $wink_devices.select{|d| string.match(/#{d.name}/i)} if devices.empty?
84
+ case
85
+ when number && string.match(/(#{LIGHT_TRIGGERS.join("|")})/) && !devices.empty?
86
+ puts "case 1"
87
+ devices.each do |d|
88
+ d.brightness = number/100.0
89
+ end
90
+ when !number && (_match1 = string.match(/(#{LIGHT_TRIGGERS.join("|")})/)[1]) && !devices.empty?
91
+ puts "case 2"
92
+ case
93
+ when _match1 == "raise"
94
+ puts "case 3"
95
+ devices.each do |d|
96
+ d.brightness = [d.brightness+0.25,1].min
97
+ end
98
+ when _match1 == "lower"
99
+ puts "case 4"
100
+ devices.each do |d|
101
+ d.brightness = [d.brightness-0.25,0].max
102
+ end
103
+ when _match2 = string.match(/turn.*(on|off)/)[1]
104
+ puts "case 5"
105
+ devices.each do |d|
106
+ d.send(_match2)
107
+ end
108
+ end
109
+ when number && string.match(/(#{LIGHT_TRIGGERS.join("|")})/) && devices.empty?
110
+ puts "case 6"
111
+ lights.each do |d|
112
+ d.brightness = number/100.0
113
+ end
114
+ when !number && (_match1 = string.match(/(#{LIGHT_TRIGGERS.join("|")})/)[1]) && devices.empty?
115
+ puts "case 7"
116
+ case
117
+ when _match1 == "raise"
118
+ puts "case 8"
119
+ lights.each do |d|
120
+ d.brightness = [d.brightness+0.25,1].min
121
+ end
122
+ when _match1 == "lower"
123
+ puts "case 9"
124
+ lights.each do |d|
125
+ d.brightness = [d.brightness-0.25,0].max
126
+ end
127
+ when _match2 = string.match(/turn (on|off)/)[1]
128
+ puts "case 10"
129
+ lights.each do |d|
130
+ d.send(_match2)
131
+ end
132
+ end
133
+ end
134
+ end
135
+
136
+ def self.find_number(string)
137
+ found_number = case string
138
+ when /(#{NUMBERS_MODIFIER.keys.join("|")}) (#{NUMBERS_ADD.keys.join("|")})/
139
+ NUMBERS_MODIFIER[$1]+NUMBERS_ADD[$2]
140
+ when /(#{NUMBERS_MODIFIER.keys.join("|")})/
141
+ NUMBERS_MODIFIER[$1]
142
+ when /(#{NUMBERS_MATCH.keys.join("|")})/
143
+ NUMBERS_MATCH[$1]
144
+ when /(#{NUMBERS_ADD.keys.join("|")})/
145
+ NUMBERS_ADD[$1]
146
+ else
147
+ nil
148
+ end
149
+ return found_number
150
+ end
151
+
152
+ def self.lights
153
+ $wink_devices.select{|d| LIGHT_TYPES.include?(d.type)}
154
+ end
155
+
156
+ def self.setup
157
+ Winker.configure do |wink|
158
+ wink.client_id = ENV['WINK_CLIENT_ID']
159
+ wink.client_secret = ENV['WINK_CLIENT_SECRET']
160
+ wink.access_token = ENV['WINK_ACCESS_TOKEN']
161
+ wink.refresh_token = ENV['WINK_REFRESH_TOKEN']
162
+ wink.username = ENV['WINK_USERNAME']
163
+ wink.password = ENV['WINK_PASSWORD']
164
+ wink.endpoint = ENV['WINK_ENDPOINT']
165
+ end
166
+ set_devices
167
+ end
168
+
169
+ def self.set_devices
170
+ begin
171
+ $wink_devices ||= Winker.devices
172
+ $wink_groups ||= Winker.groups
173
+ rescue
174
+ Winker.authorize
175
+ retry
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,3 @@
1
+ module WinkerAI
2
+ VERSION = "0.0.01"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'winker_ai/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "WinkerAI"
8
+ spec.version = WinkerAI::VERSION
9
+ spec.authors = ["Kelly Mahan"]
10
+ spec.email = ["kmahan@kmahan.com"]
11
+ spec.summary = %q{WinkerAI is an AI approach to controlling Wink hub components by making use of the Winker gem and Wink API}
12
+ spec.description = %q{WinkerAI is an AI approach to controlling Wink hub components by making use of the Winker gem and Wink API}
13
+ spec.homepage = "https://github.com/KellyMahan/WinkerAI"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_runtime_dependency 'sinatra'
24
+ spec.add_runtime_dependency 'winker'
25
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: WinkerAI
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.01
5
+ platform: ruby
6
+ authors:
7
+ - Kelly Mahan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sinatra
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: winker
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: WinkerAI is an AI approach to controlling Wink hub components by making
70
+ use of the Winker gem and Wink API
71
+ email:
72
+ - kmahan@kmahan.com
73
+ executables:
74
+ - winker_ai_start
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/winker_ai_start
84
+ - lib/winker_ai.rb
85
+ - lib/winker_ai/hash.rb
86
+ - lib/winker_ai/triggers.rb
87
+ - lib/winker_ai/version.rb
88
+ - winker_ai.gemspec
89
+ homepage: https://github.com/KellyMahan/WinkerAI
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.2.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: WinkerAI is an AI approach to controlling Wink hub components by making use
113
+ of the Winker gem and Wink API
114
+ test_files: []