mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
57 lines
1.3 KiB
Dart
57 lines
1.3 KiB
Dart
import 'dart:convert';
|
|
import 'dart:typed_data';
|
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
|
|
|
class ScenesModel {
|
|
final String id;
|
|
final String? sceneTuyaId;
|
|
final String name;
|
|
final String status;
|
|
final String type;
|
|
final String? icon;
|
|
|
|
ScenesModel({
|
|
required this.id,
|
|
this.sceneTuyaId,
|
|
required this.name,
|
|
required this.status,
|
|
required this.type,
|
|
this.icon,
|
|
});
|
|
|
|
factory ScenesModel.fromRawJson(String str) =>
|
|
ScenesModel.fromJson(json.decode(str));
|
|
|
|
String toRawJson() => json.encode(toJson());
|
|
|
|
Uint8List? get iconInBytes {
|
|
if (icon == null || icon?.isEmpty == true) return null;
|
|
try {
|
|
return base64Decode(icon!);
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
factory ScenesModel.fromJson(Map<String, dynamic> json,
|
|
{bool? isAutomation}) {
|
|
return ScenesModel(
|
|
id: json["id"] ?? json["uuid"] ?? '',
|
|
sceneTuyaId: json["sceneTuyaId"] as String?,
|
|
name: json["name"] ?? '',
|
|
status: json["status"] ?? '',
|
|
type: json["type"] ?? '',
|
|
icon:
|
|
isAutomation == true ? Assets.automation : (json["icon"] as String?),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
"id": id,
|
|
"sceneTuyaId": sceneTuyaId ?? '',
|
|
"name": name,
|
|
"status": status,
|
|
"type": type,
|
|
};
|
|
}
|