mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 17:47:28 +00:00
Implement Flush Mounted Presence Sensor Routine Control and change the device type logic
This commit is contained in:
@ -94,6 +94,8 @@ class CreateSceneModel {
|
||||
}
|
||||
|
||||
class CreateSceneAction {
|
||||
final String? productType;
|
||||
|
||||
String entityId;
|
||||
String? actionType;
|
||||
String actionExecutor;
|
||||
@ -104,15 +106,18 @@ class CreateSceneAction {
|
||||
required this.entityId,
|
||||
required this.actionExecutor,
|
||||
required this.executorProperty,
|
||||
required this.productType,
|
||||
});
|
||||
|
||||
CreateSceneAction copyWith({
|
||||
String? productType,
|
||||
String? actionType,
|
||||
String? entityId,
|
||||
String? actionExecutor,
|
||||
CreateSceneExecutorProperty? executorProperty,
|
||||
}) {
|
||||
return CreateSceneAction(
|
||||
productType: productType,
|
||||
actionType: actionType,
|
||||
entityId: entityId ?? this.entityId,
|
||||
actionExecutor: actionExecutor ?? this.actionExecutor,
|
||||
@ -126,18 +131,21 @@ class CreateSceneAction {
|
||||
'entityId': entityId,
|
||||
'actionExecutor': actionExecutor,
|
||||
'executorProperty': executorProperty?.toMap(actionExecutor),
|
||||
// 'productType': productType,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
"actionType": actionType,
|
||||
'entityId': entityId,
|
||||
'actionExecutor': actionExecutor,
|
||||
// 'productType': productType,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
factory CreateSceneAction.fromMap(Map<String, dynamic> map) {
|
||||
return CreateSceneAction(
|
||||
productType: map['productType'] ?? '',
|
||||
entityId: map['entityId'] ?? '',
|
||||
actionExecutor: map['actionExecutor'] ?? '',
|
||||
executorProperty:
|
||||
|
@ -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({
|
||||
|
@ -12,7 +12,7 @@ class SceneStaticFunction {
|
||||
final String deviceId;
|
||||
final String operationName;
|
||||
final String? uniqueCustomId;
|
||||
final dynamic functionValue;
|
||||
dynamic functionValue;
|
||||
final String? deviceIcon;
|
||||
final OperationDialogType operationDialogType;
|
||||
final String? comparator;
|
||||
@ -29,7 +29,7 @@ class SceneStaticFunction {
|
||||
this.deviceIcon,
|
||||
required this.operationDialogType,
|
||||
this.comparator,
|
||||
this.deviceType,
|
||||
this.deviceType,
|
||||
String? uniqueCustomId,
|
||||
}) : uniqueCustomId = uniqueCustomId ?? const Uuid().v4();
|
||||
|
||||
@ -127,7 +127,8 @@ class SceneStaticFunction {
|
||||
other.uniqueCustomId == uniqueCustomId &&
|
||||
other.operationDialogType == operationDialogType &&
|
||||
listEquals(other.operationalValues, operationalValues) &&
|
||||
other.deviceId == deviceId && other.deviceType == deviceType;
|
||||
other.deviceId == deviceId &&
|
||||
other.deviceType == deviceType;
|
||||
}
|
||||
|
||||
@override
|
||||
@ -142,7 +143,8 @@ class SceneStaticFunction {
|
||||
comparator.hashCode ^
|
||||
uniqueCustomId.hashCode ^
|
||||
operationDialogType.hashCode ^
|
||||
operationalValues.hashCode ^ deviceType.hashCode;
|
||||
operationalValues.hashCode ^
|
||||
deviceType.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user