Skip to content

Commit

Permalink
add delay to wait fpr multiple lamps #2
Browse files Browse the repository at this point in the history
  • Loading branch information
stroebjo committed May 26, 2014
1 parent 9ae1e68 commit 6d094ac
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
3 changes: 3 additions & 0 deletions workflow/lifx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

begin
client.discover!

sleep 1

rescue LIFX::Client::DiscoveryTimeout => e
$stderr.puts("Could not find any LIFX bulbs.")

Expand Down
23 changes: 22 additions & 1 deletion workflow/lifx_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,28 @@
Alfred.with_friendly_error do |alfred|

client = LIFX::Client.lan
client.discover! { |c| c.lights.count >= 1 }
#client.discover! { |c| c.lights.count >= 1 }

begin
client.discover!

sleep 1

rescue LIFX::Client::DiscoveryTimeout => e
$stderr.puts("Could not find any LIFX bulbs.")

# no bulbs found
fb.add_item({
:uid => "no-lifx",
:title => "Could not find any LIFX bulbs.",
:subtitle => e,
:valid => "no",
})

puts fb.to_xml(ARGV)

exit 1
end


case ARGV[0]
Expand Down
1 change: 1 addition & 0 deletions workflow/lifxc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def is_valid_color(color)

begin
client.discover!
sleep 1
rescue LIFX::Client::DiscoveryTimeout => e
$stderr.puts("Could not find any LIFX bulbs.")

Expand Down
27 changes: 26 additions & 1 deletion workflow/lifxc_run.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Alfred.with_friendly_error do |alfred|

client = LIFX::Client.lan
client.discover! { |c| c.lights.count >= 1 }
#client.discover! { |c| c.lights.count >= 1 }


arguments = ARGV[0].split # if a split pattern is omitted, whitespaces are the default
Expand All @@ -23,11 +23,36 @@

case bulb
when "all"

begin
client.discover!
sleep 1
rescue LIFX::Client::DiscoveryTimeout => e
$stderr.puts("Could not find any LIFX bulbs.")

# no bulbs found
fb.add_item({
:uid => "no-lifx",
:title => "Could not find any LIFX bulbs.",
:subtitle => e,
:valid => "no",
})

puts fb.to_xml(ARGV)

exit 1
end

client.lights.each do |c|
color = LIFX::Color.random_color
c.set_color(color)
end
else

client.discover! do |c| # Discover lights. Blocks until a light with the label 'Office' is found
c.lights.with_label(bulb)
end

if c = client.lights.with_label(bulb)

if c.off?
Expand Down

0 comments on commit 6d094ac

Please sign in to comment.