mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 18:54:55 +00:00
push switch autoaomtion status update
This commit is contained in:
@ -362,6 +362,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
|||||||
tasksList = List<SceneStaticFunction>.from(
|
tasksList = List<SceneStaticFunction>.from(
|
||||||
getTaskListFunctionsFromApi(
|
getTaskListFunctionsFromApi(
|
||||||
actions: response.actions, isAutomation: false));
|
actions: response.actions, isAutomation: false));
|
||||||
|
|
||||||
emit(AddSceneTask(
|
emit(AddSceneTask(
|
||||||
automationTasksList: automationTasksList,
|
automationTasksList: automationTasksList,
|
||||||
tasksList: tasksList,
|
tasksList: tasksList,
|
||||||
|
|||||||
@ -13,6 +13,7 @@ class SceneBloc extends Bloc<SceneEvent, SceneState> {
|
|||||||
on<LoadScenes>(_onLoadScenes);
|
on<LoadScenes>(_onLoadScenes);
|
||||||
on<LoadAutomation>(_onLoadAutomation);
|
on<LoadAutomation>(_onLoadAutomation);
|
||||||
on<SceneTrigger>(_onSceneTrigger);
|
on<SceneTrigger>(_onSceneTrigger);
|
||||||
|
on<UpdateAutomationStatus>(_onUpdateAutomationStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ScenesModel> scenes = [];
|
List<ScenesModel> scenes = [];
|
||||||
@ -26,7 +27,7 @@ class SceneBloc extends Bloc<SceneEvent, SceneState> {
|
|||||||
scenes = await SceneApi.getScenesByUnitId(event.unitId);
|
scenes = await SceneApi.getScenesByUnitId(event.unitId);
|
||||||
emit(SceneLoaded(scenes, automationList));
|
emit(SceneLoaded(scenes, automationList));
|
||||||
} else {
|
} else {
|
||||||
const SceneError(message: '');
|
emit(const SceneError(message: 'Unit ID is empty'));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(const SceneError(message: 'Something went wrong'));
|
emit(const SceneError(message: 'Something went wrong'));
|
||||||
@ -53,8 +54,11 @@ class SceneBloc extends Bloc<SceneEvent, SceneState> {
|
|||||||
SceneTrigger event, Emitter<SceneState> emit) async {
|
SceneTrigger event, Emitter<SceneState> emit) async {
|
||||||
final currentState = state;
|
final currentState = state;
|
||||||
if (currentState is SceneLoaded) {
|
if (currentState is SceneLoaded) {
|
||||||
emit(SceneLoaded(currentState.scenes, currentState.automationList,
|
emit(SceneLoaded(
|
||||||
loadingSceneId: event.sceneId));
|
currentState.scenes,
|
||||||
|
currentState.automationList,
|
||||||
|
loadingSceneId: event.sceneId,
|
||||||
|
));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final success = await SceneApi.triggerScene(event.sceneId);
|
final success = await SceneApi.triggerScene(event.sceneId);
|
||||||
@ -69,4 +73,39 @@ class SceneBloc extends Bloc<SceneEvent, SceneState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _onUpdateAutomationStatus(
|
||||||
|
UpdateAutomationStatus event, Emitter<SceneState> emit) async {
|
||||||
|
final currentState = state;
|
||||||
|
if (currentState is SceneLoaded) {
|
||||||
|
final newLoadingStates =
|
||||||
|
Map<String, bool>.from(currentState.loadingStates)
|
||||||
|
..[event.automationId] = true;
|
||||||
|
|
||||||
|
emit(SceneLoaded(
|
||||||
|
currentState.scenes,
|
||||||
|
currentState.automationList,
|
||||||
|
loadingStates: newLoadingStates,
|
||||||
|
));
|
||||||
|
|
||||||
|
try {
|
||||||
|
final success = await SceneApi.updateAutomationStatus(
|
||||||
|
event.automationId, event.automationStatusUpdate);
|
||||||
|
if (success) {
|
||||||
|
automationList = await SceneApi.getAutomationByUnitId(
|
||||||
|
event.automationStatusUpdate.unitUuid);
|
||||||
|
newLoadingStates[event.automationId] = false;
|
||||||
|
emit(SceneLoaded(
|
||||||
|
currentState.scenes,
|
||||||
|
automationList,
|
||||||
|
loadingStates: newLoadingStates,
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
emit(const SceneError(message: 'Something went wrong'));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
emit(const SceneError(message: 'Something went wrong'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/update_automation.dart';
|
||||||
|
|
||||||
abstract class SceneEvent extends Equatable {
|
abstract class SceneEvent extends Equatable {
|
||||||
const SceneEvent();
|
const SceneEvent();
|
||||||
@ -34,3 +35,15 @@ class SceneTrigger extends SceneEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [sceneId];
|
List<Object> get props => [sceneId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//updateAutomationStatus
|
||||||
|
class UpdateAutomationStatus extends SceneEvent {
|
||||||
|
final String automationId;
|
||||||
|
final AutomationStatusUpdate automationStatusUpdate;
|
||||||
|
|
||||||
|
const UpdateAutomationStatus(
|
||||||
|
{required this.automationStatusUpdate, required this.automationId});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [automationStatusUpdate];
|
||||||
|
}
|
||||||
|
|||||||
@ -15,11 +15,14 @@ class SceneLoaded extends SceneState {
|
|||||||
final List<ScenesModel> scenes;
|
final List<ScenesModel> scenes;
|
||||||
final List<ScenesModel> automationList;
|
final List<ScenesModel> automationList;
|
||||||
final String? loadingSceneId;
|
final String? loadingSceneId;
|
||||||
|
final Map<String, bool> loadingStates;
|
||||||
|
|
||||||
const SceneLoaded(this.scenes, this.automationList, {this.loadingSceneId});
|
const SceneLoaded(this.scenes, this.automationList,
|
||||||
|
{this.loadingSceneId, this.loadingStates = const {}});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [scenes, loadingSceneId, automationList];
|
List<Object?> get props =>
|
||||||
|
[scenes, loadingSceneId, automationList, loadingStates];
|
||||||
}
|
}
|
||||||
|
|
||||||
class SceneError extends SceneState {
|
class SceneError extends SceneState {
|
||||||
@ -39,3 +42,7 @@ class SceneTriggerSuccess extends SceneState {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [sceneName];
|
List<Object> get props => [sceneName];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UpdateAutomationStatusLoading extends SceneState {
|
||||||
|
const UpdateAutomationStatusLoading();
|
||||||
|
}
|
||||||
|
|||||||
@ -66,36 +66,40 @@ mixin SceneLogicHelper {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
actions: List.generate(
|
actions: [
|
||||||
actions.length,
|
...List.generate(
|
||||||
(index) {
|
actions.length,
|
||||||
final task = actions[index];
|
(index) {
|
||||||
if (task.deviceId == 'delay') {
|
final task = actions[index];
|
||||||
|
if (task.deviceId == 'delay') {
|
||||||
|
return CreateSceneAction(
|
||||||
|
entityId: actions[index].deviceId,
|
||||||
|
actionExecutor: 'delay',
|
||||||
|
executorProperty: CreateSceneExecutorProperty(
|
||||||
|
functionCode: '',
|
||||||
|
functionValue: '',
|
||||||
|
delaySeconds: task.functionValue,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
return CreateSceneAction(
|
return CreateSceneAction(
|
||||||
entityId: actions[index].deviceId,
|
entityId: task.deviceId,
|
||||||
actionExecutor: 'delay',
|
actionExecutor: 'device_issue',
|
||||||
executorProperty: CreateSceneExecutorProperty(
|
executorProperty: CreateSceneExecutorProperty(
|
||||||
functionCode: '',
|
functionCode: task.code,
|
||||||
functionValue: '',
|
functionValue: task.functionValue,
|
||||||
delaySeconds: task.functionValue,
|
delaySeconds: 0,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
return CreateSceneAction(
|
),
|
||||||
entityId: task.deviceId,
|
if (smartSceneBloc.smartSceneEnable != null)
|
||||||
actionExecutor: 'device_issue',
|
CreateSceneAction(
|
||||||
executorProperty: CreateSceneExecutorProperty(
|
entityId: smartSceneBloc.smartSceneEnable?.entityId ?? '',
|
||||||
functionCode: task.code,
|
actionExecutor:
|
||||||
functionValue: task.functionValue,
|
smartSceneBloc.smartSceneEnable?.actionExecutor ?? '',
|
||||||
delaySeconds: 0,
|
executorProperty: null)
|
||||||
),
|
],
|
||||||
);
|
|
||||||
},
|
|
||||||
)..add(CreateSceneAction(
|
|
||||||
entityId: smartSceneBloc.smartSceneEnable?.entityId ?? '',
|
|
||||||
actionExecutor:
|
|
||||||
smartSceneBloc.smartSceneEnable?.actionExecutor ?? '',
|
|
||||||
executorProperty: null)),
|
|
||||||
);
|
);
|
||||||
sceneBloc.add(CreateSceneWithTasksEvent(
|
sceneBloc.add(CreateSceneWithTasksEvent(
|
||||||
createSceneModel: null,
|
createSceneModel: null,
|
||||||
@ -121,36 +125,40 @@ mixin SceneLogicHelper {
|
|||||||
unitUuid: HomeCubit.getInstance().selectedSpace!.id ?? '',
|
unitUuid: HomeCubit.getInstance().selectedSpace!.id ?? '',
|
||||||
sceneName: sceneName.text,
|
sceneName: sceneName.text,
|
||||||
decisionExpr: 'and',
|
decisionExpr: 'and',
|
||||||
actions: List.generate(
|
actions: [
|
||||||
actions.length,
|
...List.generate(
|
||||||
(index) {
|
actions.length,
|
||||||
final task = actions[index];
|
(index) {
|
||||||
if (task.deviceId == 'delay') {
|
final task = actions[index];
|
||||||
|
if (task.deviceId == 'delay') {
|
||||||
|
return CreateSceneAction(
|
||||||
|
entityId: actions[index].deviceId,
|
||||||
|
actionExecutor: 'delay',
|
||||||
|
executorProperty: CreateSceneExecutorProperty(
|
||||||
|
functionCode: '',
|
||||||
|
functionValue: '',
|
||||||
|
delaySeconds: task.functionValue,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
return CreateSceneAction(
|
return CreateSceneAction(
|
||||||
entityId: actions[index].deviceId,
|
entityId: task.deviceId,
|
||||||
actionExecutor: 'delay',
|
actionExecutor: 'device_issue',
|
||||||
executorProperty: CreateSceneExecutorProperty(
|
executorProperty: CreateSceneExecutorProperty(
|
||||||
functionCode: '',
|
functionCode: task.code,
|
||||||
functionValue: '',
|
functionValue: task.functionValue,
|
||||||
delaySeconds: task.functionValue,
|
delaySeconds: 0,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
return CreateSceneAction(
|
),
|
||||||
entityId: task.deviceId,
|
if (smartSceneBloc.smartSceneEnable != null)
|
||||||
actionExecutor: 'device_issue',
|
CreateSceneAction(
|
||||||
executorProperty: CreateSceneExecutorProperty(
|
entityId: smartSceneBloc.smartSceneEnable?.entityId ?? '',
|
||||||
functionCode: task.code,
|
actionExecutor:
|
||||||
functionValue: task.functionValue,
|
smartSceneBloc.smartSceneEnable?.actionExecutor ?? '',
|
||||||
delaySeconds: 0,
|
executorProperty: null)
|
||||||
),
|
],
|
||||||
);
|
|
||||||
},
|
|
||||||
)..add(CreateSceneAction(
|
|
||||||
entityId: smartSceneBloc.smartSceneEnable?.entityId ?? '',
|
|
||||||
actionExecutor:
|
|
||||||
smartSceneBloc.smartSceneEnable?.actionExecutor ?? '',
|
|
||||||
executorProperty: null)),
|
|
||||||
);
|
);
|
||||||
sceneBloc.add(CreateSceneWithTasksEvent(
|
sceneBloc.add(CreateSceneWithTasksEvent(
|
||||||
createSceneModel: createSceneModel,
|
createSceneModel: createSceneModel,
|
||||||
|
|||||||
@ -32,11 +32,15 @@ class SceneDetailsModel {
|
|||||||
name: json["name"],
|
name: json["name"],
|
||||||
status: json["status"],
|
status: json["status"],
|
||||||
type: json["type"],
|
type: json["type"],
|
||||||
actions:
|
actions: (json["actions"] as List)
|
||||||
List<Action>.from(json["actions"].map((x) => Action.fromJson(x))),
|
.map((x) => Action.fromJson(x))
|
||||||
|
.where((x) => x != null)
|
||||||
|
.toList()
|
||||||
|
.cast<Action>(),
|
||||||
conditions: json["conditions"] != null
|
conditions: json["conditions"] != null
|
||||||
? List<Condition>.from(
|
? (json["conditions"] as List)
|
||||||
json["conditions"].map((x) => Condition.fromJson(x)))
|
.map((x) => Condition.fromJson(x))
|
||||||
|
.toList()
|
||||||
: null,
|
: null,
|
||||||
decisionExpr: json["decisionExpr"],
|
decisionExpr: json["decisionExpr"],
|
||||||
effectiveTime: json["effectiveTime"] != null
|
effectiveTime: json["effectiveTime"] != null
|
||||||
@ -69,15 +73,19 @@ class Action {
|
|||||||
required this.executorProperty,
|
required this.executorProperty,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory Action.fromRawJson(String str) => Action.fromJson(json.decode(str));
|
|
||||||
|
|
||||||
String toRawJson() => json.encode(toJson());
|
String toRawJson() => json.encode(toJson());
|
||||||
|
|
||||||
factory Action.fromJson(Map<String, dynamic> json) => Action(
|
static Action? fromJson(Map<String, dynamic> json) {
|
||||||
actionExecutor: json["actionExecutor"],
|
if (json["executorProperty"] == null) {
|
||||||
entityId: json["entityId"],
|
return null; // Return null if executorProperty is not present
|
||||||
executorProperty: ExecutorProperty.fromJson(json["executorProperty"]),
|
}
|
||||||
);
|
|
||||||
|
return Action(
|
||||||
|
actionExecutor: json["actionExecutor"],
|
||||||
|
entityId: json["entityId"],
|
||||||
|
executorProperty: ExecutorProperty.fromJson(json["executorProperty"]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
"actionExecutor": actionExecutor,
|
"actionExecutor": actionExecutor,
|
||||||
|
|||||||
38
lib/features/scene/model/update_automation.dart
Normal file
38
lib/features/scene/model/update_automation.dart
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
class AutomationStatusUpdate {
|
||||||
|
final String unitUuid;
|
||||||
|
final bool isEnable;
|
||||||
|
|
||||||
|
AutomationStatusUpdate({
|
||||||
|
required this.unitUuid,
|
||||||
|
required this.isEnable,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory AutomationStatusUpdate.fromRawJson(String str) =>
|
||||||
|
AutomationStatusUpdate.fromJson(json.decode(str));
|
||||||
|
|
||||||
|
String toRawJson() => json.encode(toJson());
|
||||||
|
|
||||||
|
factory AutomationStatusUpdate.fromJson(Map<String, dynamic> json) =>
|
||||||
|
AutomationStatusUpdate(
|
||||||
|
unitUuid: json["unitUuid"],
|
||||||
|
isEnable: json["isEnable"],
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
"unitUuid": unitUuid,
|
||||||
|
"isEnable": isEnable,
|
||||||
|
};
|
||||||
|
|
||||||
|
factory AutomationStatusUpdate.fromMap(Map<String, dynamic> map) =>
|
||||||
|
AutomationStatusUpdate(
|
||||||
|
unitUuid: map["unitUuid"],
|
||||||
|
isEnable: map["isEnable"],
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() => {
|
||||||
|
"unitUuid": unitUuid,
|
||||||
|
"isEnable": isEnable,
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -98,7 +98,9 @@ class SceneView extends StatelessWidget {
|
|||||||
scenes: scenes,
|
scenes: scenes,
|
||||||
loadingSceneId:
|
loadingSceneId:
|
||||||
state.loadingSceneId,
|
state.loadingSceneId,
|
||||||
disablePLayButton: false,
|
disablePlayButton: false,
|
||||||
|
loadingStates: state
|
||||||
|
.loadingStates, // Add this line
|
||||||
)
|
)
|
||||||
: const Center(
|
: const Center(
|
||||||
child: BodyMedium(
|
child: BodyMedium(
|
||||||
@ -129,7 +131,9 @@ class SceneView extends StatelessWidget {
|
|||||||
scenes: automationList,
|
scenes: automationList,
|
||||||
loadingSceneId:
|
loadingSceneId:
|
||||||
state.loadingSceneId,
|
state.loadingSceneId,
|
||||||
disablePLayButton: true,
|
disablePlayButton: true,
|
||||||
|
loadingStates: state
|
||||||
|
.loadingStates, // Add this line
|
||||||
)
|
)
|
||||||
: const Center(
|
: const Center(
|
||||||
child: BodyMedium(
|
child: BodyMedium(
|
||||||
|
|||||||
@ -4,12 +4,15 @@ import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_item.
|
|||||||
class SceneGrid extends StatelessWidget {
|
class SceneGrid extends StatelessWidget {
|
||||||
final List<dynamic> scenes;
|
final List<dynamic> scenes;
|
||||||
final String? loadingSceneId;
|
final String? loadingSceneId;
|
||||||
final bool disablePLayButton;
|
final bool disablePlayButton;
|
||||||
|
final Map<String, bool> loadingStates;
|
||||||
|
|
||||||
const SceneGrid({
|
const SceneGrid({
|
||||||
required this.scenes,
|
required this.scenes,
|
||||||
required this.loadingSceneId,
|
required this.loadingSceneId,
|
||||||
|
required this.disablePlayButton,
|
||||||
|
required this.loadingStates,
|
||||||
super.key,
|
super.key,
|
||||||
required this.disablePLayButton,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -27,10 +30,14 @@ class SceneGrid extends StatelessWidget {
|
|||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final scene = scenes[index];
|
final scene = scenes[index];
|
||||||
final isLoading = loadingSceneId == scene.id;
|
final isLoading = loadingSceneId == scene.id;
|
||||||
|
final isSwitchLoading = loadingStates[scene.id] ?? false;
|
||||||
|
|
||||||
return SceneItem(
|
return SceneItem(
|
||||||
scene: scene,
|
scene: scene,
|
||||||
isLoading: isLoading,
|
isLoading: isLoading,
|
||||||
disablePLayButton: disablePLayButton);
|
disablePlayButton: disablePlayButton,
|
||||||
|
isSwitchLoading: isSwitchLoading,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,14 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
|
||||||
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
||||||
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
||||||
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
||||||
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
|
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/update_automation.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||||
|
|
||||||
@ -16,13 +19,15 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
|||||||
class SceneItem extends StatelessWidget {
|
class SceneItem extends StatelessWidget {
|
||||||
final ScenesModel scene;
|
final ScenesModel scene;
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
final bool disablePLayButton;
|
final bool isSwitchLoading;
|
||||||
|
final bool disablePlayButton;
|
||||||
|
|
||||||
const SceneItem({
|
const SceneItem({
|
||||||
required this.scene,
|
required this.scene,
|
||||||
required this.isLoading,
|
required this.isLoading,
|
||||||
super.key,
|
super.key,
|
||||||
required this.disablePLayButton,
|
required this.disablePlayButton,
|
||||||
|
required this.isSwitchLoading,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -33,14 +38,14 @@ class SceneItem extends StatelessWidget {
|
|||||||
context,
|
context,
|
||||||
Routes.sceneTasksRoute,
|
Routes.sceneTasksRoute,
|
||||||
arguments: SceneSettingsRouteArguments(
|
arguments: SceneSettingsRouteArguments(
|
||||||
sceneType: disablePLayButton == false
|
sceneType: disablePlayButton == false
|
||||||
? CreateSceneEnum.tabToRun.name
|
? CreateSceneEnum.tabToRun.name
|
||||||
: CreateSceneEnum.deviceStatusChanges.name,
|
: CreateSceneEnum.deviceStatusChanges.name,
|
||||||
sceneId: scene.id,
|
sceneId: scene.id,
|
||||||
sceneName: scene.name,
|
sceneName: scene.name,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (disablePLayButton == false) {
|
if (disablePlayButton == false) {
|
||||||
BlocProvider.of<CreateSceneBloc>(context)
|
BlocProvider.of<CreateSceneBloc>(context)
|
||||||
.add(const SceneTypeEvent(CreateSceneEnum.tabToRun));
|
.add(const SceneTypeEvent(CreateSceneEnum.tabToRun));
|
||||||
BlocProvider.of<CreateSceneBloc>(context).add(
|
BlocProvider.of<CreateSceneBloc>(context).add(
|
||||||
@ -66,26 +71,45 @@ class SceneItem extends StatelessWidget {
|
|||||||
Assets.assetsIconsLogo,
|
Assets.assetsIconsLogo,
|
||||||
fit: BoxFit.fill,
|
fit: BoxFit.fill,
|
||||||
),
|
),
|
||||||
Visibility(
|
disablePlayButton == false
|
||||||
visible: disablePLayButton == false,
|
? IconButton(
|
||||||
child: IconButton(
|
padding: EdgeInsets.zero,
|
||||||
padding: EdgeInsets.zero,
|
onPressed: () {
|
||||||
onPressed: () {
|
context
|
||||||
context
|
.read<SceneBloc>()
|
||||||
.read<SceneBloc>()
|
.add(SceneTrigger(scene.id, scene.name));
|
||||||
.add(SceneTrigger(scene.id, scene.name));
|
},
|
||||||
},
|
icon: isLoading
|
||||||
icon: isLoading
|
? const Center(
|
||||||
? const Center(
|
child: CircularProgressIndicator(),
|
||||||
child: CircularProgressIndicator(),
|
)
|
||||||
|
: const Icon(
|
||||||
|
Icons.play_circle,
|
||||||
|
size: 40,
|
||||||
|
color: ColorsManager.greyColor,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: isSwitchLoading
|
||||||
|
? Center(
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
color: ColorsManager.primaryColorWithOpacity,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
: const Icon(
|
: CupertinoSwitch(
|
||||||
Icons.play_circle,
|
activeColor: ColorsManager.primaryColor,
|
||||||
size: 40,
|
value: scene.status == 'enable' ? true : false,
|
||||||
color: ColorsManager.greyColor,
|
onChanged: (value) {
|
||||||
|
context.read<SceneBloc>().add(
|
||||||
|
UpdateAutomationStatus(
|
||||||
|
automationStatusUpdate:
|
||||||
|
AutomationStatusUpdate(
|
||||||
|
isEnable: value,
|
||||||
|
unitUuid: HomeCubit.getInstance()
|
||||||
|
.selectedSpace!
|
||||||
|
.id!),
|
||||||
|
automationId: scene.id));
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
|
|||||||
@ -81,7 +81,8 @@ abstract class ApiEndpoints {
|
|||||||
static const String controlGroup = '/group/control';
|
static const String controlGroup = '/group/control';
|
||||||
//GET
|
//GET
|
||||||
static const String groupBySpace = '/group/{unitUuid}';
|
static const String groupBySpace = '/group/{unitUuid}';
|
||||||
static const String devicesByGroupName = '/group/{unitUuid}/devices/{groupName}';
|
static const String devicesByGroupName =
|
||||||
|
'/group/{unitUuid}/devices/{groupName}';
|
||||||
|
|
||||||
static const String groupByUuid = '/group/{groupUuid}';
|
static const String groupByUuid = '/group/{groupUuid}';
|
||||||
//DELETE
|
//DELETE
|
||||||
@ -93,7 +94,8 @@ abstract class ApiEndpoints {
|
|||||||
static const String addDeviceToRoom = '/device/room';
|
static const String addDeviceToRoom = '/device/room';
|
||||||
static const String addDeviceToGroup = '/device/group';
|
static const String addDeviceToGroup = '/device/group';
|
||||||
static const String controlDevice = '/device/{deviceUuid}/control';
|
static const String controlDevice = '/device/{deviceUuid}/control';
|
||||||
static const String firmwareDevice = '/device/{deviceUuid}/firmware/{firmwareVersion}';
|
static const String firmwareDevice =
|
||||||
|
'/device/{deviceUuid}/firmware/{firmwareVersion}';
|
||||||
static const String getDevicesByUserId = '/device/user/{userId}';
|
static const String getDevicesByUserId = '/device/user/{userId}';
|
||||||
static const String getDevicesByUnitId = '/device/unit/{unitUuid}';
|
static const String getDevicesByUnitId = '/device/unit/{unitUuid}';
|
||||||
|
|
||||||
@ -102,7 +104,8 @@ abstract class ApiEndpoints {
|
|||||||
static const String deviceByUuid = '/device/{deviceUuid}';
|
static const String deviceByUuid = '/device/{deviceUuid}';
|
||||||
static const String deviceFunctions = '/device/{deviceUuid}/functions';
|
static const String deviceFunctions = '/device/{deviceUuid}/functions';
|
||||||
static const String gatewayApi = '/device/gateway/{gatewayUuid}/devices';
|
static const String gatewayApi = '/device/gateway/{gatewayUuid}/devices';
|
||||||
static const String deviceFunctionsStatus = '/device/{deviceUuid}/functions/status';
|
static const String deviceFunctionsStatus =
|
||||||
|
'/device/{deviceUuid}/functions/status';
|
||||||
|
|
||||||
///Device Permission Module
|
///Device Permission Module
|
||||||
//POST
|
//POST
|
||||||
@ -127,22 +130,29 @@ abstract class ApiEndpoints {
|
|||||||
|
|
||||||
static const String getUnitAutomation = '/automation/{unitUuid}';
|
static const String getUnitAutomation = '/automation/{unitUuid}';
|
||||||
|
|
||||||
static const String getAutomationDetails = '/automation/details/{automationId}';
|
static const String getAutomationDetails =
|
||||||
|
'/automation/details/{automationId}';
|
||||||
|
|
||||||
/// PUT
|
/// PUT
|
||||||
static const String updateScene = '/scene/tap-to-run/{sceneId}';
|
static const String updateScene = '/scene/tap-to-run/{sceneId}';
|
||||||
|
|
||||||
static const String updateAutomation = '/automation/{automationId}';
|
static const String updateAutomation = '/automation/{automationId}';
|
||||||
|
|
||||||
|
static const String updateAutomationStatus =
|
||||||
|
'/automation/status/{automationId}';
|
||||||
|
|
||||||
/// DELETE
|
/// DELETE
|
||||||
static const String deleteScene = '/scene/tap-to-run/{unitUuid}/{sceneId}';
|
static const String deleteScene = '/scene/tap-to-run/{unitUuid}/{sceneId}';
|
||||||
|
|
||||||
static const String deleteAutomation = '/automation/{unitUuid}/{automationId}';
|
static const String deleteAutomation =
|
||||||
|
'/automation/{unitUuid}/{automationId}';
|
||||||
|
|
||||||
//////////////////////Door Lock //////////////////////
|
//////////////////////Door Lock //////////////////////
|
||||||
//online
|
//online
|
||||||
static const String addTemporaryPassword = '/door-lock/temporary-password/online/{doorLockUuid}';
|
static const String addTemporaryPassword =
|
||||||
static const String getTemporaryPassword = '/door-lock/temporary-password/online/{doorLockUuid}';
|
'/door-lock/temporary-password/online/{doorLockUuid}';
|
||||||
|
static const String getTemporaryPassword =
|
||||||
|
'/door-lock/temporary-password/online/{doorLockUuid}';
|
||||||
|
|
||||||
//one-time offline
|
//one-time offline
|
||||||
static const String addOneTimeTemporaryPassword =
|
static const String addOneTimeTemporaryPassword =
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import 'package:syncrow_app/features/scene/model/create_automation_model.dart';
|
|||||||
import 'package:syncrow_app/features/scene/model/create_scene_model.dart';
|
import 'package:syncrow_app/features/scene/model/create_scene_model.dart';
|
||||||
import 'package:syncrow_app/features/scene/model/scene_details_model.dart';
|
import 'package:syncrow_app/features/scene/model/scene_details_model.dart';
|
||||||
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/update_automation.dart';
|
||||||
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
||||||
import 'package:syncrow_app/services/api/http_service.dart';
|
import 'package:syncrow_app/services/api/http_service.dart';
|
||||||
|
|
||||||
@ -115,6 +116,22 @@ class SceneApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//updateAutomationStatus
|
||||||
|
static Future<bool> updateAutomationStatus(String automationId,
|
||||||
|
AutomationStatusUpdate createAutomationEnable) async {
|
||||||
|
try {
|
||||||
|
final response = await _httpService.put(
|
||||||
|
path: ApiEndpoints.updateAutomationStatus
|
||||||
|
.replaceAll('{automationId}', automationId),
|
||||||
|
body: createAutomationEnable.toMap(),
|
||||||
|
expectedResponseModel: (json) => json['success'],
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} catch (e) {
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//getScene
|
//getScene
|
||||||
|
|
||||||
static Future<SceneDetailsModel> getSceneDetails(String sceneId) async {
|
static Future<SceneDetailsModel> getSceneDetails(String sceneId) async {
|
||||||
|
|||||||
Reference in New Issue
Block a user