class PatronusFati::DataModels::Connection

Attributes

bssid[RW]
mac[RW]

Public Class Methods

[](key) click to toggle source
# File lib/patronus_fati/data_models/connection.rb, line 8
def self.[](key)
  bssid, mac = key.split('^')
  instances[key] ||= new(bssid, mac)
end
current_expiration_threshold() click to toggle source
# File lib/patronus_fati/data_models/connection.rb, line 13
def self.current_expiration_threshold
  Time.now.to_i - CONNECTION_EXPIRATION
end
new(bssid, mac) click to toggle source
# File lib/patronus_fati/data_models/connection.rb, line 39
def initialize(bssid, mac)
  super
  self.bssid = bssid
  self.link_lost = false
  self.mac = mac
end

Public Instance Methods

active?() click to toggle source
# File lib/patronus_fati/data_models/connection.rb, line 35
def active?
  super && !link_lost
end
announce_changes() click to toggle source
# File lib/patronus_fati/data_models/connection.rb, line 17
def announce_changes
  return unless dirty? && DataModels::AccessPoint[bssid].valid? &&
    DataModels::Client[mac].valid?

  state = active? ? :connect : :disconnect
  PatronusFati.event_handler.event(:connection, state, full_state, diagnostic_data)

  # We need to reset the first seen so we get fresh duration information
  presence.first_seen = nil

  unless active?
    DataModels::AccessPoint[bssid].remove_client(mac)
    DataModels::Client[mac].remove_access_point(bssid)
  end

  mark_synced
end
full_state() click to toggle source
# File lib/patronus_fati/data_models/connection.rb, line 46
def full_state
  data = { 'access_point' => bssid, 'client' => mac, 'connected' => active?}
  data['duration'] = presence.visible_time if !active? && presence.visible_time
  data
end