diff --git a/lib/features/scene/model/scene_details_model.dart b/lib/features/scene/model/scene_details_model.dart index 7ad0e78..2a7d751 100644 --- a/lib/features/scene/model/scene_details_model.dart +++ b/lib/features/scene/model/scene_details_model.dart @@ -90,44 +90,25 @@ class Action { String toRawJson() => json.encode(toJson()); static Action? fromJson(Map json) { - // 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) { + + if (actionExecutor == null || entityId == null) { return null; } - // 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 + return Action( + actionExecutor: actionExecutor, + entityId: entityId, + executorProperty: json["executorProperty"] != null + ? ExecutorProperty.fromJson(json["executorProperty"]) + : null, + name: json['name'] as String?, + type: json['type'] as String?, + productType: json['productType'] as String? ?? 'unknown', + deviceName: json['deviceName'] as String? ?? 'Delay Action', + ); } Map toJson() => {