xilight 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17fc14ee43f5badbb28219ee22a5cc54981034f74b63ecba76215fbba9d14158
4
- data.tar.gz: a0237242c81acbe5d0c045c826193f4d1e22faf1c6e0d93e4ba234378dbc89b9
3
+ metadata.gz: 2ab05093b44f3a72e57dcfa63e649be1aa6bd5128b9eea259b2619c8accb50ba
4
+ data.tar.gz: d928c43a33666ccb9e572974e6a91594d9b9caf9ea50b05e9e6e2883f8b828a2
5
5
  SHA512:
6
- metadata.gz: f76ca3da153d8491281e68a1f0dcd3d67459a126bbfdfa92ef4b8439453273ac2c0a7cd4c8b58860796d0ca37c3dc014db941fb5067a9f563082662fc77f3996
7
- data.tar.gz: 00597cf9aa48c2374e240d9563f996e1096931d05a9c4beb2b29e83842a6114c78717233ee9fbac25efbdfad86b35e737e8fce04c3e1af7fe419ac02b43efa2b
6
+ metadata.gz: 5ef46150fb68761ea29b368507cb95c74b4cd86aa110b7fb659b043fede7afa9d5b77aa59c46c913f66b138145cffce38ed0c4579ad020818762e2f8506873b7
7
+ data.tar.gz: c0ba4f986549cd8fcb8961f24d04b2331746aecf27a8094dfc4119e978cbd73030c9b22f77dcc3d798ab2fd0bd2c325ecbf11dd245973ce255ff1deb660dc725
@@ -0,0 +1 @@
1
+ 2.7.0
data/exe/yee CHANGED
@@ -20,6 +20,14 @@ module Xilight
20
20
  {}
21
21
  end
22
22
 
23
+ def self.rgb_to_hex(r,g,b)
24
+ [r,g,b].map{|x| x.to_i.to_s(16).rjust(2, '0') }.join
25
+ end
26
+
27
+ def self.rgb_to_i(r,g,b)
28
+ rgb_to_hex(r,g,b).to_i(16)
29
+ end
30
+
23
31
  def self.get_light(index, name=nil, attempt: 0)
24
32
  lights = ::Xilight::CLI.config['yeelights']
25
33
  light_attribs = if name && name != ''
@@ -27,7 +35,7 @@ module Xilight
27
35
  else
28
36
  lights[index.to_i]
29
37
  end
30
- light = ::Xilight::Yeelight.new(light_attribs.map{|k,v| [k.to_sym, v]}.to_h)
38
+ light = ::Xilight::Yeelight.new(**light_attribs.map{|k,v| [k.to_sym, v]}.to_h)
31
39
  unless light.available?
32
40
  self.discover
33
41
  get_light(index, name, attempt: 1) if attempt.zero?
@@ -108,8 +116,7 @@ module Xilight
108
116
 
109
117
  def call(r:, g:, b:, light: 0, name: nil, **)
110
118
  light =::Xilight::CLI.get_light(light, name)
111
- as_hex = [r,g,b].map{|x| x.to_i.to_s(16).rjust(2, '0') }.join
112
- light.rgb = as_hex.to_i(16)
119
+ light.rgb = ::Xilight::CLI.rgb_to_i(r,g,b)
113
120
  end
114
121
  end
115
122
 
@@ -145,7 +152,6 @@ module Xilight
145
152
  ]
146
153
 
147
154
  def call(brightness:, light: 0, name: nil, **)
148
- binding.pry
149
155
  light =::Xilight::CLI.get_light(light, name)
150
156
  light.bright = brightness.to_i
151
157
  end
@@ -219,6 +225,44 @@ module Xilight
219
225
  end
220
226
  end
221
227
 
228
+ module ColorFlow
229
+ class On < Dry::CLI::Command
230
+ desc "Start ColorFlow"
231
+ option :light, desc: "ID/index of Yeelight to target", default: "0", aliases: ["-l"]
232
+ option :name, desc: "Name of Yeelight to target", default: nil, aliases: ["-n"]
233
+
234
+ example [
235
+ "on # start color flow on default/first light",
236
+ "on -n kitchen # start color flow on light with name 'kitchen'",
237
+ "on -l 3 # start color flow on light #3"
238
+ ]
239
+ def call(light: 0, name: nil, **)
240
+ light =::Xilight::CLI.get_light(light, name)
241
+ flow_expression = COLORS.values.first(12).each_slice(2).map(&:first).map do |(r,g,b)|
242
+ "1000,2,#{::Xilight::CLI.rgb_to_i(r,g,b)},100"
243
+ end.join(',')
244
+ light.start_cf(0, 1, flow_expression)
245
+ end
246
+ end
247
+
248
+ class Off < Dry::CLI::Command
249
+ desc "Stop ColorFlow"
250
+ option :light, desc: "ID/index of Yeelight to target", default: "0", aliases: ["-l"]
251
+ option :name, desc: "Name of Yeelight to target", default: nil, aliases: ["-n"]
252
+
253
+ example [
254
+ "off # start color flow on default/first light",
255
+ "off -n kitchen # start color flow on light with name 'kitchen'",
256
+ "off -l 3 # start color flow on light #3"
257
+ ]
258
+
259
+ def call(light: 0, name: nil, **)
260
+ light =::Xilight::CLI.get_light(light, name)
261
+ light.power = 'off'
262
+ end
263
+ end
264
+ end
265
+
222
266
  COLORS = {
223
267
  red: [255, 0, 0],
224
268
  orange: [255, 128, 0],
@@ -262,6 +306,11 @@ module Xilight
262
306
  end
263
307
  end
264
308
 
309
+ register "color_flow", aliases: ["cf"] do |prefix|
310
+ prefix.register "on", ColorFlow::On, aliases: ["o"]
311
+ prefix.register "off", ColorFlow::Off, aliases: ["x"]
312
+ end
313
+
265
314
  register "version", Version, aliases: ["v", "-v", "--version"]
266
315
  register "discover", Discover, aliases: ["d"]
267
316
  register "rgb", Rgb
@@ -126,8 +126,8 @@ module Xilight
126
126
  # This method is used to start a color flow. Color flow is a series of smart
127
127
  # LED visible state changes. It can be either brightness changing, color changing
128
128
  # or color temperature changing
129
- def start_cf(count, action, flow_expression)
130
- request({id: 9,method: 'set_power', params: [count,action,flow_expression]})
129
+ def start_cf(count=0, action=1, flow_expression="1000,2,2700,100,500,1,255,10,5000,7,0,0,500,2,5000,1")
130
+ request({id: 9, method: 'start_cf', params: [count,action,flow_expression]})
131
131
  end
132
132
 
133
133
  # This method is used to stop a running color flow.
@@ -1,3 +1,3 @@
1
1
  module Xilight
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xilight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wouter Coppieters
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-30 00:00:00.000000000 Z
11
+ date: 2020-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -89,6 +89,7 @@ extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
91
  - ".gitignore"
92
+ - ".ruby-version"
92
93
  - CODE_OF_CONDUCT.md
93
94
  - Gemfile
94
95
  - README.md
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  - !ruby/object:Gem::Version
118
119
  version: '0'
119
120
  requirements: []
120
- rubygems_version: 3.1.4
121
+ rubygems_version: 3.1.2
121
122
  signing_key:
122
123
  specification_version: 4
123
124
  summary: Ruby Xiaomi Yeelight gem