hue-cli 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/Gemfile +3 -0
- data/README.md +117 -0
- data/Rakefile +19 -0
- data/bin/hue +5 -0
- data/hue-cli.gemspec +25 -0
- data/lib/hue/cli/command.rb +58 -0
- data/lib/hue/cli/commands/light.rb +60 -0
- data/lib/hue/cli/commands/register.rb +37 -0
- data/lib/hue/cli.rb +73 -0
- data/lib/hue/extensions/bridge.rb +21 -0
- data/lib/hue/extensions/bulb.rb +16 -0
- data/lib/hue/extensions/hue.rb +5 -0
- metadata +142 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
hue-cli
|
2
|
+
=======
|
3
|
+
|
4
|
+
Command Line Interface to the Philips Hue lighting system.
|
5
|
+
|
6
|
+
# Installation
|
7
|
+
To begin using, install the ruby gem (this requires ruby 1.9 and rubygems)
|
8
|
+
|
9
|
+
```
|
10
|
+
$ gem install hue-cli
|
11
|
+
```
|
12
|
+
|
13
|
+
# Usage
|
14
|
+
|
15
|
+
This install the hue command. Simply type
|
16
|
+
|
17
|
+
```
|
18
|
+
$ hue
|
19
|
+
```
|
20
|
+
|
21
|
+
and the bridge state will be verified. Follow the instructions to register the application with your bridge.
|
22
|
+
|
23
|
+
## Register
|
24
|
+
|
25
|
+
You can explicity register the application with
|
26
|
+
|
27
|
+
```
|
28
|
+
$ hue register
|
29
|
+
```
|
30
|
+
|
31
|
+
## Bridge state
|
32
|
+
|
33
|
+
Examine the current state of the bridge
|
34
|
+
|
35
|
+
```
|
36
|
+
$ hue
|
37
|
+
Philips Hue
|
38
|
+
IP: 196.168.0.1
|
39
|
+
Button pressed: false
|
40
|
+
Applications:
|
41
|
+
073f2ed95fcbbef2532c751dd404cc9d : hue-cli
|
42
|
+
Lights:
|
43
|
+
1. Living Overhead - OFF
|
44
|
+
2. Living Cabinet - OFF
|
45
|
+
3. Living Corner Lamp - OFF
|
46
|
+
```
|
47
|
+
|
48
|
+
## Light state
|
49
|
+
|
50
|
+
Examine the state of one of the lights
|
51
|
+
|
52
|
+
```
|
53
|
+
$ hue lights 1
|
54
|
+
```
|
55
|
+
|
56
|
+
or just
|
57
|
+
|
58
|
+
```
|
59
|
+
$ hue 1
|
60
|
+
Living Overhead: ON
|
61
|
+
Brightness: 254 (100%)
|
62
|
+
Color: Temperature=2012°K (497 mired), RGB≈[255, 136, 13]
|
63
|
+
```
|
64
|
+
|
65
|
+
## Change Light state
|
66
|
+
|
67
|
+
Change a single lights state with the follow (rather self-explanatory) commands
|
68
|
+
|
69
|
+
```
|
70
|
+
$ hue 1 on
|
71
|
+
$ hue 1 off
|
72
|
+
$ hue 1 flash
|
73
|
+
$ hue 1 blink
|
74
|
+
$ hue 1 solid
|
75
|
+
```
|
76
|
+
|
77
|
+
### Light brightness
|
78
|
+
|
79
|
+
The lights brightness command takes a value (0-255) or percentage (0%-100%)
|
80
|
+
```
|
81
|
+
$ hue 1 brightness 200
|
82
|
+
$ hue 1 brightness 50%
|
83
|
+
$ hue 1
|
84
|
+
Living Overhead: ON
|
85
|
+
Brightness: 128 (50%)
|
86
|
+
Color: Temperature=2012°K (497 mired), RGB≈[255, 136, 13]
|
87
|
+
```
|
88
|
+
|
89
|
+
### Light color
|
90
|
+
|
91
|
+
The lights color command takes 1-3 arguments, each interpreted depending on range and value.
|
92
|
+
|
93
|
+
```
|
94
|
+
$ hue 1 color 6500
|
95
|
+
$ hue 1
|
96
|
+
Living Overhead: ON
|
97
|
+
Brightness: 128 (50%)
|
98
|
+
Color: Temperature=6500°K (153 mired), RGB≈[255, 254, 250]
|
99
|
+
```
|
100
|
+
|
101
|
+
```
|
102
|
+
$ hue 1 color 240
|
103
|
+
$ hue 1
|
104
|
+
Living Overhead: ON
|
105
|
+
Brightness: 128 (50%)
|
106
|
+
Color: Temperature=4167°K (240 mired), RGB≈[255, 208, 170]
|
107
|
+
```
|
108
|
+
|
109
|
+
```
|
110
|
+
$ hue 1 color 30000 255
|
111
|
+
$ hue 1
|
112
|
+
Living Overhead: ON
|
113
|
+
Brightness: 128 (50%)
|
114
|
+
Color: Hue=30000, Saturation=255, RGB≈[0, 255, 190]
|
115
|
+
```
|
116
|
+
|
117
|
+
## More coming...
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new('spec') do |t|
|
7
|
+
t.rspec_opts = ["-fd", "-c"]
|
8
|
+
t.ruby_opts = ["-Ispec,lib"]
|
9
|
+
t.pattern = 'spec/**/*_spec.rb'
|
10
|
+
end
|
11
|
+
|
12
|
+
rescue LoadError
|
13
|
+
desc 'Spec rake task not available'
|
14
|
+
task :spec do
|
15
|
+
abort 'Spec rake task is not available. Be sure to install rspec as a gem or plugin'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
task :default => [:spec]
|
data/bin/hue
ADDED
data/hue-cli.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "hue-cli"
|
6
|
+
s.version = '0.1.0'
|
7
|
+
s.authors = ["Birkir A. Barkarson", ""]
|
8
|
+
s.email = ["birkirb@stoicviking.net"]
|
9
|
+
s.homepage = "https://github.com/birkirb/hue-lib"
|
10
|
+
s.summary = %q{Command line interface for controlling Philips Hue system's lights and bridge.}
|
11
|
+
s.description = %q{CLI that allows simple printing of bridge and light state, with easy-to-use syntax to manipulate state}
|
12
|
+
|
13
|
+
s.rubyforge_project = "hue-cli"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_runtime_dependency("json")
|
21
|
+
s.add_runtime_dependency("hue-lib", '>= 0.7.0')
|
22
|
+
s.add_development_dependency("rspec", '>= 2.6.0')
|
23
|
+
s.add_development_dependency("mocha", '>= 0.9.0')
|
24
|
+
s.add_development_dependency("webmock", '>= 1.8.0')
|
25
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Hue
|
2
|
+
module CLI
|
3
|
+
class Command
|
4
|
+
|
5
|
+
public
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
set_bridge
|
9
|
+
parse_methods
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute(*args)
|
13
|
+
if args.size > 0
|
14
|
+
send_method(*args)
|
15
|
+
else
|
16
|
+
@bridge.print_state
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :bridge
|
23
|
+
|
24
|
+
def is_available?(method_name)
|
25
|
+
@methods[method_name.to_sym]
|
26
|
+
end
|
27
|
+
|
28
|
+
def is_available!(method_name)
|
29
|
+
is_available?(method_name) or
|
30
|
+
raise Error.new("Action '#{method_name.to_s}' is not available for operation '#{name}'")
|
31
|
+
end
|
32
|
+
|
33
|
+
def name
|
34
|
+
self.class.name.gsub(/.*\:\:/, '').downcase
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_bridge
|
38
|
+
@bridge = Hue::CLI.bridge
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse_methods
|
42
|
+
@methods = self.class.instance_methods(false).inject(Hash.new(false)) do |hash, method_name|
|
43
|
+
hash[method_name] = true
|
44
|
+
hash
|
45
|
+
end
|
46
|
+
@methods[:execute] = false
|
47
|
+
end
|
48
|
+
|
49
|
+
def send_method(*args)
|
50
|
+
method = args.shift.to_sym
|
51
|
+
if is_available!(method)
|
52
|
+
send(method, *args)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Hue
|
2
|
+
module CLI
|
3
|
+
module Commands
|
4
|
+
class Light < Hue::CLI::Command
|
5
|
+
|
6
|
+
attr_reader :bulb
|
7
|
+
|
8
|
+
def execute(*args)
|
9
|
+
arg = args.shift
|
10
|
+
light_number = arg.to_i
|
11
|
+
|
12
|
+
if light_number > 0
|
13
|
+
@bulb = Hue::Bulb.new(bridge, light_number)
|
14
|
+
else
|
15
|
+
raise Hue::CLI::Error.new("Not a valid light number: #{arg}")
|
16
|
+
end
|
17
|
+
|
18
|
+
# bulb exists (is valid?)
|
19
|
+
|
20
|
+
if args.size > 0
|
21
|
+
super(*args)
|
22
|
+
else
|
23
|
+
bulb.print_state
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def on(*args)
|
30
|
+
bulb.on
|
31
|
+
end
|
32
|
+
|
33
|
+
def off(*args)
|
34
|
+
bulb.off
|
35
|
+
end
|
36
|
+
|
37
|
+
def brightness(*args)
|
38
|
+
bulb.brightness = args.first
|
39
|
+
end
|
40
|
+
|
41
|
+
def flash(*args)
|
42
|
+
bulb.flash
|
43
|
+
end
|
44
|
+
|
45
|
+
def blink(*args)
|
46
|
+
bulb.blink
|
47
|
+
end
|
48
|
+
|
49
|
+
def solid(*args)
|
50
|
+
bulb.solid
|
51
|
+
end
|
52
|
+
|
53
|
+
def color(*args)
|
54
|
+
bulb.color = Colors.parse(*args)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Hue
|
2
|
+
module CLI
|
3
|
+
module Commands
|
4
|
+
class Register < Hue::CLI::Command
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
parse_methods
|
8
|
+
end
|
9
|
+
|
10
|
+
def execute(*args)
|
11
|
+
if args.size > 0
|
12
|
+
super(*args)
|
13
|
+
else
|
14
|
+
default
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def default(*args)
|
21
|
+
print_button_instructions
|
22
|
+
Hue.register_default
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def print_button_instructions
|
28
|
+
puts "Please press the button on your bridge."
|
29
|
+
sleep 1
|
30
|
+
puts "Once done, press Enter to continue with the registration."
|
31
|
+
gets
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/hue/cli.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'hue'
|
2
|
+
require 'find'
|
3
|
+
require_relative 'cli/command'
|
4
|
+
require_relative 'extensions/bulb'
|
5
|
+
require_relative 'extensions/bridge'
|
6
|
+
require_relative 'extensions/hue'
|
7
|
+
|
8
|
+
module Hue
|
9
|
+
module CLI
|
10
|
+
class Error < StandardError; end;
|
11
|
+
|
12
|
+
def self.bridge
|
13
|
+
Hue.application
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.run(args = [])
|
17
|
+
commands = commands_in_object_space
|
18
|
+
|
19
|
+
if args.size > 0
|
20
|
+
first_arg = args.shift
|
21
|
+
if command = commands[first_arg.to_sym]
|
22
|
+
command.new.execute(*args)
|
23
|
+
else
|
24
|
+
Commands::Light.new.execute(first_arg, *args)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
print_default
|
28
|
+
end
|
29
|
+
rescue Hue::Error => err
|
30
|
+
puts err.message
|
31
|
+
rescue Hue::CLI::Error => err
|
32
|
+
puts err.message
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def self.print_default
|
38
|
+
Command.new.execute
|
39
|
+
rescue Hue::Error => err
|
40
|
+
puts "Failed to initialize bridge."
|
41
|
+
if bridges = Hue.register_bridges
|
42
|
+
puts "Found bridges:"
|
43
|
+
bridges.each do |key, config|
|
44
|
+
puts " #{config.uri} (uuid: #{key})"
|
45
|
+
end
|
46
|
+
puts
|
47
|
+
puts "Please type 'hue register' to register your application with the bridge."
|
48
|
+
else
|
49
|
+
puts "No bridges found on the local network."
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.commands_in_object_space
|
54
|
+
require_commands
|
55
|
+
commands = Hash.new
|
56
|
+
::ObjectSpace.each_object(Class) do |klass|
|
57
|
+
if(Hue::CLI::Command > klass)
|
58
|
+
commands[klass.name.gsub(/.*\:\:/, '').downcase.to_sym] = klass
|
59
|
+
end
|
60
|
+
end
|
61
|
+
commands
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.require_commands
|
65
|
+
Find.find(File.join(File.dirname(__FILE__), 'cli', 'commands')) do |path|
|
66
|
+
if File.file?(path) && path.match(/\.rb$/)
|
67
|
+
require path
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Hue
|
2
|
+
class Bridge
|
3
|
+
|
4
|
+
def print_state
|
5
|
+
state = self.status
|
6
|
+
config = state['config']
|
7
|
+
puts "#{config['name']}"
|
8
|
+
puts "IP: #{config['ipaddress']}"
|
9
|
+
puts "Button pressed: #{config['linkbutton']}"
|
10
|
+
puts "Applications:"
|
11
|
+
config['whitelist'].each do |key, values|
|
12
|
+
puts " #{key} : #{values['name']}"
|
13
|
+
end
|
14
|
+
puts "Lights:"
|
15
|
+
state['lights'].each do |key, values|
|
16
|
+
puts " #{key}. #{values['name']} - #{values['state']['on'] ? 'ON' : 'OFF'}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Hue
|
2
|
+
class Bulb
|
3
|
+
|
4
|
+
def print_state
|
5
|
+
puts "#{self.name}: #{self.on? ? 'ON' : 'OFF'}"
|
6
|
+
puts "Brightness: #{self.brightness} (#{(self.brightness_percent).to_i}%)"
|
7
|
+
print "Color: "
|
8
|
+
print self.color.to_s
|
9
|
+
puts ", #{self.color.to_rgb.to_s}"
|
10
|
+
if blinking?
|
11
|
+
puts "Alert: Blinking!"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hue-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Birkir A. Barkarson
|
9
|
+
- ''
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-02-04 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: hue-lib
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 0.7.0
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.7.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.6.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.6.0
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: mocha
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 0.9.0
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.9.0
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: webmock
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 1.8.0
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.8.0
|
95
|
+
description: CLI that allows simple printing of bridge and light state, with easy-to-use
|
96
|
+
syntax to manipulate state
|
97
|
+
email:
|
98
|
+
- birkirb@stoicviking.net
|
99
|
+
executables:
|
100
|
+
- hue
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- Gemfile
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- bin/hue
|
109
|
+
- hue-cli.gemspec
|
110
|
+
- lib/hue/cli.rb
|
111
|
+
- lib/hue/cli/command.rb
|
112
|
+
- lib/hue/cli/commands/light.rb
|
113
|
+
- lib/hue/cli/commands/register.rb
|
114
|
+
- lib/hue/extensions/bridge.rb
|
115
|
+
- lib/hue/extensions/bulb.rb
|
116
|
+
- lib/hue/extensions/hue.rb
|
117
|
+
homepage: https://github.com/birkirb/hue-lib
|
118
|
+
licenses: []
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project: hue-cli
|
137
|
+
rubygems_version: 1.8.23
|
138
|
+
signing_key:
|
139
|
+
specification_version: 3
|
140
|
+
summary: Command line interface for controlling Philips Hue system's lights and bridge.
|
141
|
+
test_files: []
|
142
|
+
has_rdoc:
|