From e28eb349ba3e8fd8658d64a4c3835c61f0737196 Mon Sep 17 00:00:00 2001 From: rzuasti Date: Thu, 28 May 2026 16:44:34 -0400 Subject: [PATCH] Align frontend device types with backend canonical list Replaces the old frontend-only `router` type and adds the full set used by the backend: network_appliance, home_security, home_appliance, watch, pc, gaming_console. Adds an `apiName` getter to map camelCase enum values to the snake_case strings the API expects. Updates the unknown device icon to a question mark. Co-Authored-By: Claude Sonnet 4.6 --- TODO.md | 4 +-- frontend/lib/devices/device_actions.dart | 2 +- frontend/lib/model/device_type.dart | 44 ++++++++++++++++++++---- frontend/lib/utils/oott_api.dart | 2 +- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/TODO.md b/TODO.md index 7dbe54b..70fa3f6 100644 --- a/TODO.md +++ b/TODO.md @@ -24,8 +24,8 @@ - [x] Use date filter from backend API for device events list - [x] Use favicon in web frontend - [x] Style app title like favicon (font Barlow Condensed in a pill format with "primary" background) -- [ ] Update the device type management to consider the following list: phone, laptop, tablet, server, tv, printer, network_appliance (router, switch, firewall, etc.), home_security (camera, doorbell, etc.), home_appliance (fridge, dish washer, washer, dryer, etc.), watch, pc, gaming_console, unknown (use when a vendor cannot be clearly identified with any of the device types or a device is of a vendor not in the vendors json file) -- [ ] Change the unkown device icon (maybe just a question mark) +- [x] Update the device type management to consider the following list: phone, laptop, tablet, server, tv, printer, network_appliance (router, switch, firewall, etc.), home_security (camera, doorbell, etc.), home_appliance (fridge, dish washer, washer, dryer, etc.), watch, pc, gaming_console, unknown (use when a vendor cannot be clearly identified with any of the device types or a device is of a vendor not in the vendors json file) +- [x] Change the unkown device icon (maybe just a question mark) - [ ] Scan process monitor and summary page - [ ] Is the scan process running - [ ] Last run (when, how long did it take, how many devices did it found) diff --git a/frontend/lib/devices/device_actions.dart b/frontend/lib/devices/device_actions.dart index f08ced4..611e164 100644 --- a/frontend/lib/devices/device_actions.dart +++ b/frontend/lib/devices/device_actions.dart @@ -121,7 +121,7 @@ Future showRegisterDeviceDialog( await BackendAPI.instance.registerDevice( device.macAddress, owner, - deviceType.name, + deviceType.apiName, ); if (!context.mounted) return; UISnackbars.showSuccess(context, 'Device registered'); diff --git a/frontend/lib/model/device_type.dart b/frontend/lib/model/device_type.dart index 0c224ca..3637879 100644 --- a/frontend/lib/model/device_type.dart +++ b/frontend/lib/model/device_type.dart @@ -5,9 +5,14 @@ enum DeviceType { laptop, tablet, server, - router, tv, printer, + networkAppliance, + homeSecurity, + homeAppliance, + watch, + pc, + gamingConsole, unknown; IconData get icon => switch (this) { @@ -15,23 +20,50 @@ enum DeviceType { laptop => Icons.laptop, tablet => Icons.tablet_android, server => Icons.dns, - router => Icons.router, tv => Icons.tv, printer => Icons.print, - unknown => Icons.device_unknown, + networkAppliance => Icons.device_hub, + homeSecurity => Icons.security, + homeAppliance => Icons.kitchen, + watch => Icons.watch, + pc => Icons.computer, + gamingConsole => Icons.sports_esports, + unknown => Icons.question_mark, }; - String get label => - this == unknown ? 'Unknown' : name[0].toUpperCase() + name.substring(1); + String get label => switch (this) { + tv => 'TV', + pc => 'PC', + _ => + name + .replaceAllMapped(RegExp(r'[A-Z]'), (m) => ' ${m.group(0)}') + .trim() + .split(' ') + .map((w) => w[0].toUpperCase() + w.substring(1)) + .join(' '), + }; + + String get apiName => switch (this) { + networkAppliance => 'network_appliance', + homeSecurity => 'home_security', + homeAppliance => 'home_appliance', + gamingConsole => 'gaming_console', + _ => name, + }; static DeviceType fromString(String value) => switch (value.toLowerCase()) { 'phone' => phone, 'laptop' => laptop, 'tablet' => tablet, 'server' => server, - 'router' => router, 'tv' => tv, 'printer' => printer, + 'network_appliance' => networkAppliance, + 'home_security' => homeSecurity, + 'home_appliance' => homeAppliance, + 'watch' => watch, + 'pc' => pc, + 'gaming_console' => gamingConsole, _ => unknown, }; } diff --git a/frontend/lib/utils/oott_api.dart b/frontend/lib/utils/oott_api.dart index bbf572d..15d2930 100644 --- a/frontend/lib/utils/oott_api.dart +++ b/frontend/lib/utils/oott_api.dart @@ -104,7 +104,7 @@ class BackendAPI { if (owner != null && owner.isNotEmpty) params['owner'] = owner; if (deviceType != null) { params['device_type'] = - deviceType == DeviceType.unknown ? '' : deviceType.name; + deviceType == DeviceType.unknown ? '' : deviceType.apiName; } final response = await _dio.get('/devices', queryParameters: params);