From ef420ad360de67d5b033a7f9bcba973947fe51ed Mon Sep 17 00:00:00 2001 From: rzuasti Date: Fri, 29 May 2026 14:20:20 -0400 Subject: [PATCH] Do not notify when a device's vendor is first deduced Treat an empty->non-empty vendor transition as not a change, so first deducing a vendor for a device that previously had none no longer raises a "vendor changed" notification. Co-Authored-By: Claude Opus 4.7 --- TODO.md | 2 +- backend/src/events.rs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/TODO.md b/TODO.md index 64681ea..eaca728 100644 --- a/TODO.md +++ b/TODO.md @@ -12,7 +12,7 @@ - [x] Add a data set (json) to store maps from vendors -> device type; modify the device creation so that it uses it automatically - [x] Add an mDNS/Bonjour scanner - [x] Extract the select_interface method and interface logic from ARP scanner to a centralized utility file -- [ ] Figure out if we can univocally identify devices that mask their MAC address (like apple) +- [x] Figure out if we can univocally identify devices that mask their MAC address (like apple) - [ ] Add the scanner that triggered the event to the device_events table ## Frontend diff --git a/backend/src/events.rs b/backend/src/events.rs index d18a557..92ce3b4 100644 --- a/backend/src/events.rs +++ b/backend/src/events.rs @@ -26,9 +26,10 @@ fn display_name(device: &Device) -> &str { // Whether a re-sighting represents a real vendor change. A scanner that cannot deduce a vendor // reports an empty string; that is not a change (db::devices::update keeps the known vendor), so -// it must not raise a "vendor changed" notification either. +// it must not raise a "vendor changed" notification either. Likewise, first deducing a vendor for a +// device that previously had none is not a change worth notifying about. fn vendor_changed(existing: &str, new: &str) -> bool { - !new.is_empty() && existing != new + !existing.is_empty() && !new.is_empty() && existing != new } // Private helper function to deliver messages @@ -216,7 +217,7 @@ mod tests { } #[test] - fn newly_deduced_vendor_from_empty_is_a_change() { - assert!(vendor_changed("", "Apple, Inc.")); + fn newly_deduced_vendor_from_empty_is_not_a_change() { + assert!(!vendor_changed("", "Apple, Inc.")); } }