home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.57k stars 30.74k forks source link

device_tracker.asuswrt has broken ARP/MAC parsing in ap mode #4742

Closed trisk closed 7 years ago

trisk commented 7 years ago

Home Assistant release (hass --version): 0.34.2

Python release (python3 --version): Python 3.4.2

Component/platform: device_tracker.asuswrt

Description of problem: When mode is ap, we are unable to detect connected devices on recent AsusWRT-Merlin releases. This is because the regex for matching MAC addresses in expects lowercase output from arp -n when the lines actually look like:

? (192.168.4.132) at CC:3D:99:99:0D:E2 [ether]  on br0

Expected: Devices are detected and written out.

Problem-relevant configuration.yaml entries and steps to reproduce:

# AsusWRT check devices
device_tracker:
  - platform: asuswrt
    host: 192.168.4.254
    mode: ap
    protocol: ssh
    username: admin
    ssh_key: /var/opt/homeassistant/id_rsa
  1. Add asuswrt device tracker with mode ap.
  2. Check for detected devices.
  3. ssh into the AsusWRT device and check arp -n output.
trisk commented 7 years ago

Forcing the MAC search against a lowercase buffer should fix it:

if match.group('mac').lower() in arp.decode('utf-8').lower():
    arp_match = _ARP_REGEX.search(arp.decode('utf-8').lower())
Danielhiversen commented 7 years ago

If you have tested that your fix solves the problem, you can make a pull request to fix the problem?