mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 11:27:54 +00:00
push automation details and update automation
This commit is contained in:
@@ -37,9 +37,9 @@ class CreateAutomationModel {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
Map<String, dynamic> toMap([String? automationId]) {
|
||||
return {
|
||||
'unitUuid': unitUuid,
|
||||
if (automationId == null) 'unitUuid': unitUuid,
|
||||
'automationName': automationName,
|
||||
'decisionExpr': decisionExpr,
|
||||
'effectiveTime': effectiveTime.toMap(),
|
||||
@@ -61,7 +61,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));
|
||||
|
||||
@@ -6,6 +6,9 @@ class SceneDetailsModel {
|
||||
final String status;
|
||||
final String type;
|
||||
final List<Action> actions;
|
||||
final List<Condition>? conditions;
|
||||
final String? decisionExpr;
|
||||
final EffectiveTime? effectiveTime;
|
||||
|
||||
SceneDetailsModel({
|
||||
required this.id,
|
||||
@@ -13,6 +16,9 @@ class SceneDetailsModel {
|
||||
required this.status,
|
||||
required this.type,
|
||||
required this.actions,
|
||||
this.conditions,
|
||||
this.decisionExpr,
|
||||
this.effectiveTime,
|
||||
});
|
||||
|
||||
factory SceneDetailsModel.fromRawJson(String str) =>
|
||||
@@ -28,6 +34,14 @@ class SceneDetailsModel {
|
||||
type: json["type"],
|
||||
actions:
|
||||
List<Action>.from(json["actions"].map((x) => Action.fromJson(x))),
|
||||
conditions: json["conditions"] != null
|
||||
? List<Condition>.from(
|
||||
json["conditions"].map((x) => Condition.fromJson(x)))
|
||||
: null,
|
||||
decisionExpr: json["decisionExpr"],
|
||||
effectiveTime: json["effectiveTime"] != null
|
||||
? EffectiveTime.fromJson(json["effectiveTime"])
|
||||
: null,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
@@ -36,6 +50,11 @@ class SceneDetailsModel {
|
||||
"status": status,
|
||||
"type": type,
|
||||
"actions": List<dynamic>.from(actions.map((x) => x.toJson())),
|
||||
"conditions": conditions != null
|
||||
? List<dynamic>.from(conditions!.map((x) => x.toJson()))
|
||||
: null,
|
||||
"decisionExpr": decisionExpr,
|
||||
"effectiveTime": effectiveTime?.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -91,3 +110,93 @@ class ExecutorProperty {
|
||||
"delaySeconds": delaySeconds,
|
||||
};
|
||||
}
|
||||
|
||||
class Condition {
|
||||
final int code;
|
||||
final String entityId;
|
||||
final String entityType;
|
||||
final Expr expr;
|
||||
|
||||
Condition({
|
||||
required this.code,
|
||||
required this.entityId,
|
||||
required this.entityType,
|
||||
required this.expr,
|
||||
});
|
||||
|
||||
factory Condition.fromRawJson(String str) =>
|
||||
Condition.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory Condition.fromJson(Map<String, dynamic> json) => Condition(
|
||||
code: json["code"],
|
||||
entityId: json["entityId"],
|
||||
entityType: json["entityType"],
|
||||
expr: Expr.fromJson(json["expr"]),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"code": code,
|
||||
"entityId": entityId,
|
||||
"entityType": entityType,
|
||||
"expr": expr.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
class Expr {
|
||||
final String comparator;
|
||||
final String statusCode;
|
||||
final dynamic statusValue;
|
||||
|
||||
Expr({
|
||||
required this.comparator,
|
||||
required this.statusCode,
|
||||
required this.statusValue,
|
||||
});
|
||||
|
||||
factory Expr.fromRawJson(String str) => Expr.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory Expr.fromJson(Map<String, dynamic> json) => Expr(
|
||||
comparator: json["comparator"],
|
||||
statusCode: json["statusCode"],
|
||||
statusValue: json["statusValue"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"comparator": comparator,
|
||||
"statusCode": statusCode,
|
||||
"statusValue": statusValue,
|
||||
};
|
||||
}
|
||||
|
||||
class EffectiveTime {
|
||||
final String start;
|
||||
final String end;
|
||||
final String loops;
|
||||
|
||||
EffectiveTime({
|
||||
required this.start,
|
||||
required this.end,
|
||||
required this.loops,
|
||||
});
|
||||
|
||||
factory EffectiveTime.fromRawJson(String str) =>
|
||||
EffectiveTime.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory EffectiveTime.fromJson(Map<String, dynamic> json) => EffectiveTime(
|
||||
start: json["start"],
|
||||
end: json["end"],
|
||||
loops: json["loops"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"start": start,
|
||||
"end": end,
|
||||
"loops": loops,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -37,9 +37,10 @@ enum Status { ENABLE }
|
||||
|
||||
final statusValues = EnumValues({"enable": Status.ENABLE});
|
||||
|
||||
enum Type { TAP_TO_RUN }
|
||||
enum Type { TAP_TO_RUN, automation }
|
||||
|
||||
final typeValues = EnumValues({"tap_to_run": Type.TAP_TO_RUN});
|
||||
final typeValues =
|
||||
EnumValues({"tap_to_run": Type.TAP_TO_RUN, "automation": Type.automation});
|
||||
|
||||
class EnumValues<T> {
|
||||
Map<String, T> map;
|
||||
|
||||
Reference in New Issue
Block a user