add autoamtion tasks

This commit is contained in:
ashrafzarkanisala
2024-07-22 23:56:33 +03:00
parent 033f33683c
commit 9f68e4695f
14 changed files with 745 additions and 1905 deletions

View File

@ -3,29 +3,11 @@ import 'dart:convert';
import 'package:flutter/foundation.dart';
class CreateSceneModel {
/*
{
"unitUuid": "string",
"sceneName": "string",
"decisionExpr": "string",
"actions": [
{
"entityId": "string",
"actionExecutor": "string",
"executorProperty": {
"functionCode": "string",
"functionValue": {},
"delaySeconds": 0
}
}
]
}
*/
String unitUuid;
String sceneName;
String decisionExpr;
List<CreateSceneAction> actions;
CreateSceneModel({
required this.unitUuid,
required this.sceneName,
@ -100,6 +82,7 @@ class CreateSceneAction {
String entityId;
String actionExecutor;
CreateSceneExecutorProperty executorProperty;
CreateSceneAction({
required this.entityId,
required this.actionExecutor,
@ -122,7 +105,7 @@ class CreateSceneAction {
return {
'entityId': entityId,
'actionExecutor': actionExecutor,
'executorProperty': executorProperty.toMap(),
'executorProperty': executorProperty.toMap(actionExecutor),
};
}
@ -163,6 +146,7 @@ class CreateSceneExecutorProperty {
String functionCode;
dynamic functionValue;
int delaySeconds;
CreateSceneExecutorProperty({
required this.functionCode,
required this.functionValue,
@ -181,12 +165,14 @@ class CreateSceneExecutorProperty {
);
}
Map<String, dynamic> toMap() {
return {
if (functionCode.isNotEmpty == true) 'functionCode': functionCode,
if (functionValue != '') 'functionValue': functionValue,
if (delaySeconds > 0) 'delaySeconds': delaySeconds,
};
Map<String, dynamic> toMap(String actionExecutor) {
final map = <String, dynamic>{};
if (functionCode.isNotEmpty) map['functionCode'] = functionCode;
if (functionValue != null) map['functionValue'] = functionValue;
if (actionExecutor == 'delay' && delaySeconds > 0) {
map['delaySeconds'] = delaySeconds;
}
return map;
}
factory CreateSceneExecutorProperty.fromMap(Map<String, dynamic> map) {
@ -197,7 +183,7 @@ class CreateSceneExecutorProperty {
);
}
String toJson() => json.encode(toMap());
String toJson(String actionExecutor) => json.encode(toMap(actionExecutor));
factory CreateSceneExecutorProperty.fromJson(String source) =>
CreateSceneExecutorProperty.fromMap(json.decode(source));