Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple features without breaking existed #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ttimasdf
Copy link

@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
Contributor

quthla commented Dec 29, 2019

How is it listening for dnsmasq events?

@ttimasdf
Copy link
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
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
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
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
3 participants