class Agents::MyqAgent

Public Instance Methods

check() click to toggle source
# File lib/huginn_myq_agent/myq_agent.rb, line 48
def check
  door = select_door(interpolated['door_name'])
  if interpolated['action'] == 'status'
    create_event :payload => status(door)
  elsif interpolated['action'] == 'open'
    open_door(door)
    create_event :payload => status(door)
  elsif interpolated['action'] == 'close'
    close_door(door)
    create_event :payload => status(door)
  elsif interpolated['action'] == 'toggle'
    toggle_door(door)
    create_event :payload => status(door)
  end
end
complete_door_name() click to toggle source
# File lib/huginn_myq_agent/myq_agent.rb, line 43
def complete_door_name
  system = create_system
  system.garage_doors.map { |door| {id: door.name, text: door.name} }
end
default_options() click to toggle source
# File lib/huginn_myq_agent/myq_agent.rb, line 12
def default_options
  {
    'email_address' => '',
    'password' => '',
  }
end
validate_options() click to toggle source
# File lib/huginn_myq_agent/myq_agent.rb, line 24
def validate_options
  if options['email_address'].blank?
    errors.add(:base, 'email address is required')
  end
  if options['password'].blank?
    errors.add(:base, 'password is required')
  end
  if options['door_name'].blank?
    errors.add(:base, 'door_name is required')
  end
  if options['action'].blank?
    errors.add(:base, 'action is required')
  end
end
working?() click to toggle source
# File lib/huginn_myq_agent/myq_agent.rb, line 39
def working?
  !recent_error_logs?
end

Private Instance Methods

close_door(door) click to toggle source
# File lib/huginn_myq_agent/myq_agent.rb, line 83
def close_door(door)
  door.close
end
create_system() click to toggle source
# File lib/huginn_myq_agent/myq_agent.rb, line 66
def create_system
  system = RubyMyq::System.new(interpolated['email_address'],interpolated['password'])
end
open_door(door) click to toggle source
# File lib/huginn_myq_agent/myq_agent.rb, line 87
def open_door(door)
  door.open
end
select_door(door_name) click to toggle source
# File lib/huginn_myq_agent/myq_agent.rb, line 70
def select_door(door_name)
  system = create_system()
  door = system.find_door_by_name(door_name)
end
status(door) click to toggle source
# File lib/huginn_myq_agent/myq_agent.rb, line 75
def status(door)
  status = {
    'name' => door.name,
    'state' => door.status,
    'since' => door.status_since
  }
end
toggle_door(door) click to toggle source
# File lib/huginn_myq_agent/myq_agent.rb, line 91
def toggle_door(door)
  if door.status == "open"
    door.close
  elsif door.status == "closed"
    door.open
  end
end