mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 17:47:28 +00:00
add autoamtion tasks
This commit is contained in:
@ -44,7 +44,8 @@ class DeviceModel {
|
||||
|
||||
if (type == DeviceType.LightBulb) {
|
||||
tempIcon = Assets.assetsIconsLight;
|
||||
} else if (type == DeviceType.CeilingSensor || type == DeviceType.WallSensor) {
|
||||
} else if (type == DeviceType.CeilingSensor ||
|
||||
type == DeviceType.WallSensor) {
|
||||
tempIcon = Assets.assetsIconsSensors;
|
||||
} else if (type == DeviceType.AC) {
|
||||
tempIcon = Assets.assetsIconsAC;
|
||||
@ -93,5 +94,6 @@ class DeviceModel {
|
||||
};
|
||||
}
|
||||
|
||||
List<FunctionModel> getFunctions(DeviceType type) => devicesFunctionsMap[productType] ?? [];
|
||||
List<FunctionModel> getFunctions(DeviceType type) =>
|
||||
devicesFunctionsMap[productType] ?? [];
|
||||
}
|
||||
|
@ -40,19 +40,25 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
|
||||
FutureOr<void> _onAddSceneTask(
|
||||
AddTaskEvent event, Emitter<CreateSceneState> emit) {
|
||||
emit(CreateSceneLoading());
|
||||
if (event.isAutomation == true) {
|
||||
final copyList = List<SceneStaticFunction>.from(automationTempTasksList);
|
||||
automationTasksList.addAll(copyList);
|
||||
automationTempTasksList.clear();
|
||||
automationSelectedValues.clear();
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
automationTasksList: automationTasksList,
|
||||
tasksList: tasksList,
|
||||
));
|
||||
} else {
|
||||
final copyList = List<SceneStaticFunction>.from(tempTasksList);
|
||||
tasksList.addAll(copyList);
|
||||
tempTasksList.clear();
|
||||
selectedValues.clear();
|
||||
emit(AddSceneTask(tasksList: tasksList));
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList,
|
||||
automationTasksList: automationTasksList,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,198 +117,9 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
tempTasksList.add(newElement);
|
||||
selectedValues[newElement.code] = event.deviceControlModel.value;
|
||||
}
|
||||
emit(TempHoldSceneTask(tempTasksList: tempTasksList));
|
||||
emit(AddSceneTask(tasksList: tasksList));
|
||||
}
|
||||
|
||||
FutureOr<void> _selectedValue(
|
||||
SelectedValueEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
automationSelectedValues[event.code] = event.value;
|
||||
emit(SelectedTaskValueState(value: event.value));
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
} else {
|
||||
selectedValues[event.code] = event.value;
|
||||
emit(SelectedTaskValueState(value: event.value));
|
||||
emit(AddSceneTask(tasksList: tasksList));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _removeTaskById(
|
||||
RemoveTaskByIdEvent event, Emitter<CreateSceneState> emit) {
|
||||
emit(CreateSceneLoading());
|
||||
if (event.isAutomation == true) {
|
||||
for (var element in automationTasksList) {
|
||||
if (element.uniqueCustomId == event.taskId) {
|
||||
automationTasksList.remove(element);
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var element in tasksList) {
|
||||
if (element.uniqueCustomId == event.taskId) {
|
||||
tasksList.remove(element);
|
||||
|
||||
emit(AddSceneTask(tasksList: tasksList));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _removeTempTaskById(
|
||||
RemoveTempTaskByIdEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
for (var element in automationTempTasksList) {
|
||||
if (element.uniqueCustomId == event.code) {
|
||||
automationTempTasksList.remove(element);
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var element in tempTasksList) {
|
||||
if (element.code == event.code) {
|
||||
tempTasksList.remove(element);
|
||||
|
||||
emit(AddSceneTask(tasksList: tasksList));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _createSceneWithTasks(
|
||||
CreateSceneWithTasksEvent event, Emitter<CreateSceneState> emit) async {
|
||||
emit(CreateSceneLoading());
|
||||
try {
|
||||
final response = event.updateScene
|
||||
? await SceneApi.updateScene(event.createSceneModel, event.sceneId)
|
||||
: await SceneApi.createScene(event.createSceneModel);
|
||||
if (response['success'] == true) {
|
||||
tasksList.clear();
|
||||
tempTasksList.clear();
|
||||
selectedValues.clear();
|
||||
emit(const CreateSceneWithTasks(success: true));
|
||||
} else {
|
||||
emit(const CreateSceneError(message: 'Something went wrong'));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(const CreateSceneError(message: 'Something went wrong'));
|
||||
emit(AddSceneTask(tasksList: tasksList));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _clearTaskList(
|
||||
ClearTaskListEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
automationTasksList.clear();
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
} else {
|
||||
tasksList.clear();
|
||||
emit(AddSceneTask(tasksList: tasksList));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _fetchSceneTasks(
|
||||
FetchSceneTasksEvent event, Emitter<CreateSceneState> emit) async {
|
||||
emit(CreateSceneLoading());
|
||||
|
||||
try {
|
||||
final response = await SceneApi.getSceneDetails(event.sceneId);
|
||||
if (response.id.isNotEmpty) {
|
||||
tasksList = List<SceneStaticFunction>.from(
|
||||
getTaskListFunctionsFromApi(actions: response.actions));
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList,
|
||||
));
|
||||
} else {
|
||||
emit(const CreateSceneError(message: 'Something went wrong'));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(const CreateSceneError(message: 'Something went wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _clearTempTaskList(
|
||||
ClearTempTaskListEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
automationTempTasksList.clear();
|
||||
automationSelectedValues.clear();
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
} else {
|
||||
tempTasksList.clear();
|
||||
selectedValues.clear();
|
||||
emit(AddSceneTask(tasksList: tempTasksList));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _removeFromSelectedValueById(
|
||||
RemoveFromSelectedValueById event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
if (automationSelectedValues.containsKey(event.code)) {
|
||||
automationSelectedValues.remove(event.code);
|
||||
emit(const SelectedTaskValueState(value: null));
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
}
|
||||
} else {
|
||||
if (selectedValues.containsKey(event.code)) {
|
||||
selectedValues.remove(event.code);
|
||||
emit(const SelectedTaskValueState(value: null));
|
||||
emit(AddSceneTask(tasksList: tasksList));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _deleteScene(
|
||||
DeleteSceneEvent event, Emitter<CreateSceneState> emit) async {
|
||||
emit(DeleteSceneLoading());
|
||||
|
||||
try {
|
||||
final response = await SceneApi.deleteScene(
|
||||
sceneId: event.sceneId, unitUuid: event.unitUuid);
|
||||
if (response == true) {
|
||||
emit(const DeleteSceneSuccess(true));
|
||||
} else {
|
||||
emit(const DeleteSceneError(message: 'Something went wrong'));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(const DeleteSceneError(message: 'Something went wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _updateTaskValue(
|
||||
UpdateTaskEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
for (var i = 0; i < automationTasksList.length; i++) {
|
||||
if (automationTasksList[i].uniqueCustomId == event.taskId) {
|
||||
automationTasksList[i] = automationTasksList[i].copyWith(
|
||||
functionValue: event.newValue,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
} else {
|
||||
for (var i = 0; i < tasksList.length; i++) {
|
||||
if (tasksList[i].uniqueCustomId == event.taskId) {
|
||||
tasksList[i] = tasksList[i].copyWith(
|
||||
functionValue: event.newValue,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
emit(AddSceneTask(tasksList: tasksList));
|
||||
}
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
}
|
||||
|
||||
void addToTempAutomationTaskList(
|
||||
@ -354,10 +171,200 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
automationSelectedValues[newElement.code] =
|
||||
event.deviceControlModel.value;
|
||||
}
|
||||
emit(TempHoldSceneTask(
|
||||
tempTasksList: tempTasksList,
|
||||
automationTempTasksList: automationTempTasksList));
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
}
|
||||
|
||||
FutureOr<void> _selectedValue(
|
||||
SelectedValueEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
automationSelectedValues[event.code] = event.value;
|
||||
emit(SelectedTaskValueState(value: event.value));
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
} else {
|
||||
selectedValues[event.code] = event.value;
|
||||
emit(SelectedTaskValueState(value: event.value));
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _removeTaskById(
|
||||
RemoveTaskByIdEvent event, Emitter<CreateSceneState> emit) {
|
||||
emit(CreateSceneLoading());
|
||||
if (event.isAutomation == true) {
|
||||
for (var element in automationTasksList) {
|
||||
if (element.uniqueCustomId == event.taskId) {
|
||||
automationTasksList.remove(element);
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var element in tasksList) {
|
||||
if (element.uniqueCustomId == event.taskId) {
|
||||
tasksList.remove(element);
|
||||
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _removeTempTaskById(
|
||||
RemoveTempTaskByIdEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
for (var element in automationTempTasksList) {
|
||||
if (element.uniqueCustomId == event.code) {
|
||||
automationTempTasksList.remove(element);
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var element in tempTasksList) {
|
||||
if (element.code == event.code) {
|
||||
tempTasksList.remove(element);
|
||||
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _createSceneWithTasks(
|
||||
CreateSceneWithTasksEvent event, Emitter<CreateSceneState> emit) async {
|
||||
emit(CreateSceneLoading());
|
||||
try {
|
||||
final response = event.updateScene
|
||||
? await SceneApi.updateScene(event.createSceneModel, event.sceneId)
|
||||
: await SceneApi.createScene(event.createSceneModel);
|
||||
if (response['success'] == true) {
|
||||
tasksList.clear();
|
||||
tempTasksList.clear();
|
||||
selectedValues.clear();
|
||||
emit(const CreateSceneWithTasks(success: true));
|
||||
} else {
|
||||
emit(const CreateSceneError(message: 'Something went wrong'));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(const CreateSceneError(message: 'Something went wrong'));
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _clearTaskList(
|
||||
ClearTaskListEvent event, Emitter<CreateSceneState> emit) {
|
||||
automationTasksList.clear();
|
||||
tasksList.clear();
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
}
|
||||
|
||||
FutureOr<void> _fetchSceneTasks(
|
||||
FetchSceneTasksEvent event, Emitter<CreateSceneState> emit) async {
|
||||
emit(CreateSceneLoading());
|
||||
|
||||
try {
|
||||
final response = await SceneApi.getSceneDetails(event.sceneId);
|
||||
if (response.id.isNotEmpty) {
|
||||
tasksList = List<SceneStaticFunction>.from(getTaskListFunctionsFromApi(
|
||||
actions: response.actions, isAutomation: false));
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList,
|
||||
));
|
||||
} else {
|
||||
emit(const CreateSceneError(message: 'Something went wrong'));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(const CreateSceneError(message: 'Something went wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _clearTempTaskList(
|
||||
ClearTempTaskListEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
automationTempTasksList.clear();
|
||||
automationSelectedValues.clear();
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
} else {
|
||||
tempTasksList.clear();
|
||||
selectedValues.clear();
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _removeFromSelectedValueById(
|
||||
RemoveFromSelectedValueById event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
if (automationSelectedValues.containsKey(event.code)) {
|
||||
automationSelectedValues.remove(event.code);
|
||||
emit(const SelectedTaskValueState(value: null));
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
}
|
||||
} else {
|
||||
if (selectedValues.containsKey(event.code)) {
|
||||
selectedValues.remove(event.code);
|
||||
emit(const SelectedTaskValueState(value: null));
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _deleteScene(
|
||||
DeleteSceneEvent event, Emitter<CreateSceneState> emit) async {
|
||||
emit(DeleteSceneLoading());
|
||||
|
||||
try {
|
||||
final response = await SceneApi.deleteScene(
|
||||
sceneId: event.sceneId, unitUuid: event.unitUuid);
|
||||
if (response == true) {
|
||||
emit(const DeleteSceneSuccess(true));
|
||||
} else {
|
||||
emit(const DeleteSceneError(message: 'Something went wrong'));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(const DeleteSceneError(message: 'Something went wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _updateTaskValue(
|
||||
UpdateTaskEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
for (var i = 0; i < automationTasksList.length; i++) {
|
||||
if (automationTasksList[i].uniqueCustomId == event.taskId) {
|
||||
automationTasksList[i] = automationTasksList[i].copyWith(
|
||||
functionValue: event.newValue,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
} else {
|
||||
for (var i = 0; i < tasksList.length; i++) {
|
||||
if (tasksList[i].uniqueCustomId == event.taskId) {
|
||||
tasksList[i] = tasksList[i].copyWith(
|
||||
functionValue: event.newValue,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -113,10 +113,12 @@ class CreateSceneWithTasksEvent extends CreateSceneEvent {
|
||||
final CreateSceneModel createSceneModel;
|
||||
final bool updateScene;
|
||||
final String sceneId;
|
||||
//final bool isAutomation;
|
||||
const CreateSceneWithTasksEvent({
|
||||
required this.createSceneModel,
|
||||
required this.updateScene,
|
||||
required this.sceneId,
|
||||
// required this.isAutomation,
|
||||
});
|
||||
|
||||
@override
|
||||
|
@ -157,18 +157,6 @@ class HumanPresenceHelperFunctions {
|
||||
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||
],
|
||||
),
|
||||
SceneStaticFunction(
|
||||
deviceId: deviceId,
|
||||
deviceName: deviceName,
|
||||
icon: Assets.assetsNobodyTime,
|
||||
operationName: 'Nobody Time',
|
||||
code: 'presence_time',
|
||||
functionValue: functionValue,
|
||||
operationDialogType: OperationDialogType.countdown,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(icon: '', value: 0),
|
||||
],
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@ -234,142 +222,6 @@ class HumanPresenceHelperFunctions {
|
||||
),
|
||||
],
|
||||
),
|
||||
SceneStaticFunction(
|
||||
deviceId: deviceId,
|
||||
deviceName: deviceName,
|
||||
icon: Assets.assetsFarDetection,
|
||||
operationName: 'Far Detection',
|
||||
code: 'far_detection',
|
||||
functionValue: functionValue,
|
||||
operationDialogType: OperationDialogType.listOfOptions,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsFarDetectionFunction,
|
||||
value: 75,
|
||||
description: '75cm',
|
||||
iconValue: '75',
|
||||
),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsFarDetectionFunction,
|
||||
value: 150,
|
||||
description: '150cm',
|
||||
iconValue: '150',
|
||||
),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsFarDetectionFunction,
|
||||
value: 225,
|
||||
description: '225cm',
|
||||
iconValue: '225',
|
||||
),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsFarDetectionFunction,
|
||||
value: 300,
|
||||
description: '300cm',
|
||||
iconValue: '300',
|
||||
),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsFarDetectionFunction,
|
||||
value: 375,
|
||||
description: '375cm',
|
||||
iconValue: '375',
|
||||
),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsFarDetectionFunction,
|
||||
value: 450,
|
||||
description: '450cm',
|
||||
iconValue: '450',
|
||||
),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsFarDetectionFunction,
|
||||
value: 525,
|
||||
description: '525cm',
|
||||
iconValue: '525',
|
||||
),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsFarDetectionFunction,
|
||||
value: 600,
|
||||
description: '600cm',
|
||||
iconValue: '600',
|
||||
),
|
||||
],
|
||||
),
|
||||
SceneStaticFunction(
|
||||
deviceId: deviceId,
|
||||
deviceName: deviceName,
|
||||
icon: Assets.assetsMotionDetection,
|
||||
operationName: 'Motion Detection Sensitivity',
|
||||
code: 'motion_sensitivity_value',
|
||||
functionValue: functionValue,
|
||||
operationDialogType: OperationDialogType.listOfOptions,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsSensitivityOperationIcon,
|
||||
value: 1,
|
||||
description: 1.toString(),
|
||||
),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsSensitivityOperationIcon,
|
||||
value: 2,
|
||||
description: 2.toString(),
|
||||
),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsSensitivityOperationIcon,
|
||||
value: 3,
|
||||
description: 3.toString(),
|
||||
),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsSensitivityOperationIcon,
|
||||
value: 4,
|
||||
description: 4.toString(),
|
||||
),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsSensitivityOperationIcon,
|
||||
value: 5,
|
||||
description: 5.toString(),
|
||||
),
|
||||
],
|
||||
),
|
||||
SceneStaticFunction(
|
||||
deviceId: deviceId,
|
||||
deviceName: deviceName,
|
||||
icon: Assets.assetsMotionlessDetection,
|
||||
operationName: 'Motionless Detection Sensitivity',
|
||||
code: 'motionless_sensitivity',
|
||||
functionValue: functionValue,
|
||||
operationDialogType: OperationDialogType.listOfOptions,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(
|
||||
iconValue: '1',
|
||||
icon: Assets.assetsFarDetectionFunction,
|
||||
value: 1,
|
||||
description: '1',
|
||||
),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsFarDetectionFunction,
|
||||
value: 2,
|
||||
description: '2',
|
||||
iconValue: '2',
|
||||
),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsFarDetectionFunction,
|
||||
value: 3,
|
||||
description: '3',
|
||||
iconValue: '3',
|
||||
),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsFarDetectionFunction,
|
||||
value: 4,
|
||||
description: '4',
|
||||
iconValue: '4',
|
||||
),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsFarDetectionFunction,
|
||||
value: 5,
|
||||
description: '5',
|
||||
iconValue: '5',
|
||||
),
|
||||
],
|
||||
),
|
||||
SceneStaticFunction(
|
||||
deviceId: deviceId,
|
||||
deviceName: deviceName,
|
||||
@ -395,13 +247,12 @@ class HumanPresenceHelperFunctions {
|
||||
operationDialogType: OperationDialogType.integerSteps,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(
|
||||
icon: '',
|
||||
value: 0.0,
|
||||
minValue: 0.0,
|
||||
maxValue: 65535,
|
||||
stepValue: 1,
|
||||
description: 'min'
|
||||
),
|
||||
icon: '',
|
||||
value: 0.0,
|
||||
minValue: 0.0,
|
||||
maxValue: 65535,
|
||||
stepValue: 1,
|
||||
description: 'min'),
|
||||
],
|
||||
),
|
||||
];
|
||||
|
@ -81,9 +81,8 @@ mixin SceneLogicHelper {
|
||||
}
|
||||
|
||||
Widget getTheCorrectDialogBody(
|
||||
SceneStaticFunction taskItem,
|
||||
dynamic functionValue,
|
||||
) {
|
||||
SceneStaticFunction taskItem, dynamic functionValue,
|
||||
{required bool isAutomation}) {
|
||||
if (taskItem.operationDialogType == OperationDialogType.temperature) {
|
||||
return AlertDialogTemperatureBody(
|
||||
taskItem: taskItem,
|
||||
@ -102,12 +101,14 @@ mixin SceneLogicHelper {
|
||||
return AlertDialogSliderSteps(
|
||||
taskItem: taskItem,
|
||||
functionValue: functionValue ?? taskItem.functionValue,
|
||||
isAutomation: isAutomation,
|
||||
);
|
||||
}
|
||||
|
||||
return AlertDialogFunctionsOperationsBody(
|
||||
taskItem: taskItem,
|
||||
functionValue: functionValue ?? taskItem.functionValue,
|
||||
isAutomation: isAutomation,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3,29 +3,11 @@ import 'dart:convert';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class CreateSceneModel {
|
||||
/*
|
||||
{
|
||||
"unitUuid": "string",
|
||||
"sceneName": "string",
|
||||
"decisionExpr": "string",
|
||||
"actions": [
|
||||
{
|
||||
"entityId": "string",
|
||||
"actionExecutor": "string",
|
||||
"executorProperty": {
|
||||
"functionCode": "string",
|
||||
"functionValue": {},
|
||||
"delaySeconds": 0
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
String unitUuid;
|
||||
String sceneName;
|
||||
String decisionExpr;
|
||||
List<CreateSceneAction> actions;
|
||||
|
||||
CreateSceneModel({
|
||||
required this.unitUuid,
|
||||
required this.sceneName,
|
||||
@ -100,6 +82,7 @@ class CreateSceneAction {
|
||||
String entityId;
|
||||
String actionExecutor;
|
||||
CreateSceneExecutorProperty executorProperty;
|
||||
|
||||
CreateSceneAction({
|
||||
required this.entityId,
|
||||
required this.actionExecutor,
|
||||
@ -122,7 +105,7 @@ class CreateSceneAction {
|
||||
return {
|
||||
'entityId': entityId,
|
||||
'actionExecutor': actionExecutor,
|
||||
'executorProperty': executorProperty.toMap(),
|
||||
'executorProperty': executorProperty.toMap(actionExecutor),
|
||||
};
|
||||
}
|
||||
|
||||
@ -163,6 +146,7 @@ class CreateSceneExecutorProperty {
|
||||
String functionCode;
|
||||
dynamic functionValue;
|
||||
int delaySeconds;
|
||||
|
||||
CreateSceneExecutorProperty({
|
||||
required this.functionCode,
|
||||
required this.functionValue,
|
||||
@ -181,12 +165,14 @@ class CreateSceneExecutorProperty {
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
if (functionCode.isNotEmpty == true) 'functionCode': functionCode,
|
||||
if (functionValue != '') 'functionValue': functionValue,
|
||||
if (delaySeconds > 0) 'delaySeconds': delaySeconds,
|
||||
};
|
||||
Map<String, dynamic> toMap(String actionExecutor) {
|
||||
final map = <String, dynamic>{};
|
||||
if (functionCode.isNotEmpty) map['functionCode'] = functionCode;
|
||||
if (functionValue != null) map['functionValue'] = functionValue;
|
||||
if (actionExecutor == 'delay' && delaySeconds > 0) {
|
||||
map['delaySeconds'] = delaySeconds;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
factory CreateSceneExecutorProperty.fromMap(Map<String, dynamic> map) {
|
||||
@ -197,7 +183,7 @@ class CreateSceneExecutorProperty {
|
||||
);
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
String toJson(String actionExecutor) => json.encode(toMap(actionExecutor));
|
||||
|
||||
factory CreateSceneExecutorProperty.fromJson(String source) =>
|
||||
CreateSceneExecutorProperty.fromMap(json.decode(source));
|
||||
|
@ -188,6 +188,7 @@ class DeviceFunctionsView extends StatelessWidget
|
||||
alertBody: getTheCorrectDialogBody(
|
||||
function,
|
||||
functionValues,
|
||||
isAutomation: false,
|
||||
),
|
||||
title: function.operationName,
|
||||
onConfirm: () {
|
||||
@ -237,6 +238,7 @@ class DeviceFunctionsView extends StatelessWidget
|
||||
alertBody: getTheCorrectDialogBody(
|
||||
function,
|
||||
automationFunctionValues,
|
||||
isAutomation: true,
|
||||
),
|
||||
title: function.operationName,
|
||||
onConfirm: () {
|
||||
|
@ -11,10 +11,12 @@ class AlertDialogFunctionsOperationsBody extends StatefulWidget {
|
||||
super.key,
|
||||
this.functionValue,
|
||||
required this.taskItem,
|
||||
required this.isAutomation,
|
||||
});
|
||||
|
||||
dynamic functionValue;
|
||||
final SceneStaticFunction taskItem;
|
||||
final bool isAutomation;
|
||||
|
||||
@override
|
||||
State<AlertDialogFunctionsOperationsBody> createState() =>
|
||||
@ -26,25 +28,46 @@ class _AlertDialogFunctionsOperationsBodyState
|
||||
@override
|
||||
didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
|
||||
final tempTaskList = context.read<CreateSceneBloc>().tempTasksList;
|
||||
if (widget.isAutomation) {
|
||||
final automationTempTasksList =
|
||||
context.read<CreateSceneBloc>().automationTempTasksList;
|
||||
|
||||
if (tempTaskList.isNotEmpty) {
|
||||
for (var element in tempTaskList) {
|
||||
if (element.code == widget.taskItem.code) {
|
||||
groupValue = element.functionValue;
|
||||
} else {
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(RemoveFromSelectedValueById(code: widget.taskItem.code));
|
||||
if (automationTempTasksList.isNotEmpty) {
|
||||
for (var element in automationTempTasksList) {
|
||||
if (element.code == widget.taskItem.code) {
|
||||
groupValue = element.functionValue;
|
||||
} else {
|
||||
context.read<CreateSceneBloc>().add(RemoveFromSelectedValueById(
|
||||
code: widget.taskItem.code, isAutomation: widget.isAutomation));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (widget.functionValue != null) {
|
||||
setState(() {
|
||||
groupValue = widget.functionValue;
|
||||
});
|
||||
if (widget.functionValue != null) {
|
||||
setState(() {
|
||||
groupValue = widget.functionValue;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
final tempTaskList = context.read<CreateSceneBloc>().tempTasksList;
|
||||
|
||||
if (tempTaskList.isNotEmpty) {
|
||||
for (var element in tempTaskList) {
|
||||
if (element.code == widget.taskItem.code) {
|
||||
groupValue = element.functionValue;
|
||||
} else {
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(RemoveFromSelectedValueById(code: widget.taskItem.code));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (widget.functionValue != null) {
|
||||
setState(() {
|
||||
groupValue = widget.functionValue;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,7 +100,9 @@ class _AlertDialogFunctionsOperationsBodyState
|
||||
groupValue = value;
|
||||
});
|
||||
context.read<CreateSceneBloc>().add(SelectedValueEvent(
|
||||
value: value!, code: widget.taskItem.code));
|
||||
value: value!,
|
||||
code: widget.taskItem.code,
|
||||
isAutomation: widget.isAutomation));
|
||||
},
|
||||
),
|
||||
onPressed: () {
|
||||
@ -85,7 +110,9 @@ class _AlertDialogFunctionsOperationsBodyState
|
||||
groupValue = operation.value;
|
||||
});
|
||||
context.read<CreateSceneBloc>().add(SelectedValueEvent(
|
||||
value: groupValue, code: widget.taskItem.code));
|
||||
value: groupValue,
|
||||
code: widget.taskItem.code,
|
||||
isAutomation: widget.isAutomation));
|
||||
},
|
||||
);
|
||||
},
|
||||
|
@ -11,10 +11,12 @@ class AlertDialogSliderSteps extends StatefulWidget {
|
||||
super.key,
|
||||
this.functionValue,
|
||||
required this.taskItem,
|
||||
required this.isAutomation,
|
||||
});
|
||||
|
||||
final dynamic functionValue;
|
||||
final SceneStaticFunction taskItem;
|
||||
final bool isAutomation;
|
||||
|
||||
@override
|
||||
State<AlertDialogSliderSteps> createState() => _AlertDialogSliderStepsState();
|
||||
@ -27,24 +29,27 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final tempTaskList = context.read<CreateSceneBloc>().tempTasksList;
|
||||
if (tempTaskList.isNotEmpty) {
|
||||
for (var element in tempTaskList) {
|
||||
if (element.code == widget.taskItem.code) {
|
||||
groupValue = element.functionValue;
|
||||
} else {
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(RemoveFromSelectedValueById(code: widget.taskItem.code));
|
||||
|
||||
if (widget.isAutomation) {
|
||||
final automationTempTaskList =
|
||||
context.read<CreateSceneBloc>().automationTempTasksList;
|
||||
if (automationTempTaskList.isNotEmpty) {
|
||||
for (var element in automationTempTaskList) {
|
||||
if (element.code == widget.taskItem.code) {
|
||||
groupValue = element.functionValue;
|
||||
} else {
|
||||
context.read<CreateSceneBloc>().add(RemoveFromSelectedValueById(
|
||||
code: widget.taskItem.code, isAutomation: widget.isAutomation));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (widget.functionValue != null) {
|
||||
setState(() {
|
||||
groupValue = widget.functionValue;
|
||||
});
|
||||
} else {
|
||||
groupValue = widget.taskItem.operationalValues[0].minValue;
|
||||
if (widget.functionValue != null) {
|
||||
setState(() {
|
||||
groupValue = widget.functionValue;
|
||||
});
|
||||
} else {
|
||||
groupValue = widget.taskItem.operationalValues[0].minValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,8 +159,12 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
|
||||
: null,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
groupValue = value;
|
||||
groupValue = value.round().toDouble();
|
||||
});
|
||||
context.read<CreateSceneBloc>().add(SelectedValueEvent(
|
||||
value: groupValue,
|
||||
code: widget.taskItem.code,
|
||||
isAutomation: widget.isAutomation));
|
||||
},
|
||||
),
|
||||
),
|
||||
|
@ -14,14 +14,10 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
class AlertDialogTemperatureBody extends StatefulWidget {
|
||||
AlertDialogTemperatureBody({
|
||||
super.key,
|
||||
//required this.index,
|
||||
// required this.functions,
|
||||
this.functionValue,
|
||||
required this.taskItem,
|
||||
});
|
||||
|
||||
//final List<SceneStaticFunction> functions;
|
||||
// final int index;
|
||||
final SceneStaticFunction taskItem;
|
||||
dynamic functionValue;
|
||||
|
||||
@ -32,14 +28,16 @@ class AlertDialogTemperatureBody extends StatefulWidget {
|
||||
|
||||
class _AlertDialogTemperatureBodyState
|
||||
extends State<AlertDialogTemperatureBody> {
|
||||
int temperature = 24;
|
||||
|
||||
@override
|
||||
didChangeDependencies() {
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final tempTaskList = context.read<CreateSceneBloc>().tempTasksList;
|
||||
|
||||
for (var element in tempTaskList) {
|
||||
if (element.code == widget.taskItem.code) {
|
||||
temperature = element.functionValue;
|
||||
temperature = _normalizeTemperature(element.functionValue);
|
||||
} else {
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
@ -48,12 +46,18 @@ class _AlertDialogTemperatureBodyState
|
||||
}
|
||||
if (widget.functionValue != null) {
|
||||
setState(() {
|
||||
temperature = widget.functionValue;
|
||||
temperature = _normalizeTemperature(widget.functionValue);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
int temperature = 24;
|
||||
int _normalizeTemperature(dynamic value) {
|
||||
if (value is int && value >= 100) {
|
||||
return value ~/ 10;
|
||||
}
|
||||
return value as int? ?? 24;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
@ -98,8 +102,7 @@ class _AlertDialogTemperatureBodyState
|
||||
],
|
||||
),
|
||||
subtitle: BodyLarge(
|
||||
text: widget.taskItem.operationalValues[0].description
|
||||
.toString(),
|
||||
text: widget.taskItem.operationalValues[0].description.toString(),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
trailing: IconButton(
|
||||
@ -110,8 +113,7 @@ class _AlertDialogTemperatureBodyState
|
||||
}
|
||||
});
|
||||
context.read<CreateSceneBloc>().add(SelectedValueEvent(
|
||||
value: temperature * 10,
|
||||
code: widget.taskItem.code));
|
||||
value: temperature * 10, code: widget.taskItem.code));
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
|
@ -34,7 +34,7 @@ class ThenAddedTasksContainer extends StatelessWidget
|
||||
Widget build(BuildContext context) {
|
||||
final createSceneBloc = context.read<CreateSceneBloc>();
|
||||
String operationValue = '';
|
||||
if (taskItem.code.contains('countdown') ||
|
||||
if ((taskItem.code.contains('countdown') && isAutomation != true) ||
|
||||
taskItem.deviceId.contains('delay')) {
|
||||
final functionValue =
|
||||
taskItem.functionValue ?? taskItem.operationalValues.first.value;
|
||||
@ -64,7 +64,8 @@ class ThenAddedTasksContainer extends StatelessWidget
|
||||
|
||||
/// show alert dialog based on type
|
||||
context.customAlertDialog(
|
||||
alertBody: getTheCorrectDialogBody(functionOperation.first, null),
|
||||
alertBody: getTheCorrectDialogBody(functionOperation.first, null,
|
||||
isAutomation: isAutomation ?? false),
|
||||
title: functionOperation.first.operationName,
|
||||
onConfirm: () {
|
||||
final savedCode = functionOperation.first.deviceId.contains('delay')
|
||||
|
@ -2,8 +2,8 @@ import 'package:flutter/foundation.dart';
|
||||
|
||||
abstract class ApiEndpoints {
|
||||
static const String baseUrl = kReleaseMode
|
||||
? 'https://syncrow-staging.azurewebsites.net/api'
|
||||
: 'https://syncrow-dev.azurewebsites.net/api';
|
||||
? 'https://syncrow-staging.azurewebsites.net'
|
||||
: 'https://syncrow-dev.azurewebsites.net';
|
||||
// static const String baseUrl = 'http://100.107.182.63:4001'; //Localhost
|
||||
|
||||
////////////////////////////////////// Authentication ///////////////////////////////
|
||||
|
@ -12,7 +12,7 @@ class SceneApi {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.createScene,
|
||||
body: createSceneModel.toJson(),
|
||||
body: createSceneModel.toMap(),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
|
Reference in New Issue
Block a user