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.



8
9
10
11
12
13
# File 'lib/lifx_dash/monitor.rb', line 8

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.



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

def iface
  @iface
end

#macObject (readonly)

Returns the value of attribute mac.



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

def mac
  @mac
end

#selectorObject (readonly)

Returns the value of attribute selector.



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

def selector
  @selector
end

#tokenObject (readonly)

Returns the value of attribute token.



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

def token
  @token
end

Instance Method Details

#runObject



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

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