Skip to content

Add multiple features without breaking existed#45

Open
ttimasdf wants to merge 3 commits into
mueslo:masterfrom
ttimasdf:modified
Open

Add multiple features without breaking existed#45
ttimasdf wants to merge 3 commits into
mueslo:masterfrom
ttimasdf:modified

Conversation

@ttimasdf
Copy link
Copy Markdown

@ttimasdf ttimasdf commented Dec 29, 2019

The modification is a bit messy so I combine the features inside one PR.

  • Listen dnsmasq DHCP events, report to HA after IP and hostname present.
  • Currently the script get IP with MAC address from ARP cache. Add another way to get from DHCP leases as fallback.
  • Filter hostapd associate event, if hostname could not be found from nslookup or DHCP leases, ignore the event. (DHCP event will call the script, so no device will be missed)
  • Add whitelist option so non-related devices could be filtered out.

I didn't test the build. Only scp'ed the script with modified one a.nd it works..

Hopefully this could fix #37, fix #43, fix #8.

There's the case that my home Wi-Fi contains many devices of different purposes, e.g. guest phone, TV stream box, IoT sensors and such. Those Wi-Fi clients shouldn't be reported as a device tracker, because we don't care about their connection status. So a whitelist function is implemented.
@quthla
Copy link
Copy Markdown
Contributor

quthla commented Dec 29, 2019

How is it listening for dnsmasq events?

@ttimasdf
Copy link
Copy Markdown
Author

echo "dhcp-script=/usr/lib/hass-tracker/push_event.sh" >> /etc/dnsmasq.conf

[ -z "$hostname" ] && hostname="$(get_host_name $mac)"
if [ -n "$hass_whitelist_devices" ] && ! array_contains "$hostname" $hass_whitelist_devices; then
logger -t $0 -p warning "push_event ignored, $hostname not in whitelist."
elif [ -z "$hostname" ]; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will ignore devices with no hostname?

# get hostname for mac
nslookup "$(get_ip $1)" | grep -o "name = .*$" | cut -d ' ' -f 3
domain="$(uci get dhcp.@dnsmasq[0].domain)"
nslookup "$(get_ip $1)" | grep -o "name = .*$" | cut -d ' ' -f 3 | sed -e "s/\\.$domain//"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you strip the domain?

resp=$(curl "$hass_host/api/services/device_tracker/see" -sfSX POST \
config_get hass_curl_insecure global curl_insecure

[ -n "$hass_curl_insecure" ] && curl_param="-k"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if hass_curl_insecure=0 this would still add the parameter, contrary to expectation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

correctly handle multiple ips Name resolution fails if reverse DNS zone not setup Add initial delay until hostname is clear

3 participants