etm-powersync-app/lib/models/thing_category.dart
Patrick Schurig b7a7213ee4 feat(installateur): catalogue de things (lecture seule) + filtres
- nymea_models : NymeaVendor + NymeaThingClass étendu (vendorId, setupMethod, createMethods)
- nymea_service : getVendors() + getAllThingClasses() (typées, erreurs FR, guards sim/déco)
- thing_category : +simpleheatpump/smartgridheatpump -> hvac (interfaces réelles)
- thing_catalog_screen : liste groupée + 3 filtres combinables (fabricant/type/recherche) + détail read-only
- main.dart : /settings/system/things -> ThingCatalogScreen (remplace le stub)

Type dérivé des interfaces réelles (pas d'enum), fabricant résolu par vendorId (doublon ABB géré).
Aucun AddThing/Discovery/Pairing (lots B/C à venir).
Validé contre nymea réel (hems .75) : 6 vendors, 45 classes, 18 interfaces.
Réf. UI_DATA_CONTRACT.md §5.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 14:00:12 +02:00

205 lines
8.1 KiB
Dart

import 'package:flutter/material.dart';
import '../theme/etm_tokens.dart';
import 'nymea_models.dart';
// ─────────────────────────────────────────────────────────────────────────────
// Catégories affichées dans le Things screen
// ─────────────────────────────────────────────────────────────────────────────
enum ThingCategory {
energy, // smartmeter, energymeter, powersocket
solar, // solarinverter, solarpanel
battery, // battery, energystorage
evCharger, // evcharger, wallbox
cars, // evvehicle, electricvehicle + class name "car"/"vehicle"
hvac, // thermostat, heatingzone, ac, pump
lighting, // light, dimmablelight, colorlight
sensors, // sensor, temperaturesensor, humiditysensor, motionsensor
network, // networkdevice, gateway
notifications, // pushnotification, email, sms
media, // mediadevice, mediaplayer
weather, // weather
other, // tout le reste
}
class ThingCategoryInfo {
final ThingCategory category;
final String label;
final IconData icon;
final Color color;
const ThingCategoryInfo({
required this.category,
required this.label,
required this.icon,
required this.color,
});
}
// ─────────────────────────────────────────────────────────────────────────────
// Mapping interface nymea → catégorie
// ─────────────────────────────────────────────────────────────────────────────
const Map<String, ThingCategory> interfaceToCategoryMap = {
'smartmeter': ThingCategory.energy,
'electricmeter': ThingCategory.energy,
'energymeter': ThingCategory.energy,
'smartenergymeter': ThingCategory.energy,
'extendedsmartmeter': ThingCategory.energy,
'powersocket': ThingCategory.energy,
'smartplug': ThingCategory.energy,
'solarinverter': ThingCategory.solar,
'solarpanel': ThingCategory.solar,
'inverter': ThingCategory.solar,
'battery': ThingCategory.battery,
'energystorage': ThingCategory.battery,
'batterymonitor': ThingCategory.battery,
'evcharger': ThingCategory.evCharger,
'wallbox': ThingCategory.evCharger,
'evvehicle': ThingCategory.cars,
'electricvehicle': ThingCategory.cars,
'electriccar': ThingCategory.cars,
'vehicle': ThingCategory.cars,
'thermostat': ThingCategory.hvac,
'heatingzone': ThingCategory.hvac,
'ac': ThingCategory.hvac,
'airconditioner': ThingCategory.hvac,
'pump': ThingCategory.hvac,
'heatpump': ThingCategory.hvac,
'simpleheatpump': ThingCategory.hvac, // interfaces réelles (hems)
'smartgridheatpump': ThingCategory.hvac,
'ventilation': ThingCategory.hvac,
'boiler': ThingCategory.hvac,
'light': ThingCategory.lighting,
'dimmablelight': ThingCategory.lighting,
'colorlight': ThingCategory.lighting,
'colortemperaturelight': ThingCategory.lighting,
'sensor': ThingCategory.sensors,
'temperaturesensor': ThingCategory.sensors,
'humiditysensor': ThingCategory.sensors,
'pressuresensor': ThingCategory.sensors,
'motionsensor': ThingCategory.sensors,
'doorsensor': ThingCategory.sensors,
'windowsensor': ThingCategory.sensors,
'smokesensor': ThingCategory.sensors,
'co2sensor': ThingCategory.sensors,
'lightsensor': ThingCategory.sensors,
'networkdevice': ThingCategory.network,
'gateway': ThingCategory.network,
'router': ThingCategory.network,
'pushnotification': ThingCategory.notifications,
'notificationservice': ThingCategory.notifications,
'notification': ThingCategory.notifications,
'email': ThingCategory.notifications,
'sms': ThingCategory.notifications,
'weather': ThingCategory.weather,
'weatherstation': ThingCategory.weather,
'mediadevice': ThingCategory.media,
'mediaplayer': ThingCategory.media,
};
// ─────────────────────────────────────────────────────────────────────────────
// Infos visuelles par catégorie
// ─────────────────────────────────────────────────────────────────────────────
const Map<ThingCategory, ThingCategoryInfo> categoryInfoMap = {
ThingCategory.energy: ThingCategoryInfo(
category: ThingCategory.energy,
label: 'Compteurs & Prises',
icon: Icons.electrical_services_rounded,
color: EtmTokens.muted,
),
ThingCategory.solar: ThingCategoryInfo(
category: ThingCategory.solar,
label: 'Solaire',
icon: Icons.solar_power_rounded,
color: EtmTokens.amber,
),
ThingCategory.battery: ThingCategoryInfo(
category: ThingCategory.battery,
label: 'Stockage',
icon: Icons.battery_charging_full_rounded,
color: EtmTokens.green,
),
ThingCategory.evCharger: ThingCategoryInfo(
category: ThingCategory.evCharger,
label: 'Chargeurs EV',
icon: Icons.electric_car_rounded,
color: EtmTokens.blue,
),
ThingCategory.cars: ThingCategoryInfo(
category: ThingCategory.cars,
label: 'Véhicules',
icon: Icons.directions_car_rounded,
color: EtmTokens.blue,
),
ThingCategory.hvac: ThingCategoryInfo(
category: ThingCategory.hvac,
label: 'Chauffage & Clim',
icon: Icons.thermostat_rounded,
color: EtmTokens.orange,
),
ThingCategory.lighting: ThingCategoryInfo(
category: ThingCategory.lighting,
label: 'Éclairage',
icon: Icons.lightbulb_rounded,
color: EtmTokens.amber,
),
ThingCategory.sensors: ThingCategoryInfo(
category: ThingCategory.sensors,
label: 'Capteurs',
icon: Icons.sensors_rounded,
color: EtmTokens.blue,
),
ThingCategory.network: ThingCategoryInfo(
category: ThingCategory.network,
label: 'Réseau',
icon: Icons.router_rounded,
color: Color(0xFF7C4DFF),
),
ThingCategory.notifications: ThingCategoryInfo(
category: ThingCategory.notifications,
label: 'Notifications',
icon: Icons.notifications_rounded,
color: Color(0xFFEC407A),
),
ThingCategory.weather: ThingCategoryInfo(
category: ThingCategory.weather,
label: 'Météo',
icon: Icons.wb_cloudy_rounded,
color: EtmTokens.blue,
),
ThingCategory.media: ThingCategoryInfo(
category: ThingCategory.media,
label: 'Multimédia',
icon: Icons.speaker_rounded,
color: Color(0xFFAB47BC),
),
ThingCategory.other: ThingCategoryInfo(
category: ThingCategory.other,
label: 'Autres',
icon: Icons.device_hub_rounded,
color: EtmTokens.faint,
),
};
// ─────────────────────────────────────────────────────────────────────────────
// Extension utilitaire sur NymeaThingClass
// ─────────────────────────────────────────────────────────────────────────────
extension ThingClassCategoryExt on NymeaThingClass {
ThingCategory get category {
for (final iface in interfaces) {
final cat = interfaceToCategoryMap[iface.toLowerCase()];
if (cat != null) return cat;
}
// Fallback : nom de classe contient "car" ou "vehicle" → catégorie Cars
final lower = name.toLowerCase();
if (lower.contains('car') || lower.contains('vehicle')) {
return ThingCategory.cars;
}
return ThingCategory.other;
}
ThingCategoryInfo get categoryDetails => categoryInfoMap[category]!;
}