|
|
|
@ -1,9 +1,10 @@
|
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
|
|
import 'package:bloc/bloc.dart';
|
|
|
|
|
import 'package:equatable/equatable.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
|
|
|
|
import 'package:syncrow_web/pages/routines/bloc/automation_scene_trigger_bloc/automation_status_update.dart';
|
|
|
|
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
|
|
|
@ -89,8 +90,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
final updatedIfItems = List<Map<String, dynamic>>.from(state.ifItems);
|
|
|
|
|
|
|
|
|
|
// Find the index of the item in teh current itemsList
|
|
|
|
|
int index = updatedIfItems
|
|
|
|
|
.indexWhere((map) => map['uniqueCustomId'] == event.item['uniqueCustomId']);
|
|
|
|
|
int index =
|
|
|
|
|
updatedIfItems.indexWhere((map) => map['uniqueCustomId'] == event.item['uniqueCustomId']);
|
|
|
|
|
// Replace the map if the index is valid
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
updatedIfItems[index] = event.item;
|
|
|
|
@ -99,11 +100,9 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.isTabToRun) {
|
|
|
|
|
emit(state.copyWith(
|
|
|
|
|
ifItems: updatedIfItems, isTabToRun: true, isAutomation: false));
|
|
|
|
|
emit(state.copyWith(ifItems: updatedIfItems, isTabToRun: true, isAutomation: false));
|
|
|
|
|
} else {
|
|
|
|
|
emit(state.copyWith(
|
|
|
|
|
ifItems: updatedIfItems, isTabToRun: false, isAutomation: true));
|
|
|
|
|
emit(state.copyWith(ifItems: updatedIfItems, isTabToRun: false, isAutomation: true));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -111,8 +110,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
final currentItems = List<Map<String, dynamic>>.from(state.thenItems);
|
|
|
|
|
|
|
|
|
|
// Find the index of the item in teh current itemsList
|
|
|
|
|
int index = currentItems
|
|
|
|
|
.indexWhere((map) => map['uniqueCustomId'] == event.item['uniqueCustomId']);
|
|
|
|
|
int index =
|
|
|
|
|
currentItems.indexWhere((map) => map['uniqueCustomId'] == event.item['uniqueCustomId']);
|
|
|
|
|
// Replace the map if the index is valid
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
currentItems[index] = event.item;
|
|
|
|
@ -123,8 +122,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
emit(state.copyWith(thenItems: currentItems));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _onAddFunctionsToRoutine(
|
|
|
|
|
AddFunctionToRoutine event, Emitter<RoutineState> emit) {
|
|
|
|
|
void _onAddFunctionsToRoutine(AddFunctionToRoutine event, Emitter<RoutineState> emit) {
|
|
|
|
|
try {
|
|
|
|
|
if (event.functions.isEmpty) return;
|
|
|
|
|
|
|
|
|
@ -174,20 +172,17 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
|
|
|
|
var createRoutineBloc = context.read<CreateRoutineBloc>();
|
|
|
|
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
|
|
|
|
if (createRoutineBloc.selectedSpaceId == '' &&
|
|
|
|
|
createRoutineBloc.selectedCommunityId == '') {
|
|
|
|
|
if (createRoutineBloc.selectedSpaceId == '' && createRoutineBloc.selectedCommunityId == '') {
|
|
|
|
|
var spaceBloc = context.read<SpaceTreeBloc>();
|
|
|
|
|
for (var communityId in spaceBloc.state.selectedCommunities) {
|
|
|
|
|
List<String> spacesList =
|
|
|
|
|
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
|
|
|
|
List<String> spacesList = spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
|
|
|
|
for (var spaceId in spacesList) {
|
|
|
|
|
scenes
|
|
|
|
|
.addAll(await SceneApi.getScenes(spaceId, communityId, projectUuid));
|
|
|
|
|
scenes.addAll(await SceneApi.getScenes(spaceId, communityId, projectUuid));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
scenes.addAll(await SceneApi.getScenes(createRoutineBloc.selectedSpaceId,
|
|
|
|
|
createRoutineBloc.selectedCommunityId, projectUuid));
|
|
|
|
|
scenes.addAll(await SceneApi.getScenes(
|
|
|
|
|
createRoutineBloc.selectedSpaceId, createRoutineBloc.selectedCommunityId, projectUuid));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit(state.copyWith(
|
|
|
|
@ -204,8 +199,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _onLoadAutomation(
|
|
|
|
|
LoadAutomation event, Emitter<RoutineState> emit) async {
|
|
|
|
|
Future<void> _onLoadAutomation(LoadAutomation event, Emitter<RoutineState> emit) async {
|
|
|
|
|
emit(state.copyWith(isLoading: true, errorMessage: null));
|
|
|
|
|
List<ScenesModel> automations = [];
|
|
|
|
|
final projectId = await ProjectManager.getProjectUUID() ?? '';
|
|
|
|
@ -213,22 +207,17 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
|
|
|
|
var createRoutineBloc = context.read<CreateRoutineBloc>();
|
|
|
|
|
try {
|
|
|
|
|
if (createRoutineBloc.selectedSpaceId == '' &&
|
|
|
|
|
createRoutineBloc.selectedCommunityId == '') {
|
|
|
|
|
if (createRoutineBloc.selectedSpaceId == '' && createRoutineBloc.selectedCommunityId == '') {
|
|
|
|
|
var spaceBloc = context.read<SpaceTreeBloc>();
|
|
|
|
|
for (var communityId in spaceBloc.state.selectedCommunities) {
|
|
|
|
|
List<String> spacesList =
|
|
|
|
|
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
|
|
|
|
List<String> spacesList = spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
|
|
|
|
for (var spaceId in spacesList) {
|
|
|
|
|
automations.addAll(
|
|
|
|
|
await SceneApi.getAutomation(spaceId, communityId, projectId));
|
|
|
|
|
automations.addAll(await SceneApi.getAutomation(spaceId, communityId, projectId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
automations.addAll(await SceneApi.getAutomation(
|
|
|
|
|
createRoutineBloc.selectedSpaceId,
|
|
|
|
|
createRoutineBloc.selectedCommunityId,
|
|
|
|
|
projectId));
|
|
|
|
|
createRoutineBloc.selectedSpaceId, createRoutineBloc.selectedCommunityId, projectId));
|
|
|
|
|
}
|
|
|
|
|
emit(state.copyWith(
|
|
|
|
|
automations: automations,
|
|
|
|
@ -244,16 +233,14 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FutureOr<void> _onSearchRoutines(
|
|
|
|
|
SearchRoutines event, Emitter<RoutineState> emit) async {
|
|
|
|
|
FutureOr<void> _onSearchRoutines(SearchRoutines event, Emitter<RoutineState> emit) async {
|
|
|
|
|
emit(state.copyWith(isLoading: true, errorMessage: null));
|
|
|
|
|
await Future.delayed(const Duration(seconds: 1));
|
|
|
|
|
emit(state.copyWith(isLoading: false, errorMessage: null));
|
|
|
|
|
emit(state.copyWith(searchText: event.query));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FutureOr<void> _onAddSelectedIcon(
|
|
|
|
|
AddSelectedIcon event, Emitter<RoutineState> emit) {
|
|
|
|
|
FutureOr<void> _onAddSelectedIcon(AddSelectedIcon event, Emitter<RoutineState> emit) {
|
|
|
|
|
emit(state.copyWith(selectedIcon: event.icon));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -267,8 +254,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
return actions.last['deviceId'] == 'delay';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _onCreateScene(
|
|
|
|
|
CreateSceneEvent event, Emitter<RoutineState> emit) async {
|
|
|
|
|
Future<void> _onCreateScene(CreateSceneEvent event, Emitter<RoutineState> emit) async {
|
|
|
|
|
try {
|
|
|
|
|
// Check if first action is delay
|
|
|
|
|
// if (_isFirstActionDelay(state.thenItems)) {
|
|
|
|
@ -357,8 +343,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _onCreateAutomation(
|
|
|
|
|
CreateAutomationEvent event, Emitter<RoutineState> emit) async {
|
|
|
|
|
Future<void> _onCreateAutomation(CreateAutomationEvent event, Emitter<RoutineState> emit) async {
|
|
|
|
|
try {
|
|
|
|
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
|
|
|
|
if (state.routineName == null || state.routineName!.isEmpty) {
|
|
|
|
@ -471,8 +456,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
actions: actions,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final result =
|
|
|
|
|
await SceneApi.createAutomation(createAutomationModel, projectUuid);
|
|
|
|
|
final result = await SceneApi.createAutomation(createAutomationModel, projectUuid);
|
|
|
|
|
if (result['success']) {
|
|
|
|
|
add(ResetRoutineState());
|
|
|
|
|
add(const LoadAutomation());
|
|
|
|
@ -493,21 +477,17 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FutureOr<void> _onRemoveDragCard(
|
|
|
|
|
RemoveDragCard event, Emitter<RoutineState> emit) {
|
|
|
|
|
FutureOr<void> _onRemoveDragCard(RemoveDragCard event, Emitter<RoutineState> emit) {
|
|
|
|
|
if (event.isFromThen) {
|
|
|
|
|
final thenItems = List<Map<String, dynamic>>.from(state.thenItems);
|
|
|
|
|
final selectedFunctions =
|
|
|
|
|
Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
|
|
|
|
final selectedFunctions = Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
|
|
|
|
|
|
|
|
|
thenItems.removeAt(event.index);
|
|
|
|
|
selectedFunctions.remove(event.key);
|
|
|
|
|
emit(state.copyWith(
|
|
|
|
|
thenItems: thenItems, selectedFunctions: selectedFunctions));
|
|
|
|
|
emit(state.copyWith(thenItems: thenItems, selectedFunctions: selectedFunctions));
|
|
|
|
|
} else {
|
|
|
|
|
final ifItems = List<Map<String, dynamic>>.from(state.ifItems);
|
|
|
|
|
final selectedFunctions =
|
|
|
|
|
Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
|
|
|
|
final selectedFunctions = Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
|
|
|
|
|
|
|
|
|
ifItems.removeAt(event.index);
|
|
|
|
|
selectedFunctions.remove(event.key);
|
|
|
|
@ -530,13 +510,11 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FutureOr<void> _onEffectiveTimeEvent(
|
|
|
|
|
EffectiveTimePeriodEvent event, Emitter<RoutineState> emit) {
|
|
|
|
|
FutureOr<void> _onEffectiveTimeEvent(EffectiveTimePeriodEvent event, Emitter<RoutineState> emit) {
|
|
|
|
|
emit(state.copyWith(effectiveTime: event.effectiveTime));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FutureOr<void> _onSetRoutineName(
|
|
|
|
|
SetRoutineName event, Emitter<RoutineState> emit) {
|
|
|
|
|
FutureOr<void> _onSetRoutineName(SetRoutineName event, Emitter<RoutineState> emit) {
|
|
|
|
|
emit(state.copyWith(
|
|
|
|
|
routineName: event.name,
|
|
|
|
|
));
|
|
|
|
@ -663,8 +641,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
// return (thenItems, ifItems, currentFunctions);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
Future<void> _onGetSceneDetails(
|
|
|
|
|
GetSceneDetails event, Emitter<RoutineState> emit) async {
|
|
|
|
|
Future<void> _onGetSceneDetails(GetSceneDetails event, Emitter<RoutineState> emit) async {
|
|
|
|
|
try {
|
|
|
|
|
emit(state.copyWith(
|
|
|
|
|
isLoading: true,
|
|
|
|
@ -713,10 +690,9 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
deviceCards[deviceId] = {
|
|
|
|
|
'entityId': action.entityId,
|
|
|
|
|
'deviceId': action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
|
|
|
|
'uniqueCustomId':
|
|
|
|
|
action.type == 'automation' || action.actionExecutor == 'delay'
|
|
|
|
|
? action.entityId
|
|
|
|
|
: const Uuid().v4(),
|
|
|
|
|
'uniqueCustomId': action.type == 'automation' || action.actionExecutor == 'delay'
|
|
|
|
|
? action.entityId
|
|
|
|
|
: const Uuid().v4(),
|
|
|
|
|
'title': action.actionExecutor == 'delay'
|
|
|
|
|
? 'Delay'
|
|
|
|
|
: action.type == 'automation'
|
|
|
|
@ -756,8 +732,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
// emit(state.copyWith(automationActionExecutor: action.actionExecutor));
|
|
|
|
|
} else if (action.executorProperty != null &&
|
|
|
|
|
action.actionExecutor != 'delay') {
|
|
|
|
|
} else if (action.executorProperty != null && action.actionExecutor != 'delay') {
|
|
|
|
|
final functions = matchingDevice?.functions ?? [];
|
|
|
|
|
final functionCode = action.executorProperty?.functionCode;
|
|
|
|
|
for (DeviceFunction function in functions) {
|
|
|
|
@ -823,8 +798,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FutureOr<void> _onResetRoutineState(
|
|
|
|
|
ResetRoutineState event, Emitter<RoutineState> emit) {
|
|
|
|
|
FutureOr<void> _onResetRoutineState(ResetRoutineState event, Emitter<RoutineState> emit) {
|
|
|
|
|
emit(state.copyWith(
|
|
|
|
|
ifItems: [],
|
|
|
|
|
thenItems: [],
|
|
|
|
@ -857,8 +831,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
var spaceBloc = context.read<SpaceTreeBloc>();
|
|
|
|
|
if (state.isTabToRun) {
|
|
|
|
|
await SceneApi.deleteScene(
|
|
|
|
|
unitUuid: spaceBloc.state.selectedSpaces[0],
|
|
|
|
|
sceneId: state.sceneId ?? '');
|
|
|
|
|
unitUuid: spaceBloc.state.selectedSpaces[0], sceneId: state.sceneId ?? '');
|
|
|
|
|
} else {
|
|
|
|
|
await SceneApi.deleteAutomation(
|
|
|
|
|
unitUuid: spaceBloc.state.selectedSpaces[0],
|
|
|
|
@ -903,8 +876,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
FutureOr<void> _fetchDevices(
|
|
|
|
|
FetchDevicesInRoutine event, Emitter<RoutineState> emit) async {
|
|
|
|
|
FutureOr<void> _fetchDevices(FetchDevicesInRoutine event, Emitter<RoutineState> emit) async {
|
|
|
|
|
emit(state.copyWith(isLoading: true));
|
|
|
|
|
try {
|
|
|
|
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
|
|
|
@ -913,21 +885,17 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
var createRoutineBloc = context.read<CreateRoutineBloc>();
|
|
|
|
|
var spaceBloc = context.read<SpaceTreeBloc>();
|
|
|
|
|
|
|
|
|
|
if (createRoutineBloc.selectedSpaceId == '' &&
|
|
|
|
|
createRoutineBloc.selectedCommunityId == '') {
|
|
|
|
|
if (createRoutineBloc.selectedSpaceId == '' && createRoutineBloc.selectedCommunityId == '') {
|
|
|
|
|
for (var communityId in spaceBloc.state.selectedCommunities) {
|
|
|
|
|
List<String> spacesList =
|
|
|
|
|
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
|
|
|
|
List<String> spacesList = spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
|
|
|
|
for (var spaceId in spacesList) {
|
|
|
|
|
devices.addAll(await DevicesManagementApi()
|
|
|
|
|
.fetchDevices(communityId, spaceId, projectUuid));
|
|
|
|
|
devices.addAll(
|
|
|
|
|
await DevicesManagementApi().fetchDevices(communityId, spaceId, projectUuid));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
devices.addAll(await DevicesManagementApi().fetchDevices(
|
|
|
|
|
createRoutineBloc.selectedCommunityId,
|
|
|
|
|
createRoutineBloc.selectedSpaceId,
|
|
|
|
|
projectUuid));
|
|
|
|
|
createRoutineBloc.selectedCommunityId, createRoutineBloc.selectedSpaceId, projectUuid));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit(state.copyWith(isLoading: false, devices: devices));
|
|
|
|
@ -936,8 +904,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FutureOr<void> _onUpdateScene(
|
|
|
|
|
UpdateScene event, Emitter<RoutineState> emit) async {
|
|
|
|
|
FutureOr<void> _onUpdateScene(UpdateScene event, Emitter<RoutineState> emit) async {
|
|
|
|
|
try {
|
|
|
|
|
// Check if first action is delay
|
|
|
|
|
// if (_isFirstActionDelay(state.thenItems)) {
|
|
|
|
@ -1004,8 +971,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
actions: actions,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final result =
|
|
|
|
|
await SceneApi.updateScene(createSceneModel, state.sceneId ?? '');
|
|
|
|
|
final result = await SceneApi.updateScene(createSceneModel, state.sceneId ?? '');
|
|
|
|
|
if (result['success']) {
|
|
|
|
|
add(ResetRoutineState());
|
|
|
|
|
add(const LoadScenes());
|
|
|
|
@ -1024,8 +990,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FutureOr<void> _onUpdateAutomation(
|
|
|
|
|
UpdateAutomation event, Emitter<RoutineState> emit) async {
|
|
|
|
|
FutureOr<void> _onUpdateAutomation(UpdateAutomation event, Emitter<RoutineState> emit) async {
|
|
|
|
|
try {
|
|
|
|
|
if (state.routineName == null || state.routineName!.isEmpty) {
|
|
|
|
|
emit(state.copyWith(
|
|
|
|
@ -1141,8 +1106,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
|
|
|
|
|
if (result['success']) {
|
|
|
|
|
add(ResetRoutineState());
|
|
|
|
|
add(const LoadAutomation());
|
|
|
|
|
add(const LoadScenes());
|
|
|
|
|
add(LoadAutomation());
|
|
|
|
|
add(LoadScenes());
|
|
|
|
|
} else {
|
|
|
|
|
emit(state.copyWith(
|
|
|
|
|
isLoading: false,
|
|
|
|
@ -1326,13 +1291,10 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final ifItems =
|
|
|
|
|
deviceIfCards.values.where((card) => card['type'] == 'condition').toList();
|
|
|
|
|
final ifItems = deviceIfCards.values.where((card) => card['type'] == 'condition').toList();
|
|
|
|
|
final thenItems = deviceThenCards.values
|
|
|
|
|
.where((card) =>
|
|
|
|
|
card['type'] == 'action' ||
|
|
|
|
|
card['type'] == 'automation' ||
|
|
|
|
|
card['type'] == 'scene')
|
|
|
|
|
card['type'] == 'action' || card['type'] == 'automation' || card['type'] == 'scene')
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
emit(state.copyWith(
|
|
|
|
@ -1354,8 +1316,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _onSceneTrigger(
|
|
|
|
|
SceneTrigger event, Emitter<RoutineState> emit) async {
|
|
|
|
|
Future<void> _onSceneTrigger(SceneTrigger event, Emitter<RoutineState> emit) async {
|
|
|
|
|
emit(state.copyWith(loadingSceneId: event.sceneId));
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
@ -1400,24 +1361,21 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|
|
|
|
event.automationStatusUpdate.spaceUuid, event.communityId, projectId);
|
|
|
|
|
|
|
|
|
|
// Remove from loading set safely
|
|
|
|
|
final updatedLoadingIds = {...state.loadingAutomationIds!}
|
|
|
|
|
..remove(event.automationId);
|
|
|
|
|
final updatedLoadingIds = {...state.loadingAutomationIds!}..remove(event.automationId);
|
|
|
|
|
|
|
|
|
|
emit(state.copyWith(
|
|
|
|
|
automations: updatedAutomations,
|
|
|
|
|
loadingAutomationIds: updatedLoadingIds,
|
|
|
|
|
));
|
|
|
|
|
} else {
|
|
|
|
|
final updatedLoadingIds = {...state.loadingAutomationIds!}
|
|
|
|
|
..remove(event.automationId);
|
|
|
|
|
final updatedLoadingIds = {...state.loadingAutomationIds!}..remove(event.automationId);
|
|
|
|
|
emit(state.copyWith(
|
|
|
|
|
loadingAutomationIds: updatedLoadingIds,
|
|
|
|
|
errorMessage: 'Update failed',
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
final updatedLoadingIds = {...state.loadingAutomationIds!}
|
|
|
|
|
..remove(event.automationId);
|
|
|
|
|
final updatedLoadingIds = {...state.loadingAutomationIds!}..remove(event.automationId);
|
|
|
|
|
emit(state.copyWith(
|
|
|
|
|
loadingAutomationIds: updatedLoadingIds,
|
|
|
|
|
errorMessage: 'Update error: ${e.toString()}',
|
|
|
|
|