mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 09:45:22 +00:00
55 lines
1.2 KiB
Dart
55 lines
1.2 KiB
Dart
import 'dart:convert';
|
|
|
|
class ScenesModel {
|
|
final String id;
|
|
final String name;
|
|
final Status status;
|
|
final Type type;
|
|
|
|
ScenesModel({
|
|
required this.id,
|
|
required this.name,
|
|
required this.status,
|
|
required this.type,
|
|
});
|
|
|
|
factory ScenesModel.fromRawJson(String str) =>
|
|
ScenesModel.fromJson(json.decode(str));
|
|
|
|
String toRawJson() => json.encode(toJson());
|
|
|
|
factory ScenesModel.fromJson(Map<String, dynamic> json) => ScenesModel(
|
|
id: json["id"],
|
|
name: json["name"],
|
|
status: statusValues.map[json["status"]]!,
|
|
type: typeValues.map[json["type"]]!,
|
|
);
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
"id": id,
|
|
"name": name,
|
|
"status": statusValues.reverse[status],
|
|
"type": typeValues.reverse[type],
|
|
};
|
|
}
|
|
|
|
enum Status { ENABLE }
|
|
|
|
final statusValues = EnumValues({"enable": Status.ENABLE});
|
|
|
|
enum Type { TAP_TO_RUN }
|
|
|
|
final typeValues = EnumValues({"tap_to_run": Type.TAP_TO_RUN});
|
|
|
|
class EnumValues<T> {
|
|
Map<String, T> map;
|
|
late Map<T, String> reverseMap;
|
|
|
|
EnumValues(this.map);
|
|
|
|
Map<T, String> get reverse {
|
|
reverseMap = map.map((k, v) => MapEntry(v, k));
|
|
return reverseMap;
|
|
}
|
|
}
|