mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 07:14:56 +00:00
fixed automation and tab to run bugs
This commit is contained in:
@ -1,18 +1,187 @@
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_scene_model.dart';
|
||||
|
||||
// class CreateAutomationModel {
|
||||
// String unitUuid;
|
||||
// String automationName;
|
||||
// String decisionExpr;
|
||||
// EffectiveTime effectiveTime;
|
||||
// List<CreateCondition> conditions;
|
||||
// List<CreateSceneAction> actions;
|
||||
|
||||
// CreateAutomationModel({
|
||||
// required this.unitUuid,
|
||||
// required this.automationName,
|
||||
// required this.decisionExpr,
|
||||
// required this.effectiveTime,
|
||||
// required this.conditions,
|
||||
// required this.actions,
|
||||
// });
|
||||
|
||||
// CreateAutomationModel copyWith({
|
||||
// String? unitUuid,
|
||||
// String? automationName,
|
||||
// String? decisionExpr,
|
||||
// EffectiveTime? effectiveTime,
|
||||
// List<CreateCondition>? conditions,
|
||||
// List<CreateSceneAction>? actions,
|
||||
// }) {
|
||||
// return CreateAutomationModel(
|
||||
// unitUuid: unitUuid ?? this.unitUuid,
|
||||
// automationName: automationName ?? this.automationName,
|
||||
// decisionExpr: decisionExpr ?? this.decisionExpr,
|
||||
// effectiveTime: effectiveTime ?? this.effectiveTime,
|
||||
// conditions: conditions ?? this.conditions,
|
||||
// actions: actions ?? this.actions,
|
||||
// );
|
||||
// }
|
||||
|
||||
// Map<String, dynamic> toMap([String? automationId]) {
|
||||
// return {
|
||||
// if (automationId == null) 'spaceUuid': unitUuid,
|
||||
// 'automationName': automationName,
|
||||
// 'decisionExpr': decisionExpr,
|
||||
// 'effectiveTime': effectiveTime.toMap(),
|
||||
// 'conditions': conditions.map((x) => x.toMap()).toList(),
|
||||
// 'actions': actions.map((x) => x.toMap()).toList(),
|
||||
// };
|
||||
// }
|
||||
|
||||
// factory CreateAutomationModel.fromMap(Map<String, dynamic> map) {
|
||||
// return CreateAutomationModel(
|
||||
// unitUuid: map['spaceUuid'] ?? '',
|
||||
// automationName: map['automationName'] ?? '',
|
||||
// decisionExpr: map['decisionExpr'] ?? '',
|
||||
// effectiveTime: EffectiveTime.fromMap(map['effectiveTime']),
|
||||
// conditions: List<CreateCondition>.from(
|
||||
// map['conditions']?.map((x) => CreateCondition.fromMap(x))),
|
||||
// actions: List<CreateSceneAction>.from(
|
||||
// map['actions']?.map((x) => CreateSceneAction.fromMap(x))),
|
||||
// );
|
||||
// }
|
||||
|
||||
// String toJson([String? automationId]) => json.encode(toMap(automationId));
|
||||
|
||||
// factory CreateAutomationModel.fromJson(String source) =>
|
||||
// CreateAutomationModel.fromMap(json.decode(source));
|
||||
|
||||
// @override
|
||||
// String toString() {
|
||||
// return 'CreateAutomationModel(unitUuid: $unitUuid, automationName: $automationName, decisionExpr: $decisionExpr, effectiveTime: $effectiveTime, conditions: $conditions, actions: $actions)';
|
||||
// }
|
||||
// }
|
||||
|
||||
// class EffectiveTime {
|
||||
// String start;
|
||||
// String end;
|
||||
// String loops;
|
||||
|
||||
// EffectiveTime({
|
||||
// required this.start,
|
||||
// required this.end,
|
||||
// required this.loops,
|
||||
// });
|
||||
|
||||
// Map<String, dynamic> toMap() {
|
||||
// return {
|
||||
// 'start': start,
|
||||
// 'end': end,
|
||||
// 'loops': loops,
|
||||
// };
|
||||
// }
|
||||
|
||||
// factory EffectiveTime.fromMap(Map<String, dynamic> map) {
|
||||
// return EffectiveTime(
|
||||
// start: map['start'] ?? '',
|
||||
// end: map['end'] ?? '',
|
||||
// loops: map['loops'] ?? '',
|
||||
// );
|
||||
// }
|
||||
|
||||
// @override
|
||||
// String toString() => 'EffectiveTime(start: $start, end: $end, loops: $loops)';
|
||||
// }
|
||||
|
||||
// class CreateCondition {
|
||||
// int code;
|
||||
// String entityId;
|
||||
// String entityType;
|
||||
// ConditionExpr expr;
|
||||
|
||||
// CreateCondition({
|
||||
// required this.code,
|
||||
// required this.entityId,
|
||||
// required this.entityType,
|
||||
// required this.expr,
|
||||
// });
|
||||
|
||||
// Map<String, dynamic> toMap() {
|
||||
// return {
|
||||
// 'code': code,
|
||||
// 'entityId': entityId,
|
||||
// 'entityType': entityType,
|
||||
// 'expr': expr.toMap(),
|
||||
// };
|
||||
// }
|
||||
|
||||
// factory CreateCondition.fromMap(Map<String, dynamic> map) {
|
||||
// return CreateCondition(
|
||||
// code: map['code'] ?? 0,
|
||||
// entityId: map['entityId'] ?? '',
|
||||
// entityType: map['entityType'] ?? '',
|
||||
// expr: ConditionExpr.fromMap(map['expr']),
|
||||
// );
|
||||
// }
|
||||
|
||||
// @override
|
||||
// String toString() =>
|
||||
// 'CreateCondition(code: $code, entityId: $entityId, entityType: $entityType, expr: $expr)';
|
||||
// }
|
||||
|
||||
// class ConditionExpr {
|
||||
// String statusCode;
|
||||
// String comparator;
|
||||
// dynamic statusValue;
|
||||
|
||||
// ConditionExpr({
|
||||
// required this.statusCode,
|
||||
// required this.comparator,
|
||||
// required this.statusValue,
|
||||
// });
|
||||
|
||||
// Map<String, dynamic> toMap() {
|
||||
// return {
|
||||
// 'statusCode': statusCode,
|
||||
// 'comparator': comparator,
|
||||
// 'statusValue': statusValue,
|
||||
// };
|
||||
// }
|
||||
|
||||
// factory ConditionExpr.fromMap(Map<String, dynamic> map) {
|
||||
// return ConditionExpr(
|
||||
// statusCode: map['statusCode'] ?? '',
|
||||
// comparator: map['comparator'] ?? '',
|
||||
// statusValue: map['statusValue'],
|
||||
// );
|
||||
// }
|
||||
|
||||
// @override
|
||||
// String toString() =>
|
||||
// 'ConditionExpr(statusCode: $statusCode, comparator: $comparator, statusValue: $statusValue)';
|
||||
// }
|
||||
import 'dart:convert';
|
||||
|
||||
class CreateAutomationModel {
|
||||
String unitUuid;
|
||||
String spaceUuid;
|
||||
String automationName;
|
||||
String decisionExpr;
|
||||
EffectiveTime effectiveTime;
|
||||
List<CreateCondition> conditions;
|
||||
List<CreateSceneAction> actions;
|
||||
List<Condition> conditions;
|
||||
List<AutomationAction> actions;
|
||||
|
||||
CreateAutomationModel({
|
||||
required this.unitUuid,
|
||||
required this.spaceUuid,
|
||||
required this.automationName,
|
||||
required this.decisionExpr,
|
||||
required this.effectiveTime,
|
||||
@ -20,27 +189,9 @@ class CreateAutomationModel {
|
||||
required this.actions,
|
||||
});
|
||||
|
||||
CreateAutomationModel copyWith({
|
||||
String? unitUuid,
|
||||
String? automationName,
|
||||
String? decisionExpr,
|
||||
EffectiveTime? effectiveTime,
|
||||
List<CreateCondition>? conditions,
|
||||
List<CreateSceneAction>? actions,
|
||||
}) {
|
||||
return CreateAutomationModel(
|
||||
unitUuid: unitUuid ?? this.unitUuid,
|
||||
automationName: automationName ?? this.automationName,
|
||||
decisionExpr: decisionExpr ?? this.decisionExpr,
|
||||
effectiveTime: effectiveTime ?? this.effectiveTime,
|
||||
conditions: conditions ?? this.conditions,
|
||||
actions: actions ?? this.actions,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap([String? automationId]) {
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
if (automationId == null) 'spaceUuid': unitUuid,
|
||||
'spaceUuid': spaceUuid,
|
||||
'automationName': automationName,
|
||||
'decisionExpr': decisionExpr,
|
||||
'effectiveTime': effectiveTime.toMap(),
|
||||
@ -51,26 +202,21 @@ class CreateAutomationModel {
|
||||
|
||||
factory CreateAutomationModel.fromMap(Map<String, dynamic> map) {
|
||||
return CreateAutomationModel(
|
||||
unitUuid: map['spaceUuid'] ?? '',
|
||||
spaceUuid: map['spaceUuid'] ?? '',
|
||||
automationName: map['automationName'] ?? '',
|
||||
decisionExpr: map['decisionExpr'] ?? '',
|
||||
effectiveTime: EffectiveTime.fromMap(map['effectiveTime']),
|
||||
conditions: List<CreateCondition>.from(
|
||||
map['conditions']?.map((x) => CreateCondition.fromMap(x))),
|
||||
actions: List<CreateSceneAction>.from(
|
||||
map['actions']?.map((x) => CreateSceneAction.fromMap(x))),
|
||||
conditions: List<Condition>.from(
|
||||
map['conditions']?.map((x) => Condition.fromMap(x)) ?? []),
|
||||
actions: List<AutomationAction>.from(
|
||||
map['actions']?.map((x) => AutomationAction.fromMap(x)) ?? []),
|
||||
);
|
||||
}
|
||||
|
||||
String toJson([String? automationId]) => json.encode(toMap(automationId));
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory CreateAutomationModel.fromJson(String source) =>
|
||||
CreateAutomationModel.fromMap(json.decode(source));
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'CreateAutomationModel(unitUuid: $unitUuid, automationName: $automationName, decisionExpr: $decisionExpr, effectiveTime: $effectiveTime, conditions: $conditions, actions: $actions)';
|
||||
}
|
||||
}
|
||||
|
||||
class EffectiveTime {
|
||||
@ -99,18 +245,15 @@ class EffectiveTime {
|
||||
loops: map['loops'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => 'EffectiveTime(start: $start, end: $end, loops: $loops)';
|
||||
}
|
||||
|
||||
class CreateCondition {
|
||||
class Condition {
|
||||
int code;
|
||||
String entityId;
|
||||
String entityType;
|
||||
ConditionExpr expr;
|
||||
|
||||
CreateCondition({
|
||||
Condition({
|
||||
required this.code,
|
||||
required this.entityId,
|
||||
required this.entityType,
|
||||
@ -126,18 +269,14 @@ class CreateCondition {
|
||||
};
|
||||
}
|
||||
|
||||
factory CreateCondition.fromMap(Map<String, dynamic> map) {
|
||||
return CreateCondition(
|
||||
code: map['code'] ?? 0,
|
||||
factory Condition.fromMap(Map<String, dynamic> map) {
|
||||
return Condition(
|
||||
code: map['code']?.toInt() ?? 0,
|
||||
entityId: map['entityId'] ?? '',
|
||||
entityType: map['entityType'] ?? '',
|
||||
expr: ConditionExpr.fromMap(map['expr']),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
'CreateCondition(code: $code, entityId: $entityId, entityType: $entityType, expr: $expr)';
|
||||
}
|
||||
|
||||
class ConditionExpr {
|
||||
@ -166,8 +305,62 @@ class ConditionExpr {
|
||||
statusValue: map['statusValue'],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
'ConditionExpr(statusCode: $statusCode, comparator: $comparator, statusValue: $statusValue)';
|
||||
}
|
||||
|
||||
class AutomationAction {
|
||||
String entityId;
|
||||
String actionExecutor;
|
||||
ExecutorProperty? executorProperty;
|
||||
|
||||
AutomationAction({
|
||||
required this.entityId,
|
||||
required this.actionExecutor,
|
||||
this.executorProperty,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'entityId': entityId,
|
||||
'actionExecutor': actionExecutor,
|
||||
'executorProperty': executorProperty?.toMap(),
|
||||
};
|
||||
}
|
||||
|
||||
factory AutomationAction.fromMap(Map<String, dynamic> map) {
|
||||
return AutomationAction(
|
||||
entityId: map['entityId'] ?? '',
|
||||
actionExecutor: map['actionExecutor'] ?? '',
|
||||
executorProperty: map['executorProperty'] != null
|
||||
? ExecutorProperty.fromMap(map['executorProperty'])
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ExecutorProperty {
|
||||
String? functionCode;
|
||||
dynamic functionValue;
|
||||
int? delaySeconds;
|
||||
|
||||
ExecutorProperty({
|
||||
this.functionCode,
|
||||
this.functionValue,
|
||||
this.delaySeconds,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
if (functionCode != null) 'functionCode': functionCode,
|
||||
if (functionValue != null) 'functionValue': functionValue,
|
||||
if (delaySeconds != null) 'delaySeconds': delaySeconds,
|
||||
};
|
||||
}
|
||||
|
||||
factory ExecutorProperty.fromMap(Map<String, dynamic> map) {
|
||||
return ExecutorProperty(
|
||||
functionCode: map['functionCode'],
|
||||
functionValue: map['functionValue'],
|
||||
delaySeconds: map['delaySeconds']?.toInt(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user