lights 0.8.3 → 0.8.4
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 +8 -8
- data/bin/lights +68 -2
- data/lib/lights.rb +25 -0
- data/lib/lights/group.rb +15 -1
- data/lib/lights/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzUzMjA0NzFlODMzNmZjODIyZGZlNTQ2NTI3Y2QxNWQ5MjhhZmQ0OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzgxNTIyZGNkODQxOTJhOTI4NDdmZDAzM2VhMzY1MDFmYjhkMGFhMw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDMwNzQ0OGUxZTBjYjY1NjY2MWU3Yjg2YWNhMmExYmM1MGIzMWIyZGI3OThl
|
10
|
+
OWM1MWExYzA1YTVlNTE3NGYzN2MzYzA3MmQwNjAxMTg3YTQzOWFlMjUxMjNm
|
11
|
+
YmFlMzUyYWJmMDk2ZTFmM2QxYmY5OGQ5ZGE3NWZjYWUyZGIzZDA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDRjMjE0NmE2MDVlODVkYTJmNmNhZDc3NzQ5OTkxNmQ4MGRlZWQyMzNlNGVl
|
14
|
+
YmUzOTYyMjMxZDVjOTBlNzFkZGEzMGM3OGU2MjY1YTUxMzk1YjQzZDVhYmY4
|
15
|
+
ZjA0ZGRlZTRmY2JiOGI2MmI4MjI5NzY0OThiYjRkZWYxYjk4NWQ=
|
data/bin/lights
CHANGED
@@ -66,7 +66,69 @@ class LightsCli
|
|
66
66
|
puts "Configuration settings saved."
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
|
+
def create
|
71
|
+
type = ARGV.shift
|
72
|
+
hue = Lights.new @config["bridge_ip"], @config["username"]
|
73
|
+
options = {}
|
74
|
+
|
75
|
+
case type
|
76
|
+
when "group"
|
77
|
+
OptionParser.new do |opts|
|
78
|
+
opts.on("-l", "--lights 1,2,...N", Array, "Which lights to put in group") do |l|
|
79
|
+
options[:lights] = l
|
80
|
+
end
|
81
|
+
opts.on("-n", "--name <name>", String, "Set group name") do |n|
|
82
|
+
options[:name] = n
|
83
|
+
end
|
84
|
+
end.parse!
|
85
|
+
|
86
|
+
if !options[:lights]
|
87
|
+
puts "Must specify which lights to group."
|
88
|
+
exit 1
|
89
|
+
end
|
90
|
+
if !options[:name]
|
91
|
+
puts "Must specify group name."
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
|
95
|
+
group = Group.new
|
96
|
+
group.name = options[:name]
|
97
|
+
group.lights = options[:lights]
|
98
|
+
hue.create_group(group)
|
99
|
+
when nil
|
100
|
+
STDERR.puts "Must specify a type to create."
|
101
|
+
else
|
102
|
+
STDERR.puts "Don't know how to create type \"#{type}\"."
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def delete
|
107
|
+
type = ARGV.shift
|
108
|
+
hue = Lights.new @config["bridge_ip"], @config["username"]
|
109
|
+
options = {}
|
110
|
+
|
111
|
+
case type
|
112
|
+
when "group"
|
113
|
+
OptionParser.new do |opts|
|
114
|
+
opts.on("-i", "--id <id>", String, "Group ID to delete") do |i|
|
115
|
+
options[:id] = i
|
116
|
+
end
|
117
|
+
end.parse!
|
118
|
+
|
119
|
+
if !options[:id]
|
120
|
+
puts "Must specify group id."
|
121
|
+
exit 1
|
122
|
+
end
|
123
|
+
|
124
|
+
hue.delete_group(options[:id])
|
125
|
+
when nil
|
126
|
+
STDERR.puts "Must specify a type to delete."
|
127
|
+
else
|
128
|
+
STDERR.puts "Don't know how to delete type \"#{type}\"."
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
70
132
|
def list
|
71
133
|
hue = Lights.new @config["bridge_ip"], @config["username"]
|
72
134
|
if !ARGV[0] || ARGV[0] == "lights"
|
@@ -348,7 +410,7 @@ end
|
|
348
410
|
|
349
411
|
|
350
412
|
if !ARGV[0]
|
351
|
-
STDERR.puts "Must specify a command. (config, list, register, discover, on, off, set)"
|
413
|
+
STDERR.puts "Must specify a command. (config, list, register, discover, on, off, set, create, delete)"
|
352
414
|
exit 1
|
353
415
|
end
|
354
416
|
|
@@ -371,6 +433,10 @@ begin
|
|
371
433
|
cli.off
|
372
434
|
elsif command == "set"
|
373
435
|
cli.set
|
436
|
+
elsif command == "create"
|
437
|
+
cli.create
|
438
|
+
elsif command == "delete"
|
439
|
+
cli.delete
|
374
440
|
else
|
375
441
|
puts "Cannot find command #{command}."
|
376
442
|
end
|
data/lib/lights.rb
CHANGED
@@ -112,6 +112,13 @@ class Lights
|
|
112
112
|
put "groups/#{id}/action", state
|
113
113
|
end
|
114
114
|
|
115
|
+
def create_group( group )
|
116
|
+
post "groups", group
|
117
|
+
end
|
118
|
+
|
119
|
+
def delete_group( id )
|
120
|
+
delete "groups/#{id}"
|
121
|
+
end
|
115
122
|
private
|
116
123
|
|
117
124
|
def process_error(result)
|
@@ -148,5 +155,23 @@ private
|
|
148
155
|
JSON.parse response.body
|
149
156
|
end
|
150
157
|
|
158
|
+
def post( path, data )
|
159
|
+
@logger.debug "==> POST: #{path}"
|
160
|
+
@logger.debug data.to_json
|
161
|
+
response = @http.post( "/api/#{@username}/#{path}", data.to_json )
|
162
|
+
@logger.debug "<== #{response.code}"
|
163
|
+
@logger.debug response.body
|
164
|
+
JSON.parse response.body
|
165
|
+
end
|
166
|
+
|
167
|
+
def delete( path )
|
168
|
+
@logger.debug "==> DELETE: #{path}"
|
169
|
+
request = Net::HTTP::Delete.new( "/api/#{@username}/#{path}" )
|
170
|
+
response = @http.request request
|
171
|
+
@logger.debug "<== #{response.code}"
|
172
|
+
@logger.debug response.body
|
173
|
+
JSON.parse response.body
|
174
|
+
end
|
175
|
+
|
151
176
|
end
|
152
177
|
|
data/lib/lights/group.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
class Group
|
2
2
|
|
3
3
|
attr_reader :id, :data, :name, :lights
|
4
|
-
|
4
|
+
attr_writer :name, :lights
|
5
|
+
def initialize( id = nil, data = {} )
|
5
6
|
@id = id
|
6
7
|
@data = data
|
7
8
|
@action = BulbState.new(data["action"])
|
@@ -13,4 +14,17 @@ class Group
|
|
13
14
|
@action.data
|
14
15
|
end
|
15
16
|
|
17
|
+
def data
|
18
|
+
data = @data
|
19
|
+
data["id"] = @id if @id
|
20
|
+
data["name"] = @name if @name
|
21
|
+
data["lights"] = @lights if @lights
|
22
|
+
data["action"] = @action.data if @action.data != {}
|
23
|
+
data
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_json
|
27
|
+
data.to_json
|
28
|
+
end
|
29
|
+
|
16
30
|
end
|
data/lib/lights/version.rb
CHANGED