etm-powersync-app/lib/models/thing_category.dart
etm d5dc0c7ca5 Initial commit : Flutter app nymea energy monitor
- NymeaService : auth complète (Hello → Authenticate → SetNotificationStatus)
- Token top-level dans chaque requête JSON-RPC (fix critique GetThings)
- Persistance token via shared_preferences par hôte
- Dashboard : champs utilisateur/mot de passe dans le dialog de connexion
- ThingDetailScreen : renommer, réglages (settingsTypes) et supprimer
- NymeaThingClass : champ settingsTypes parsé depuis l'API
- NymeaThing : copyWith(name) + settingValue()
- Fix overflow _StateChip dans ThingsScreen

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 16:57:46 +01:00

187 lines
7.4 KiB
Dart

import 'package:flutter/material.dart';
import '../theme/app_theme.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
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,
'thermostat': ThingCategory.hvac,
'heatingzone': ThingCategory.hvac,
'ac': ThingCategory.hvac,
'airconditioner': ThingCategory.hvac,
'pump': ThingCategory.hvac,
'heatpump': 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: AppTheme.gridGray,
),
ThingCategory.solar: ThingCategoryInfo(
category: ThingCategory.solar,
label: 'Solaire',
icon: Icons.solar_power_rounded,
color: AppTheme.solarYellow,
),
ThingCategory.battery: ThingCategoryInfo(
category: ThingCategory.battery,
label: 'Stockage',
icon: Icons.battery_charging_full_rounded,
color: AppTheme.batteryGreen,
),
ThingCategory.evCharger: ThingCategoryInfo(
category: ThingCategory.evCharger,
label: 'Chargeurs EV',
icon: Icons.electric_car_rounded,
color: AppTheme.minPvBlue,
),
ThingCategory.hvac: ThingCategoryInfo(
category: ThingCategory.hvac,
label: 'Chauffage & Climatisation',
icon: Icons.thermostat_rounded,
color: Color(0xFFFF7043),
),
ThingCategory.lighting: ThingCategoryInfo(
category: ThingCategory.lighting,
label: 'Éclairage',
icon: Icons.lightbulb_rounded,
color: Color(0xFFFFCA28),
),
ThingCategory.sensors: ThingCategoryInfo(
category: ThingCategory.sensors,
label: 'Capteurs',
icon: Icons.sensors_rounded,
color: Color(0xFF26C6DA),
),
ThingCategory.network: ThingCategoryInfo(
category: ThingCategory.network,
label: 'Réseau & Passerelles',
icon: Icons.router_rounded,
color: Color(0xFF7C4DFF),
),
ThingCategory.notifications: ThingCategoryInfo(
category: ThingCategory.notifications,
label: 'Services de notification',
icon: Icons.notifications_rounded,
color: Color(0xFFEC407A),
),
ThingCategory.weather: ThingCategoryInfo(
category: ThingCategory.weather,
label: 'Météo',
icon: Icons.wb_cloudy_rounded,
color: Color(0xFF42A5F5),
),
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: Color(0xFF78909C),
),
};
// ─────────────────────────────────────────────────────────────────────────────
// 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;
}
return ThingCategory.other;
}
ThingCategoryInfo get categoryDetails => categoryInfoMap[category]!;
}