Class: LifxDash::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/lifx_dash/monitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token: nil, mac: nil, selector: "all", iface: "en0") ⇒ Monitor

Returns a new instance of Monitor



6
7
8
9
10
11
# File 'lib/lifx_dash/monitor.rb', line 6

def initialize(token: nil, mac: nil, selector: "all", iface: "en0")
  @iface    = iface
  @token    = token
  @mac      = mac
  @selector = selector
end

Instance Attribute Details

#ifaceObject (readonly)

Returns the value of attribute iface



4
5
6
# File 'lib/lifx_dash/monitor.rb', line 4

def iface
  @iface
end

#macObject (readonly)

Returns the value of attribute mac



4
5
6
# File 'lib/lifx_dash/monitor.rb', line 4

def mac
  @mac
end

#selectorObject (readonly)

Returns the value of attribute selector



4
5
6
# File 'lib/lifx_dash/monitor.rb', line 4

def selector
  @selector
end

#tokenObject (readonly)

Returns the value of attribute token



4
5
6
# File 'lib/lifx_dash/monitor.rb', line 4

def token
  @token
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lifx_dash/monitor.rb', line 13

def run
  puts "Starting lifx_dash monitor ..."
  puts " * listening on #{iface} for Dash button #{mac} presses to toggle #{selector} bulb(s)"

  LifxDash::Capturer.new(iface).listen do |pkt, source_mac_addr|
    if source_mac_addr == mac
      LOGGER.info "Detected Dash button press from MAC address: #{mac} -- pkt summary: #{pkt.peek}"
      lifx_api.toggle(selector)
    end
  end
end