Sha256: 358cf4a3ce99b11da44b299969ce6e73451fb08b4128b2a3ce27c5106c9692f7

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true
require 'optparse'
require 'rg_refresh'
require 'yaml'

opts = {}
optparser = OptionParser.new do |cmd|
  cmd.banner = "usage: #$0 [options]"

  cmd.on('-c FILE', '--config=FILE', 'Configuration file') do |v|
    opts[:config_file] = v
  end
end

begin
  optparser.parse!
rescue OptionParser::InvalidOption=>e
  $stderr.puts e

  abort optparser.help
end

abort optparser.help \
  unless opts[:config_file] && ARGV.empty?

config = YAML.load(File.read(opts[:config_file]), :symbolize_names=>true)

begin
  puts 'Connecting...'
  $netgear = RgRefresh::Netgear.start(config.fetch(:netgear))
  $rg = RgRefresh::PublishWrapper.new(config.fetch(:mqtt))

  puts 'Affirming bypass mode (manually power RG *OFF* if necessary)...'
  $netgear.transition_to(:bypass)
  sleep 15
  $rg.transition_to(:bypass)
  sleep 15

  puts 'Transitioning to re-auth mode (manually power RG *ON* if necessary)...'
  $rg.transition_to(:reauth)
  $netgear.transition_to(:reauth) # point of no return

  puts 'Waiting for re-auth...'
  sleep 240

  puts 'Transitioning to bypass mode (manually power RG *OFF* if necessary)...'
  $netgear.transition_to(:bypass)
  sleep 15
  $rg.transition_to(:bypass)
  sleep 15
ensure
  puts 'Disconnecting...'
  $rg.finish
  $netgear.finish
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rg_refresh-0.1.2 exe/rg_refresh