mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 01:35:23 +00:00
59 lines
1.4 KiB
Dart
59 lines
1.4 KiB
Dart
class FunctionsEntity {
|
|
final String productUuid;
|
|
final String productType;
|
|
final List<DeviceFunction> functions;
|
|
|
|
FunctionsEntity({
|
|
required this.productUuid,
|
|
required this.productType,
|
|
required this.functions,
|
|
});
|
|
|
|
factory FunctionsEntity.fromJson(Map<String, dynamic> json) =>
|
|
FunctionsEntity(
|
|
productUuid: json["productUuid"],
|
|
productType: json["productType"],
|
|
functions: List<DeviceFunction>.from(
|
|
json["functions"].map((x) => DeviceFunction.fromJson(x)),
|
|
),
|
|
);
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
"productUuid": productUuid,
|
|
"productType": productType,
|
|
"functions": List<dynamic>.from(functions.map((x) => x.toJson())),
|
|
};
|
|
}
|
|
|
|
class DeviceFunction {
|
|
final String code;
|
|
final String values;
|
|
final String dataType;
|
|
|
|
DeviceFunction({
|
|
required this.code,
|
|
required this.values,
|
|
required this.dataType,
|
|
});
|
|
|
|
factory DeviceFunction.fromJson(Map<String, dynamic> json) => DeviceFunction(
|
|
code: _formatCode(json["code"]),
|
|
values: json["values"],
|
|
dataType: json["dataType"],
|
|
);
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
"code": code,
|
|
"values": values,
|
|
"dataType": dataType,
|
|
};
|
|
|
|
static String _formatCode(String originalCode) {
|
|
return originalCode
|
|
.replaceAll('_', ' ')
|
|
.split(' ')
|
|
.map((word) => word[0].toUpperCase() + word.substring(1))
|
|
.join(' ');
|
|
}
|
|
}
|