mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +00:00
Implement Flush Mounted Presence Sensor Routine Control and change the device type logic
This commit is contained in:
@ -75,7 +75,6 @@ class Action {
|
||||
String? name;
|
||||
String? type;
|
||||
final String productType;
|
||||
|
||||
final String deviceName;
|
||||
|
||||
Action({
|
||||
@ -91,39 +90,57 @@ class Action {
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
static Action? fromJson(Map<String, dynamic> json) {
|
||||
if (json['name'] != null && json['type'] != null) {
|
||||
return Action(
|
||||
actionExecutor: json["actionExecutor"] as String,
|
||||
entityId: json["entityId"] as String,
|
||||
name: json['name'] as String?,
|
||||
type: json['type'] as String?,
|
||||
productType: json['productType'] as String,
|
||||
deviceName: json['deviceName'] as String,
|
||||
);
|
||||
}
|
||||
if (json["executorProperty"] == null) {
|
||||
// Safely extract required fields with null checks
|
||||
final String? actionExecutor = json["actionExecutor"] as String?;
|
||||
final String? entityId = json["entityId"] as String?;
|
||||
final String? productType = json['productType'] as String?;
|
||||
final String? deviceName = json['deviceName'] as String?;
|
||||
|
||||
// Skip invalid actions with missing required fields
|
||||
if (actionExecutor == null ||
|
||||
entityId == null ||
|
||||
productType == null ||
|
||||
deviceName == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Action(
|
||||
actionExecutor: json["actionExecutor"] as String,
|
||||
entityId: json["entityId"] as String,
|
||||
executorProperty: ExecutorProperty.fromJson(json["executorProperty"]),
|
||||
productType: json['productType'] as String,
|
||||
deviceName: json['deviceName'] as String,
|
||||
);
|
||||
// Handle actions with 'name' and 'type'
|
||||
if (json['name'] != null && json['type'] != null) {
|
||||
return Action(
|
||||
actionExecutor: actionExecutor,
|
||||
entityId: entityId,
|
||||
name: json['name'] as String?,
|
||||
type: json['type'] as String?,
|
||||
productType: productType,
|
||||
deviceName: deviceName,
|
||||
);
|
||||
}
|
||||
|
||||
// Handle actions with 'executorProperty'
|
||||
if (json["executorProperty"] != null) {
|
||||
return Action(
|
||||
actionExecutor: actionExecutor,
|
||||
entityId: entityId,
|
||||
executorProperty: ExecutorProperty.fromJson(json["executorProperty"]),
|
||||
productType: productType,
|
||||
deviceName: deviceName,
|
||||
);
|
||||
}
|
||||
|
||||
return null; // Skip invalid actions
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"actionExecutor": actionExecutor,
|
||||
"entityId": entityId,
|
||||
"executorProperty": executorProperty?.toJson(),
|
||||
// "productType": productType
|
||||
};
|
||||
}
|
||||
|
||||
class ExecutorProperty {
|
||||
final String? functionCode;
|
||||
final dynamic functionValue;
|
||||
dynamic functionValue;
|
||||
final dynamic delaySeconds;
|
||||
|
||||
ExecutorProperty({
|
||||
|
Reference in New Issue
Block a user