33 lines
943 B
Dart
33 lines
943 B
Dart
class IrReceivedModel {
|
|
final String protocol;
|
|
final String code;
|
|
final int bits;
|
|
final String timestamp;
|
|
|
|
IrReceivedModel({
|
|
required this.protocol,
|
|
required this.code,
|
|
required this.bits,
|
|
required this.timestamp,
|
|
});
|
|
|
|
factory IrReceivedModel.fromMap(Map<dynamic, dynamic> json) {
|
|
return IrReceivedModel(
|
|
protocol: json['protocol'] ?? 'UNKNOWN',
|
|
code: json['code'] ?? '0x0',
|
|
bits: json['bits'] ?? 0,
|
|
timestamp: _parseTimestamp(json['timestamp']),
|
|
);
|
|
}
|
|
}
|
|
|
|
String _parseTimestamp(dynamic value) {
|
|
if (value == null) return '';
|
|
if (value is int) {
|
|
final dt = DateTime.fromMillisecondsSinceEpoch(value * 1000);
|
|
return '${dt.year}-${dt.month.toString().padLeft(2, '0')}-${dt.day.toString().padLeft(2, '0')} '
|
|
'${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}:${dt.second.toString().padLeft(2, '0')}';
|
|
}
|
|
return value.toString();
|
|
}
|