tools

various tools I have been using throughout the years
Log | Files | Refs | README | LICENSE

light.rb (1771B)


      1 # frozen_string_literal: true
      2 
      3 module Hue
      4   module CLI
      5     module Commands
      6       class Light < Hue::CLI::Command
      7         attr_reader :bulb
      8 
      9         def execute(*args)
     10           arg = args.shift
     11           light_number = arg.to_i
     12 
     13           raise Hue::CLI::Error, "Not a valid light number: #{arg}" unless light_number.positive?
     14 
     15           @bulb = Hue::Bulb.new(bridge, light_number)
     16 
     17           if args.empty?
     18             bulb.print_state
     19           elsif available?(args.first)
     20             super
     21           else
     22             apply_alias(args.join(' '))
     23           end
     24         end
     25 
     26         protected
     27 
     28         def on(*_args)
     29           bulb.on
     30         end
     31 
     32         def off(*_args)
     33           bulb.off
     34         end
     35 
     36         def brightness(*args)
     37           bulb.brightness = args.first
     38         end
     39 
     40         def flash(*_args)
     41           bulb.flash
     42         end
     43 
     44         def blink(*_args)
     45           bulb.blink
     46         end
     47 
     48         def solid(*_args)
     49           bulb.solid
     50         end
     51 
     52         def color(*args)
     53           bulb.color = Colors.parse(*args)
     54         end
     55 
     56         def name(*args)
     57           bulb.name = args.join(' ')
     58         end
     59 
     60         def action(*args)
     61           bulb.effect = args.join
     62         end
     63 
     64         def effect(*args)
     65           bulb.effect = args.join
     66         end
     67 
     68         def colorloop(*_args)
     69           bulb.colorloop
     70         end
     71 
     72         def clear(*args)
     73           target = args.first
     74           bulb.clear_effect if target != 'action'
     75           bulb.solid if target != 'effect'
     76         end
     77 
     78         def dump(*_args)
     79           puts bulb.state.to_json
     80         end
     81 
     82         private
     83 
     84         def apply_alias(alias_name)
     85           state_alias = Processors::LightStateAlias.new(alias_name)
     86           bulb.state = state_alias.state
     87         end
     88       end
     89     end
     90   end
     91 end