lifx-console 0.2.0

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: 19a647825db39d37979e9b8b9acca85a954b6124
4
+ data.tar.gz: a7b50fb31b624c89aa8d73cf8fef867a1fcd44bc
5
+ SHA512:
6
+ metadata.gz: 0287e38c64d2688574e42ce25aa319544c03af1f1386ecfbd6ea2dfef57db3ad9780898dcb8d5d7c98d9e278c2c59496bc09b250c7a9baf2301cd18da7cd2456
7
+ data.tar.gz: 72a1fadb0fa1641c0a540b31b6873a67aa0bdebb3eba2ca51b5f9dac0c335ee3cb1e1835151ae07fd291bbb4c2f1abe793653ca551fa2e5adef9cb6b24df23a3
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lifx-console.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jack Chen (chendo)
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,36 @@
1
+ # LIFX Console
2
+
3
+ A [Pry](https://github.com/pry/pry)-enabled REPL to interact with [LIFX](http://lifx.co) devices.
4
+
5
+ ## Features
6
+
7
+ * Pry-enabled!
8
+ * Helpers to help you visually identify lights.
9
+
10
+ ## Installation
11
+
12
+ $ gem install lifx-console
13
+
14
+ ## Usage
15
+
16
+ ```bash
17
+ $ lifx-console
18
+ ```
19
+
20
+ Print the label of lights being visually identified
21
+ ```bash
22
+ [1] pry(#<LIFX::Client>)> while light = identify
23
+ [1] pry(#<LIFX::Client>)* puts light.label
24
+ [1] pry(#<LIFX::Client>)* end
25
+ ```
26
+ ## Contributing
27
+
28
+ 1. Fork it ( http://github.com/<my-github-username>/lifx-console/fork )
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
33
+
34
+ ## License
35
+
36
+ MIT. See `LICENSE.txt`
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "..", "lib")
3
+ require 'lifx/console'
4
+
5
+ LIFX::Config.allowed_transports = [:udp] if ENV["UDP_ONLY"]
6
+ LIFX::Console.start
@@ -0,0 +1,33 @@
1
+ require "pry"
2
+ require "lifx"
3
+ require "lifx/console/version"
4
+ require "lifx/console/identify"
5
+
6
+ module LIFX
7
+ class Console
8
+ class << self
9
+ def client
10
+ @client ||= LIFX::Client.lan.tap do |c|
11
+ c.extend(LIFX::Colors)
12
+ c.extend(Commands)
13
+ end
14
+ end
15
+
16
+ def start
17
+ begin
18
+ client.discover!
19
+ rescue LIFX::Client::DiscoveryTimeout
20
+ $stderr.puts("Could not find any LIFX devices.")
21
+ exit 1
22
+ end
23
+ client.pry
24
+ end
25
+ end
26
+
27
+ module Commands
28
+ def identify(candidates = lights)
29
+ Identify.new.run(candidates)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,80 @@
1
+ require 'abbrev'
2
+
3
+ module LIFX
4
+ class Console
5
+ class Identify
6
+ COLORS = {
7
+ 'red' => LIFX::Color.red.with_brightness(0.7),
8
+ 'green' => LIFX::Color.green.with_brightness(0.7),
9
+ 'blue' => LIFX::Color.blue.with_brightness(0.7),
10
+ 'yellow' => LIFX::Color.yellow.with_brightness(0.7),
11
+ 'purple' => LIFX::Color.purple.with_brightness(0.7),
12
+ }
13
+
14
+ def run(lights)
15
+ candidates = lights.to_a.shuffle
16
+ mapping = {}
17
+
18
+ if lights.respond_to?(:set_color)
19
+ lights.set_color(LIFX::Color.white, duration: 0)
20
+ else
21
+ lights.each { |l| l.set_color(LIFX::Color.white, duration: 0) }
22
+ end
23
+
24
+ while candidates.count > 1
25
+ puts "Searching through #{candidates.count} devices..."
26
+ partitions = partition(candidates, COLORS.values.count)
27
+ COLORS.keys.each_with_index do |color_name, index|
28
+ color = COLORS[color_name]
29
+ mapping[color_name] = partitions[index]
30
+ next if partitions[index].nil?
31
+ partitions[index].each do |l|
32
+ l.pulse(color, period: 10, duty_cycle: 1.0)
33
+ end
34
+ end
35
+ puts "What color did the light change to? (#{COLORS.keys.join(', ')}. Press enter to retry)"
36
+ resp = gets.strip
37
+ abbrev = Abbrev.abbrev(COLORS.keys)
38
+ if mapping.has_key?(abbrev[resp])
39
+ candidates = mapping[abbrev[resp]]
40
+ else
41
+ puts "Color not found. Pulsing again."
42
+ end
43
+ end
44
+
45
+ if candidates.count == 1
46
+ result = candidates.first
47
+ puts "Light identified: #{result}"
48
+ result.pulse(LIFX::Color.green, cycles: 3, period: 1)
49
+ return candidates.first
50
+ else
51
+ puts "No lights matched."
52
+ end
53
+ end
54
+
55
+ def partition(list, partition_count)
56
+ [].tap do |array|
57
+ list.each_slice((list.count.to_f / partition_count).ceil) do |chunk|
58
+ array << chunk
59
+ end
60
+ end
61
+ end
62
+
63
+ def client
64
+ LIFX::Console.client
65
+ end
66
+ end
67
+
68
+ Pry::Commands.create_command "identify", keep_retval: true, use_shellwords: false do
69
+ description "identify a light visually: identify [Array, LightCollection]"
70
+
71
+ def process
72
+ Identify.new.run(lights)
73
+ end
74
+
75
+ def lights
76
+ arg_string.length > 0 ? target.eval(arg_string) : target.eval('lights')
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,5 @@
1
+ module LIFX
2
+ class Console
3
+ VERSION = "0.2.0"
4
+ end
5
+ 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 'lifx/console/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lifx-console"
8
+ spec.version = LIFX::Console::VERSION
9
+ spec.authors = ["Jack Chen (chendo)"]
10
+ spec.email = ["gems+lifx-console@github.com"]
11
+ spec.summary = %q{Pry-enabled REPL for interacting with LIFX devices.}
12
+ spec.description = %q{Pry-enabled REPL for interacting with LIFX devices. Contains a bunch of useful utilities, like visual device identification.}
13
+ spec.homepage = "https://github.com/chendo/lifx-console"
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_dependency "lifx", "~> 0.4"
22
+ spec.add_dependency "pry", "~> 0.9"
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake", "~> 10.1"
25
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lifx-console
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Jack Chen (chendo)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lifx
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.1'
69
+ description: Pry-enabled REPL for interacting with LIFX devices. Contains a bunch
70
+ of useful utilities, like visual device identification.
71
+ email:
72
+ - gems+lifx-console@github.com
73
+ executables:
74
+ - lifx-console
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/lifx-console
84
+ - lib/lifx/console.rb
85
+ - lib/lifx/console/identify.rb
86
+ - lib/lifx/console/version.rb
87
+ - lifx-console.gemspec
88
+ homepage: https://github.com/chendo/lifx-console
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Pry-enabled REPL for interacting with LIFX devices.
112
+ test_files: []
113
+ has_rdoc: