class SensorData { final bool apiTerdeteksi; final bool buzzerActive; final bool exhaustActive; final int gasValue; final int kelembapan; final bool pumpActive; final double suhu; SensorData({ required this.apiTerdeteksi, required this.buzzerActive, required this.exhaustActive, required this.gasValue, required this.kelembapan, required this.pumpActive, required this.suhu, }); factory SensorData.fromJson(Map json) { return SensorData( apiTerdeteksi: json['api_terdeteksi'] ?? false, buzzerActive: json['buzzer_active'] ?? false, exhaustActive: json['exhaust_active'] ?? false, gasValue: json['gas_value'] ?? 0, kelembapan: json['kelembapan'] ?? 0, pumpActive: json['pump_active'] ?? false, suhu: (json['suhu'] ?? 0).toDouble(), ); } Map toJson() { return { 'api_terdeteksi': apiTerdeteksi, 'buzzer_active': buzzerActive, 'exhaust_active': exhaustActive, 'gas_value': gasValue, 'kelembapan': kelembapan, 'pump_active': pumpActive, 'suhu': suhu, }; } // Helper methods untuk status String get statusApi => apiTerdeteksi ? 'Terdeteksi' : 'Aman'; String get statusSuhu => suhu > 35 ? 'Panas' : suhu > 25 ? 'Normal' : 'Dingin'; String get statusKelembapan => kelembapan > 70 ? 'Tinggi' : kelembapan > 40 ? 'Normal' : 'Rendah'; String get statusGas => gasValue > 300 ? 'Bahaya' : gasValue > 150 ? 'Waspada' : 'Aman'; // Helper untuk warna status bool get isFireDetected => apiTerdeteksi || gasValue > 300 || suhu > 40; bool get isWarning => gasValue > 150 || suhu > 35 || kelembapan > 70; }