lights 0.8.7 → 0.8.8

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjQwMmQ2OGY5NDlhZjE5MWZjMWY2YWE5MjFkYmYyMGM3ZGNjMGVkZg==
4
+ YTJiMjA2NzIxYTIyM2Q1NjM4NWJhY2MyNDI2OGQ4NmViOWFjMzQyZg==
5
5
  data.tar.gz: !binary |-
6
- OGRmODc0ZGJkYjE4ZjVlN2QwMzM1ZDBiMzEzYWM3ZjNmZmFhZGNmMA==
6
+ MDA2ZjJhNTBiMzdhMGNkMGNkYzVjNDI3OWQ2Yjk0OThmNGRhODEzZg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MDRlNzA1YTdhMTk1M2I5OWViZDY1NGYyYWIwNDZhZWRlOTExM2YwZTdlOTUy
10
- MDJmYmVjMjFkNGRlNjJhZDc2NjU1N2E1OTI5ZjNhZmViOWU3OWYzMDliNDNl
11
- MDhhNWEzZTI1ZjMxYTY0MWI2ZDk4ZDk5MDIzNThjNWQ0NDU3OGY=
9
+ ODJkYjA0ZTdiZDYzY2Q4YjRhNzg3YmMxMjE1MTUxMTAzYmMxMTc0M2NmODhm
10
+ MTc3NTRiZDJlNmE1ZGZmOTdjYTJhNTI0NmRhNTZjN2ZmZWYzODgyNTU2MThm
11
+ NDI1YTZjZWRiMDM3ODQ5ZmNjMWU0NDJjN2ZmMWY5M2YzMTdlZTE=
12
12
  data.tar.gz: !binary |-
13
- MzY0OTIyZDBkZmU0YzlkOTQxNzY4YjI0MGQzNzg5OWU3NDA1OGI5ZDI3ODU5
14
- ZTY0ZDdhNmZiNDhkNTVhOTk3YmQwZmVhMmE0MGMxYTY0MmIzOTIwNGZkMWUx
15
- NmRhZjdmZmJkYjU1YmUwMDgyYTZjYjBiMzc0ZjA0NGZjY2I4N2U=
13
+ ZmJiMWIyOTBlOWFjNzk2OGZkOTQ2ZDc4YjU2YjE0NGUxMzdkZmM1ZGUwY2Iw
14
+ MzNiMjI2ZTk0MzZmOWFjZTVkMjIyMDRhZTg0MTU4YTk3ZGQ1NGY1N2RiODU1
15
+ ZmY0MTA0M2IzY2I1NDZkOWYxODIxYmZlNjc2YjE5YTI2MzI3NGQ=
data/bin/lights CHANGED
@@ -111,18 +111,23 @@ class LightsCli
111
111
 
112
112
  case type
113
113
  when "group"
114
- OptionParser.new do |opts|
115
- opts.on("-i", "--id <id>", String, "Group ID to delete") do |i|
116
- options[:id] = i
117
- end
118
- end.parse!
114
+ id = ARGV.shift
119
115
 
120
- if !options[:id]
116
+ if !id
121
117
  puts "Must specify group id."
122
118
  exit 1
123
119
  end
124
120
 
125
- hue.delete_group(options[:id])
121
+ hue.delete_group id
122
+ when "user"
123
+ id = ARGV.shift
124
+
125
+ if !id
126
+ puts "Must specify user id."
127
+ exit 1
128
+ end
129
+
130
+ hue.delete_user id
126
131
  when nil
127
132
  STDERR.puts "Must specify a type to delete."
128
133
  else
@@ -135,41 +140,70 @@ class LightsCli
135
140
  objects = []
136
141
  titles = []
137
142
  methods = []
138
- if !ARGV[0] || ARGV[0] == "lights"
143
+
144
+ options = {}
145
+ OptionParser.new do |opts|
146
+ opts.on("-j", "--json", "Print JSON response") do |j|
147
+ options[:json] = j
148
+ end
149
+ end.parse!
150
+
151
+ type = ARGV.shift
152
+ case type
153
+ when nil, "","lights"
139
154
  response = hue.request_bulb_list
140
155
  response.each{|id,value| objects << hue.request_bulb_info( id )}
141
156
  titles = ["ID","NAME"]
142
157
  methods = [:id,:name]
143
- elsif ARGV[0] == "sensors"
158
+ when "sensors"
144
159
  response = hue.request_sensor_list
145
160
  response.each { |id,value| objects << hue.request_sensor_info( id )}
146
161
  titles = ["ID","NAME"]
147
162
  methods = [:id,:name]
148
- elsif ARGV[0] == "groups"
163
+ when "groups"
149
164
  response = hue.request_group_list
150
165
  response.each {|id,value| objects << hue.request_group_info( id )}
151
166
  titles = ["ID","NAME","LIGHTS"]
152
167
  methods = [:id,:name,:lights]
153
- elsif ARGV[0] == "scenes"
168
+ when "scenes"
154
169
  response = hue.request_scene_list
155
170
  response.each {|id,value| objects << Scene.new(id,value)}
156
171
  titles = ["ID","NAME","LIGHTS"]
157
172
  methods = [:id,:name,:lights]
158
- elsif ARGV[0] == "users"
173
+ when "users"
159
174
  response = hue.request_config
160
175
  response["whitelist"].each {|id,value| objects << User.new(id,value)}
161
176
  titles = ["ID","NAME","CREATE DATE","LAST USE DATE"]
162
177
  methods = [:id,:name,:create_date,:last_use_date]
163
- elsif ARGV[0] == "rules"
178
+ when "rules"
164
179
  response = hue.request_rules
165
180
  response.each {|id,value| objects << Rule.new(id,value)}
166
181
  titles = ["ID","NAME"]
167
182
  methods = [:id,:name]
183
+ when "schedules"
184
+ response = hue.request_schedules
185
+ response.each {|id,value| objects << Schedule.new(id,value)}
186
+ titles = ["ID","NAME","TIME","SCENE","STATUS"]
187
+ methods = [:id,:name,:time,:scene,:status]
188
+ when "datastore"
189
+ response = hue.request_datastore
190
+ response["lights"].each {|id,value| objects << Bulb.new(id,value)}
191
+ response["groups"].each {|id,value| objects << Group.new(id,value)}
192
+ response["config"]["whitelist"].each {|id,value| objects << User.new(id,value)}
193
+ response["rules"].each {|id,value| objects << Rule.new(id,value)}
194
+ response["scenes"].each {|id,value| objects << Scene.new(id,value)}
195
+ response["schedules"].each {|id,value| objects << Schedule.new(id,value)}
196
+ titles = ["TYPE","ID","NAME"]
197
+ methods = [:class,:id,:name]
168
198
  else
169
- puts "Don't know how to list \"#{ARGV[0]}\""
199
+ puts "Don't know how to list \"#{type}\""
170
200
  return
171
201
  end
172
- SimpleTable.new.from_objects(objects,titles,methods).print_text
202
+ if options[:json]
203
+ jp response
204
+ else
205
+ puts SimpleTable.new.from_objects(objects,titles,methods).text
206
+ end
173
207
  end
174
208
 
175
209
  def register
@@ -0,0 +1,23 @@
1
+ class Command
2
+ attr_reader :address, :method, :body
3
+ def initialize(data = {})
4
+ @address = data["address"]
5
+ @body = data["body"]
6
+ @method = data["method"]
7
+ @data = data
8
+ end
9
+
10
+ def data
11
+ data = @data
12
+ data["address"] = @address if @address
13
+ data["body"] = @body if @body
14
+ data["method"] = @method if @method
15
+ data
16
+ end
17
+
18
+ def to_json
19
+ data.to_json
20
+ end
21
+ end
22
+
23
+
@@ -0,0 +1,31 @@
1
+ require 'lights/command'
2
+
3
+ class Schedule
4
+ attr_reader :id, :name, :time, :status
5
+ def initialize(id,data = {})
6
+ @id = id
7
+ @name = data["name"]
8
+ @time = data["time"]
9
+ @status = data["status"]
10
+ @command = Command.new(data["command"])
11
+ @data = data
12
+ end
13
+
14
+ def scene
15
+ @command.body["scene"]
16
+ end
17
+
18
+ def data
19
+ data = @data
20
+ data["name"] = @name if @name
21
+ data["time"] = @time if @time
22
+ data["status"] = @status if @status
23
+ data["command"] = @command.data if !@command.data.empty?
24
+ data
25
+ end
26
+
27
+ def to_json
28
+ data.to_json
29
+ end
30
+ end
31
+
@@ -1,3 +1,3 @@
1
1
  module LightsConst
2
- VERSION = "0.8.7"
2
+ VERSION = "0.8.8"
3
3
  end
data/lib/lights.rb CHANGED
@@ -12,6 +12,7 @@ require 'lights/sensor'
12
12
  require 'lights/scene'
13
13
  require 'lights/user'
14
14
  require 'lights/rule'
15
+ require 'lights/schedule'
15
16
  require 'lights/loggerconfig'
16
17
 
17
18
  def jp( s )
@@ -109,6 +110,14 @@ class Lights
109
110
  get "rules"
110
111
  end
111
112
 
113
+ def request_schedules
114
+ get "schedules"
115
+ end
116
+
117
+ def request_datastore
118
+ get ""
119
+ end
120
+
112
121
  def set_bulb_state( id, state )
113
122
  put "lights/#{id}/state", state
114
123
  end
@@ -124,8 +133,12 @@ class Lights
124
133
  def delete_group( id )
125
134
  delete "groups/#{id}"
126
135
  end
127
- private
128
136
 
137
+ def delete_user( username )
138
+ delete "config/whitelist/#{username}"
139
+ end
140
+
141
+ private
129
142
  def process_error(result)
130
143
  type = result["error"]["type"]
131
144
  case type
data/lights.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_runtime_dependency "simpletable", "~> 0.2.0"
22
+ s.add_runtime_dependency "simpletable", "~> 0.3.0"
23
23
 
24
24
  s.add_development_dependency "bundler", "~> 1.3"
25
25
  s.add_development_dependency "rake"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lights
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.7
4
+ version: 0.8.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brady Turner
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.0
19
+ version: 0.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.0
26
+ version: 0.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -111,11 +111,13 @@ files:
111
111
  - lib/lights/bridge.rb
112
112
  - lib/lights/bulb.rb
113
113
  - lib/lights/bulbstate.rb
114
+ - lib/lights/command.rb
114
115
  - lib/lights/exception.rb
115
116
  - lib/lights/group.rb
116
117
  - lib/lights/loggerconfig.rb
117
118
  - lib/lights/rule.rb
118
119
  - lib/lights/scene.rb
120
+ - lib/lights/schedule.rb
119
121
  - lib/lights/sensor.rb
120
122
  - lib/lights/user.rb
121
123
  - lib/lights/version.rb