bin/milight in milight-v6-0.1.1 vs bin/milight in milight-v6-0.2.0
- old
+ new
@@ -1,32 +1,47 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require "milight/v6"
-if ARGV.length < 2
- puts "Usage: #{$PROGRAM_NAME} <host> <command> [zone]"
- exit 1
-end
-
host = ARGV.shift
-command = ARGV.shift
-zone = ARGV.shift
-controller = Milight::V6::Controller.new(host)
+if host == "search"
+ controllers = Milight::V6::Controller.search
-if zone.nil?
- lights = controller.all
+ if !controllers.empty?
+ controllers.each { |c| puts c.to_s }
+ else
+ puts "No Mi-Light devices found."
+ end
else
- lights = controller.zone(zone.to_i)
-end
+ if ARGV.empty?
+ puts "Usage: #{$PROGRAM_NAME} <host> <command> [zone]"
+ puts " #{$PROGRAM_NAME} search"
+ exit 1
+ end
-case command
-when "link"
- lights.link
-when "unlink"
- lights.unlink
-when "off"
- lights.off
-when "on"
- lights.on
+ command = ARGV.shift
+ zone = ARGV.shift
+
+ controller = Milight::V6::Controller.new(host)
+
+ case zone
+ when nil
+ lights = controller.all
+ when "bridge"
+ lights = controller.bridge
+ else
+ lights = controller.zone(zone.to_i)
+ end
+
+ case command
+ when "link"
+ lights.link
+ when "unlink"
+ lights.unlink
+ when "off"
+ lights.off
+ when "on"
+ lights.on
+ end
end