Pulled latest changes

This commit is contained in:
Abdullah Alassaf
2024-11-30 21:37:55 +03:00
16 changed files with 870 additions and 342 deletions

View File

@ -17,7 +17,7 @@ class CreateAutomationModel {
required this.actions,
});
Map<String, dynamic> toMap() {
Map<String, dynamic> toMap([String? automationId]) {
return {
'spaceUuid': spaceUuid,
'automationName': automationName,
@ -41,7 +41,7 @@ class CreateAutomationModel {
);
}
String toJson() => json.encode(toMap());
String toJson(String? automationId) => json.encode(toMap(automationId));
factory CreateAutomationModel.fromJson(String source) =>
CreateAutomationModel.fromMap(json.decode(source));

View File

@ -13,6 +13,8 @@ class RoutineDetailsModel {
final EffectiveTime? effectiveTime;
final List<RoutineCondition>? conditions;
final String? type;
final String? sceneId;
final String? automationId;
RoutineDetailsModel({
required this.spaceUuid,
@ -24,6 +26,8 @@ class RoutineDetailsModel {
this.effectiveTime,
this.conditions,
this.type,
this.sceneId,
this.automationId,
});
// Convert to CreateSceneModel
@ -44,8 +48,7 @@ class RoutineDetailsModel {
spaceUuid: spaceUuid,
automationName: name,
decisionExpr: decisionExpr,
effectiveTime:
effectiveTime ?? EffectiveTime(start: '', end: '', loops: ''),
effectiveTime: effectiveTime ?? EffectiveTime(start: '', end: '', loops: ''),
conditions: conditions?.map((c) => c.toCondition()).toList() ?? [],
actions: actions.map((a) => a.toAutomationAction()).toList(),
);
@ -57,12 +60,13 @@ class RoutineDetailsModel {
'name': name,
'decisionExpr': decisionExpr,
'actions': actions.map((x) => x.toMap()).toList(),
if (iconId != null) 'iconId': iconId,
if (iconId != null) 'iconUuid': iconId,
if (showInDevice != null) 'showInDevice': showInDevice,
if (effectiveTime != null) 'effectiveTime': effectiveTime!.toMap(),
if (conditions != null)
'conditions': conditions!.map((x) => x.toMap()).toList(),
if (conditions != null) 'conditions': conditions!.map((x) => x.toMap()).toList(),
if (type != null) 'type': type,
if (sceneId != null) 'sceneId': sceneId,
if (automationId != null) 'automationId': automationId,
};
}
@ -74,16 +78,16 @@ class RoutineDetailsModel {
actions: List<RoutineAction>.from(
map['actions']?.map((x) => RoutineAction.fromMap(x)) ?? [],
),
iconId: map['iconId'],
iconId: map['iconUuid'],
showInDevice: map['showInDevice'],
effectiveTime: map['effectiveTime'] != null
? EffectiveTime.fromMap(map['effectiveTime'])
: null,
effectiveTime:
map['effectiveTime'] != null ? EffectiveTime.fromMap(map['effectiveTime']) : null,
conditions: map['conditions'] != null
? List<RoutineCondition>.from(
map['conditions'].map((x) => RoutineCondition.fromMap(x)))
? List<RoutineCondition>.from(map['conditions'].map((x) => RoutineCondition.fromMap(x)))
: null,
type: map['type'],
sceneId: map['sceneId'],
automationId: map['automationId'],
);
}
@ -96,12 +100,18 @@ class RoutineDetailsModel {
class RoutineAction {
final String entityId;
final String actionExecutor;
final String? name;
final RoutineExecutorProperty? executorProperty;
final String productType;
final String? type;
RoutineAction({
required this.entityId,
required this.actionExecutor,
required this.productType,
this.executorProperty,
this.name,
this.type,
});
CreateSceneAction toCreateSceneAction() {
@ -124,8 +134,9 @@ class RoutineAction {
return {
'entityId': entityId,
'actionExecutor': actionExecutor,
if (executorProperty != null)
'executorProperty': executorProperty!.toMap(),
if (type != null) 'type': type,
if (name != null) 'name': name,
if (executorProperty != null) 'executorProperty': executorProperty!.toMap(),
};
}
@ -133,6 +144,9 @@ class RoutineAction {
return RoutineAction(
entityId: map['entityId'] ?? '',
actionExecutor: map['actionExecutor'] ?? '',
productType: map['productType'] ?? '',
name: map['name'] ?? '',
type: map['type'] ?? '',
executorProperty: map['executorProperty'] != null
? RoutineExecutorProperty.fromMap(map['executorProperty'])
: null,
@ -189,12 +203,14 @@ class RoutineCondition {
final String entityId;
final String entityType;
final RoutineConditionExpr expr;
final String productType;
RoutineCondition({
required this.code,
required this.entityId,
required this.entityType,
required this.expr,
required this.productType,
});
Condition toCondition() {
@ -221,6 +237,7 @@ class RoutineCondition {
entityId: map['entityId'] ?? '',
entityType: map['entityType'] ?? '',
expr: RoutineConditionExpr.fromMap(map['expr']),
productType: map['productType'] ?? '',
);
}
}