Delay arrival alert 2s so mDNS hostname resolves before alert fires
DHCP triggers on_arrival immediately but iPhone sends mDNS frames milliseconds later. Without the delay the alert fires with no hostname and falls back to the device label. Timer reads from known_devices at fire time so mDNS-updated hostname is used.
This commit is contained in:
@@ -1089,11 +1089,25 @@ def on_arrival(mac: str, ip: str, hostname: str = "") -> None:
|
|||||||
'last_seen': now
|
'last_seen': now
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = format_arrival(hostname, ip, vendor or "unknown", mac)
|
# Delay alert 2 seconds so mDNS can update the hostname before we send.
|
||||||
|
# The timer callback reads from known_devices at fire time to get the real name.
|
||||||
|
def _send_arrival_alert():
|
||||||
|
with known_lock:
|
||||||
|
dev = known_devices.get(mac)
|
||||||
|
if dev is None:
|
||||||
|
return # Device departed before timer fired
|
||||||
|
resolved_hostname = dev.get('hostname', hostname)
|
||||||
|
resolved_ip = dev.get('ip', ip)
|
||||||
|
resolved_vendor = dev.get('vendor', vendor)
|
||||||
|
msg = format_arrival(resolved_hostname, resolved_ip, resolved_vendor or "unknown", mac)
|
||||||
logging.info(msg)
|
logging.info(msg)
|
||||||
send_alert(msg)
|
send_alert(msg)
|
||||||
update_occupancy_state()
|
update_occupancy_state()
|
||||||
|
|
||||||
|
t = threading.Timer(2.0, _send_arrival_alert)
|
||||||
|
t.daemon = True
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
|
||||||
def on_departure(mac: str) -> None:
|
def on_departure(mac: str) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user