xilight 0.1.5 → 0.1.6

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: 44464a51e814edd4efc2df5a1fbf336f8081faa936cc1a3a1e228bcdc6777ae7
4
- data.tar.gz: fd04dddea590e4f0fb860b57e5334bacf017f151245eb839e425fd1727d6ebe0
3
+ metadata.gz: 17fc14ee43f5badbb28219ee22a5cc54981034f74b63ecba76215fbba9d14158
4
+ data.tar.gz: a0237242c81acbe5d0c045c826193f4d1e22faf1c6e0d93e4ba234378dbc89b9
5
5
  SHA512:
6
- metadata.gz: d065ccb4e6aa4ff99984778525dd69f1b6fda9cf2d7f25e1de176d241b53fbcd846e8735588cb11634f8a9efb320d5374f280803a9c72ebdab27ca0928dfa07b
7
- data.tar.gz: 538d5da718744d16bd2690728a496cfd799fbee712ed97ec1166be6bde5deabf4a7b00e40b91cfeff47d3141e96f90038894d4450ee936e490903c8c0fba94b3
6
+ metadata.gz: f76ca3da153d8491281e68a1f0dcd3d67459a126bbfdfa92ef4b8439453273ac2c0a7cd4c8b58860796d0ca37c3dc014db941fb5067a9f563082662fc77f3996
7
+ data.tar.gz: 00597cf9aa48c2374e240d9563f996e1096931d05a9c4beb2b29e83842a6114c78717233ee9fbac25efbdfad86b35e737e8fce04c3e1af7fe419ac02b43efa2b
data/exe/yee CHANGED
@@ -20,14 +20,20 @@ module Xilight
20
20
  {}
21
21
  end
22
22
 
23
- def self.get_light(index, name=nil)
23
+ def self.get_light(index, name=nil, attempt: 0)
24
24
  lights = ::Xilight::CLI.config['yeelights']
25
25
  light_attribs = if name && name != ''
26
26
  lights.find{|l| l['name'].downcase.strip == name.downcase.strip }
27
27
  else
28
28
  lights[index.to_i]
29
29
  end
30
- ::Xilight::Yeelight.new(light_attribs.map{|k,v| [k.to_sym, v]}.to_h)
30
+ light = ::Xilight::Yeelight.new(light_attribs.map{|k,v| [k.to_sym, v]}.to_h)
31
+ unless light.available?
32
+ self.discover
33
+ get_light(index, name, attempt: 1) if attempt.zero?
34
+ else
35
+ light
36
+ end
31
37
  rescue
32
38
  puts "Couldn't find light with " + ((name && name != '') ? "name #{name}" : "ID #{index}")
33
39
  puts "Known lights:"
@@ -35,6 +41,14 @@ module Xilight
35
41
  exit(1)
36
42
  end
37
43
 
44
+ def self.discover
45
+ ::Xilight::CLI.config = {
46
+ 'yeelights' => ::Xilight::Yeelight.discover.each do |light|
47
+ light.instance_variables.map{|v| [v.to_s[1..-1], light.instance_variable_get(v)] }.to_h
48
+ end
49
+ }
50
+ end
51
+
38
52
  module Commands
39
53
  extend Dry::CLI::Registry
40
54
 
@@ -58,11 +72,7 @@ module Xilight
58
72
  ]
59
73
 
60
74
  def call(**)
61
- ::Xilight::CLI.config = {
62
- 'yeelights' => ::Xilight::Yeelight.discover.each do |light|
63
- light.instance_variables.map{|v| [v.to_s[1..-1], light.instance_variable_get(v)] }.to_h
64
- end
65
- }
75
+ ::Xilight::CLI.discover
66
76
  end
67
77
  end
68
78
 
@@ -135,6 +145,7 @@ module Xilight
135
145
  ]
136
146
 
137
147
  def call(brightness:, light: 0, name: nil, **)
148
+ binding.pry
138
149
  light =::Xilight::CLI.get_light(light, name)
139
150
  light.bright = brightness.to_i
140
151
  end
@@ -24,6 +24,22 @@ module Xilight
24
24
  @port = location[/(?!<:)\d+$/]
25
25
  end
26
26
 
27
+ def available?()
28
+ begin
29
+ Timeout::timeout(1) do
30
+ begin
31
+ s = TCPSocket.new(@host, @port)
32
+ s.close
33
+ return true
34
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
35
+ return false
36
+ end
37
+ end
38
+ rescue Timeout::Error
39
+ end
40
+ return false
41
+ end
42
+
27
43
  def request(cmd)
28
44
  begin
29
45
  Timeout.timeout(0.5) do
@@ -1,3 +1,3 @@
1
1
  module Xilight
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
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.5
4
+ version: 0.1.6
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-27 00:00:00.000000000 Z
11
+ date: 2020-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli