Class: Ewelink::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/ewelink/runner.rb

Instance Method Summary collapse

Instance Method Details

#runObject



5
6
7
8
9
10
11
12
13
# File 'lib/ewelink/runner.rb', line 5

def run
  api = Api.new(**options.slice(:email, :password, :phone_number))
  puts(JSON.pretty_generate(api.switches)) if options[:list_switches]
  puts(JSON.pretty_generate(api.rf_bridge_buttons)) if options[:list_rf_bridge_buttons]
  options[:turn_switches_on_uuids].each { |uuid| api.turn_switch!(uuid, :on) }
  options[:turn_switches_off_uuids].each { |uuid| api.turn_switch!(uuid, :off) }
  options[:press_rf_bridge_buttons_uuids].each { |uuid| api.press_rf_bridge_button!(uuid) }
  puts(JSON.pretty_generate(options[:switch_status_uuids].to_h { |uuid| [uuid, api.switch_on?(uuid) ? 'on' : 'off'] })) if options[:switch_status_uuids].present?
end