mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-26 08:34:56 +00:00
Merge pull request #42 from SyncrowIOT/automation_fixes2
Automation fixes2
This commit is contained in:
@ -63,8 +63,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
|
||||
Future fetchUserInfo() async {
|
||||
try {
|
||||
var uuid =
|
||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||
var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||
user = await ProfileApi().fetchUserInfo(uuid);
|
||||
emit(HomeUserInfoLoaded(user!)); // Emit state after fetching user info
|
||||
} catch (e) {
|
||||
@ -85,12 +84,9 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
selectedSpace = null;
|
||||
selectedRoom = null;
|
||||
pageIndex = 0;
|
||||
OneSignal.User.pushSubscription
|
||||
.removeObserver((stateChanges) => oneSignalSubscriptionObserver);
|
||||
OneSignal.Notifications.removePermissionObserver(
|
||||
(permission) => oneSignalPermissionObserver);
|
||||
OneSignal.Notifications.removeClickListener(
|
||||
(event) => oneSignalClickListenerObserver);
|
||||
OneSignal.User.pushSubscription.removeObserver((stateChanges) => oneSignalSubscriptionObserver);
|
||||
OneSignal.Notifications.removePermissionObserver((permission) => oneSignalPermissionObserver);
|
||||
OneSignal.Notifications.removeClickListener((event) => oneSignalClickListenerObserver);
|
||||
return super.close();
|
||||
}
|
||||
|
||||
@ -132,9 +128,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
return;
|
||||
}
|
||||
|
||||
var userUuid =
|
||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ??
|
||||
'';
|
||||
var userUuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ?? '';
|
||||
if (userUuid.isNotEmpty) {
|
||||
await OneSignal.login(userUuid);
|
||||
}
|
||||
@ -142,24 +136,21 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
await OneSignal.User.pushSubscription.optIn();
|
||||
|
||||
//this function will be called once a user is subscribed
|
||||
oneSignalSubscriptionObserver =
|
||||
OneSignal.User.pushSubscription.addObserver((state) async {
|
||||
oneSignalSubscriptionObserver = OneSignal.User.pushSubscription.addObserver((state) async {
|
||||
if (state.current.optedIn) {
|
||||
await _sendSubscriptionId();
|
||||
}
|
||||
});
|
||||
|
||||
// Send the player id when a user allows notifications
|
||||
oneSignalPermissionObserver =
|
||||
OneSignal.Notifications.addPermissionObserver((state) async {
|
||||
oneSignalPermissionObserver = OneSignal.Notifications.addPermissionObserver((state) async {
|
||||
await _sendSubscriptionId();
|
||||
});
|
||||
|
||||
//check if the player id is sent, if not send it again
|
||||
await _sendSubscriptionId();
|
||||
|
||||
oneSignalClickListenerObserver =
|
||||
OneSignal.Notifications.addClickListener((event) async {
|
||||
oneSignalClickListenerObserver = OneSignal.Notifications.addClickListener((event) async {
|
||||
//Once the user clicks on the notification
|
||||
});
|
||||
} catch (err) {
|
||||
@ -246,9 +237,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
|
||||
Future<bool> joinAUnit(String code) async {
|
||||
try {
|
||||
var uuid =
|
||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ??
|
||||
'';
|
||||
var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey) ?? '';
|
||||
Map<String, String> body = {'userUuid': uuid, 'inviteCode': code};
|
||||
|
||||
final success = await SpacesAPI.joinUnit(body);
|
||||
@ -360,50 +349,47 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
// ),
|
||||
// onPressed: () {},
|
||||
// ),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
size: 32,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
WidgetStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(
|
||||
NavigationService.navigatorKey.currentContext!,
|
||||
Routes.sceneTasksRoute,
|
||||
arguments: SceneSettingsRouteArguments(
|
||||
sceneType: '',
|
||||
sceneId: '',
|
||||
sceneName: '',
|
||||
),
|
||||
);
|
||||
NavigationService.navigatorKey.currentContext!
|
||||
.read<CreateSceneBloc>()
|
||||
.add(const ClearTaskListEvent());
|
||||
NavigationService.navigatorKey.currentContext!
|
||||
.read<CreateSceneBloc>()
|
||||
.add(const SceneTypeEvent(CreateSceneEnum.none));
|
||||
NavigationService.navigatorKey.currentContext!
|
||||
.read<SmartSceneSelectBloc>()
|
||||
.add(const SmartSceneClearEvent());
|
||||
BlocProvider.of<EffectPeriodBloc>(
|
||||
NavigationService.navigatorKey.currentState!.context)
|
||||
.add(ResetEffectivePeriod());
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.more_vert,
|
||||
size: 28,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
foregroundColor:
|
||||
WidgetStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
),
|
||||
onPressed: () {},
|
||||
),
|
||||
// IconButton(
|
||||
// icon: const Icon(
|
||||
// Icons.add,
|
||||
// size: 32,
|
||||
// ),
|
||||
// style: ButtonStyle(
|
||||
// foregroundColor: WidgetStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
// ),
|
||||
// onPressed: () {
|
||||
// Navigator.pushNamed(
|
||||
// NavigationService.navigatorKey.currentContext!,
|
||||
// Routes.sceneTasksRoute,
|
||||
// arguments: SceneSettingsRouteArguments(
|
||||
// sceneType: '',
|
||||
// sceneId: '',
|
||||
// sceneName: '',
|
||||
// ),
|
||||
// );
|
||||
// NavigationService.navigatorKey.currentContext!
|
||||
// .read<CreateSceneBloc>()
|
||||
// .add(const ClearTaskListEvent());
|
||||
// NavigationService.navigatorKey.currentContext!
|
||||
// .read<CreateSceneBloc>()
|
||||
// .add(const SceneTypeEvent(CreateSceneEnum.none));
|
||||
// NavigationService.navigatorKey.currentContext!
|
||||
// .read<SmartSceneSelectBloc>()
|
||||
// .add(const SmartSceneClearEvent());
|
||||
// BlocProvider.of<EffectPeriodBloc>(NavigationService.navigatorKey.currentState!.context)
|
||||
// .add(ResetEffectivePeriod());
|
||||
// },
|
||||
// ),
|
||||
// IconButton(
|
||||
// icon: const Icon(
|
||||
// Icons.more_vert,
|
||||
// size: 28,
|
||||
// ),
|
||||
// style: ButtonStyle(
|
||||
// foregroundColor: WidgetStateProperty.all(ColorsManager.textPrimaryColor),
|
||||
// ),
|
||||
// onPressed: () {},
|
||||
// ),
|
||||
],
|
||||
'Menu': [
|
||||
IconButton(
|
||||
@ -433,8 +419,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
};
|
||||
|
||||
static var bottomNavItems = [
|
||||
defaultBottomNavBarItem(
|
||||
icon: Assets.assetsIconsDashboard, label: 'Dashboard'),
|
||||
defaultBottomNavBarItem(icon: Assets.assetsIconsDashboard, label: 'Dashboard'),
|
||||
// defaultBottomNavBarItem(icon: Assets.assetsIconslayout, label: 'Layout'),
|
||||
defaultBottomNavBarItem(icon: Assets.assetsIconsDevices, label: 'Devices'),
|
||||
defaultBottomNavBarItem(icon: Assets.assetsIconsRoutines, label: 'Routine'),
|
||||
@ -460,8 +445,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
|
||||
void updateDevice(String deviceId) async {
|
||||
try {
|
||||
final response = await DevicesAPI.firmwareDevice(
|
||||
deviceId: deviceId, firmwareVersion: '0');
|
||||
final response = await DevicesAPI.firmwareDevice(deviceId: deviceId, firmwareVersion: '0');
|
||||
if (response['success'] ?? false) {
|
||||
CustomSnackBar.displaySnackBar('No updates available');
|
||||
}
|
||||
@ -469,8 +453,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
}
|
||||
}
|
||||
|
||||
BottomNavigationBarItem defaultBottomNavBarItem(
|
||||
{required String icon, required String label}) {
|
||||
BottomNavigationBarItem defaultBottomNavBarItem({required String icon, required String label}) {
|
||||
return BottomNavigationBarItem(
|
||||
icon: SvgPicture.asset(icon),
|
||||
activeIcon: SvgPicture.asset(
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/effective_period/effect_period_event.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
||||
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
|
||||
@ -29,7 +27,6 @@ class SceneListview extends StatelessWidget {
|
||||
itemCount: scenes.length,
|
||||
itemBuilder: (context, index) {
|
||||
final scene = scenes[index];
|
||||
final isLoading = loadingSceneId == scene.id;
|
||||
return Container(
|
||||
padding: const EdgeInsets.only(right: 10),
|
||||
child: DefaultContainer(
|
||||
@ -43,8 +40,17 @@ class SceneListview extends StatelessWidget {
|
||||
sceneName: scene.name,
|
||||
),
|
||||
);
|
||||
context
|
||||
.read<SmartSceneSelectBloc>()
|
||||
.add(const SmartSceneClearEvent());
|
||||
|
||||
BlocProvider.of<CreateSceneBloc>(context).add(
|
||||
FetchSceneTasksEvent(
|
||||
sceneId: scene.id, isAutomation: false));
|
||||
|
||||
/// the state to set the scene type must be after the fetch
|
||||
BlocProvider.of<CreateSceneBloc>(context)
|
||||
.add(FetchSceneTasksEvent(sceneId: scene.id));
|
||||
.add(const SceneTypeEvent(CreateSceneEnum.tabToRun));
|
||||
},
|
||||
child: SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.4,
|
||||
|
||||
@ -26,12 +26,14 @@ class RoomsView extends StatelessWidget {
|
||||
title: 'Space Management',
|
||||
child: state is LoadingState
|
||||
? const Center(child: RefreshProgressIndicator())
|
||||
: Container(
|
||||
margin: const EdgeInsets.only(top: 32),
|
||||
: SizedBox(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
child: Column(
|
||||
child: ListView(
|
||||
children: [
|
||||
const SizedBox(
|
||||
height: 32,
|
||||
),
|
||||
if (state is FetchRoomsState)
|
||||
Container(
|
||||
decoration: const ShapeDecoration(
|
||||
|
||||
@ -55,7 +55,7 @@ class ProfileTab extends StatelessWidget {
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
BodyMedium(
|
||||
text: HomeCubit.user!.lastName ?? '',
|
||||
text: HomeCubit.user?.lastName ?? '',
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
],
|
||||
|
||||
@ -13,6 +13,7 @@ import 'package:syncrow_app/features/scene/model/create_scene_model.dart';
|
||||
import 'package:syncrow_app/features/scene/model/scene_static_function.dart';
|
||||
import 'package:syncrow_app/navigation/navigation_service.dart';
|
||||
import 'package:syncrow_app/services/api/scene_api.dart';
|
||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||
|
||||
part 'create_scene_event.dart';
|
||||
part 'create_scene_state.dart';
|
||||
@ -52,8 +53,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
String conditionRule = 'or';
|
||||
EffectiveTime? effectiveTime;
|
||||
|
||||
FutureOr<void> _onAddSceneTask(
|
||||
AddTaskEvent event, Emitter<CreateSceneState> emit) {
|
||||
FutureOr<void> _onAddSceneTask(AddTaskEvent event, Emitter<CreateSceneState> emit) {
|
||||
emit(CreateSceneLoading());
|
||||
if (event.isAutomation == true) {
|
||||
final copyList = List<SceneStaticFunction>.from(automationTempTasksList);
|
||||
@ -88,32 +88,33 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
}
|
||||
}
|
||||
|
||||
void addToTempTaskList(
|
||||
TempHoldSceneTasksEvent event, Emitter<CreateSceneState> emit) {
|
||||
void addToTempTaskList(TempHoldSceneTasksEvent event, Emitter<CreateSceneState> emit) {
|
||||
emit(CreateSceneLoading());
|
||||
bool updated = false;
|
||||
|
||||
// Check and update if the task exists in tempTasksList
|
||||
for (var element in tempTasksList) {
|
||||
var updatedElement = element.copyWith(
|
||||
operationName: event.operation,
|
||||
deviceName: event.deviceName,
|
||||
icon: event.icon,
|
||||
code: event.deviceControlModel.code ?? '',
|
||||
deviceId: event.deviceId,
|
||||
functionValue: event.deviceControlModel.value,
|
||||
operationDialogType: event.operationType,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(
|
||||
value: event.deviceControlModel.value,
|
||||
icon: '',
|
||||
),
|
||||
],
|
||||
);
|
||||
tempTasksList[tempTasksList.indexOf(element)] = updatedElement;
|
||||
selectedValues[updatedElement.code] = event.deviceControlModel.value;
|
||||
updated = true;
|
||||
break;
|
||||
if (element.code == event.deviceControlModel.code) {
|
||||
var updatedElement = element.copyWith(
|
||||
operationName: event.operation,
|
||||
deviceName: event.deviceName,
|
||||
icon: event.icon,
|
||||
code: event.deviceControlModel.code ?? '',
|
||||
deviceId: event.deviceId,
|
||||
functionValue: event.deviceControlModel.value,
|
||||
operationDialogType: event.operationType,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(
|
||||
value: event.deviceControlModel.value,
|
||||
icon: '',
|
||||
),
|
||||
],
|
||||
);
|
||||
tempTasksList[tempTasksList.indexOf(element)] = updatedElement;
|
||||
selectedValues[updatedElement.code] = event.deviceControlModel.value;
|
||||
updated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!updated) {
|
||||
@ -172,8 +173,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
));
|
||||
}
|
||||
|
||||
void addToTempAutomationTaskList(
|
||||
TempHoldSceneTasksEvent event, Emitter<CreateSceneState> emit) {
|
||||
void addToTempAutomationTaskList(TempHoldSceneTasksEvent event, Emitter<CreateSceneState> emit) {
|
||||
emit(CreateSceneLoading());
|
||||
bool updated = false;
|
||||
for (var element in automationTempTasksList) {
|
||||
@ -195,10 +195,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
],
|
||||
comparator: automationComparatorValues[element.code],
|
||||
);
|
||||
automationTempTasksList[automationTempTasksList.indexOf(element)] =
|
||||
updatedElement;
|
||||
automationSelectedValues[updatedElement.code] =
|
||||
event.deviceControlModel.value;
|
||||
automationTempTasksList[automationTempTasksList.indexOf(element)] = updatedElement;
|
||||
automationSelectedValues[updatedElement.code] = event.deviceControlModel.value;
|
||||
updated = true;
|
||||
break;
|
||||
}
|
||||
@ -218,12 +216,10 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
icon: '',
|
||||
),
|
||||
],
|
||||
comparator:
|
||||
automationComparatorValues[event.deviceControlModel.code] ?? '==',
|
||||
comparator: automationComparatorValues[event.deviceControlModel.code] ?? '==',
|
||||
);
|
||||
automationTempTasksList.add(newElement);
|
||||
automationSelectedValues[newElement.code] =
|
||||
event.deviceControlModel.value;
|
||||
automationSelectedValues[newElement.code] = event.deviceControlModel.value;
|
||||
}
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList,
|
||||
@ -232,8 +228,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
));
|
||||
}
|
||||
|
||||
FutureOr<void> _selectedValue(
|
||||
SelectedValueEvent event, Emitter<CreateSceneState> emit) {
|
||||
FutureOr<void> _selectedValue(SelectedValueEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
automationSelectedValues[event.code] = event.value;
|
||||
automationComparatorValues[event.code] = event.comparator ?? '==';
|
||||
@ -248,6 +243,15 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < tasksList.length; i++) {
|
||||
if (tasksList[i].code == event.code) {
|
||||
tasksList[i] = tasksList[i].copyWith(
|
||||
comparator: event.comparator ?? '==',
|
||||
functionValue: event.value,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
selectedValues[event.code] = event.value;
|
||||
}
|
||||
@ -261,8 +265,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
));
|
||||
}
|
||||
|
||||
FutureOr<void> _removeTaskById(
|
||||
RemoveTaskByIdEvent event, Emitter<CreateSceneState> emit) {
|
||||
FutureOr<void> _removeTaskById(RemoveTaskByIdEvent event, Emitter<CreateSceneState> emit) {
|
||||
emit(CreateSceneLoading());
|
||||
if (event.isAutomation == true) {
|
||||
for (var element in automationTasksList) {
|
||||
@ -335,8 +338,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
: await SceneApi.createScene(event.createSceneModel!);
|
||||
} else if (event.createAutomationModel != null) {
|
||||
response = event.updateScene
|
||||
? await SceneApi.updateAutomation(
|
||||
event.createAutomationModel!, event.sceneId)
|
||||
? await SceneApi.updateAutomation(event.createAutomationModel!, event.sceneId)
|
||||
: await SceneApi.createAutomation(event.createAutomationModel!);
|
||||
}
|
||||
|
||||
@ -348,11 +350,12 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
automationTempTasksList.clear();
|
||||
automationSelectedValues.clear();
|
||||
automationComparatorValues.clear();
|
||||
effectiveTime =
|
||||
EffectiveTime(start: '00:00', end: '23:59', loops: '1111111');
|
||||
effectiveTime = EffectiveTime(start: '00:00', end: '23:59', loops: '1111111');
|
||||
sceneType = CreateSceneEnum.none;
|
||||
conditionRule = 'or';
|
||||
emit(const CreateSceneWithTasks(success: true));
|
||||
CustomSnackBar.greenSnackBar(
|
||||
event.updateScene ? 'Scene updated successfully' : 'Scene created successfully');
|
||||
} else {
|
||||
emit(const CreateSceneError(message: 'Something went wrong'));
|
||||
}
|
||||
@ -366,8 +369,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _clearTaskList(
|
||||
ClearTaskListEvent event, Emitter<CreateSceneState> emit) {
|
||||
FutureOr<void> _clearTaskList(ClearTaskListEvent event, Emitter<CreateSceneState> emit) {
|
||||
emit(CreateSceneLoading());
|
||||
automationTasksList.clear();
|
||||
tasksList.clear();
|
||||
@ -383,19 +385,26 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
emit(CreateSceneLoading());
|
||||
|
||||
try {
|
||||
tasksList.clear();
|
||||
tempTasksList.clear();
|
||||
selectedValues.clear();
|
||||
automationTasksList.clear();
|
||||
automationTempTasksList.clear();
|
||||
automationSelectedValues.clear();
|
||||
automationComparatorValues.clear();
|
||||
effectiveTime = EffectiveTime(start: '00:00', end: '23:59', loops: '1111111');
|
||||
sceneType = CreateSceneEnum.none;
|
||||
conditionRule = 'or';
|
||||
|
||||
final response = event.isAutomation
|
||||
? await SceneApi.getAutomationDetails(event.sceneId)
|
||||
: await SceneApi.getSceneDetails(event.sceneId);
|
||||
if (response.id.isNotEmpty) {
|
||||
if (event.isAutomation) {
|
||||
automationTasksList = List<SceneStaticFunction>.from(
|
||||
getTaskListFunctionsFromApi(
|
||||
actions: [],
|
||||
isAutomation: true,
|
||||
conditions: response.conditions));
|
||||
automationTasksList = List<SceneStaticFunction>.from(getTaskListFunctionsFromApi(
|
||||
actions: [], isAutomation: true, conditions: response.conditions));
|
||||
tasksList = List<SceneStaticFunction>.from(
|
||||
getTaskListFunctionsFromApi(
|
||||
actions: response.actions, isAutomation: false));
|
||||
getTaskListFunctionsFromApi(actions: response.actions, isAutomation: false));
|
||||
|
||||
conditionRule = response.decisionExpr ?? conditionRule;
|
||||
|
||||
@ -407,25 +416,14 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
)
|
||||
: EffectiveTime(start: '00:00', end: '23:59', loops: '1111111');
|
||||
|
||||
// Set the days directly from the API response
|
||||
BlocProvider.of<EffectPeriodBloc>(NavigationService.navigatorKey.currentContext!)
|
||||
.add(SetDays(response.effectiveTime?.loops ?? '1111111'));
|
||||
|
||||
// Set Custom Time and reset days first
|
||||
BlocProvider.of<EffectPeriodBloc>(
|
||||
NavigationService.navigatorKey.currentContext!)
|
||||
BlocProvider.of<EffectPeriodBloc>(NavigationService.navigatorKey.currentContext!)
|
||||
.add(SetCustomTime(effectiveTime!.start, effectiveTime!.end));
|
||||
|
||||
// Reset all days to not selected before toggling
|
||||
BlocProvider.of<EffectPeriodBloc>(
|
||||
NavigationService.navigatorKey.currentContext!)
|
||||
.add(ResetDays());
|
||||
|
||||
// Iterate over the loops and toggle each day
|
||||
for (int i = 0; i < effectiveTime!.loops.length; i++) {
|
||||
if (effectiveTime!.loops[i] == '1') {
|
||||
BlocProvider.of<EffectPeriodBloc>(
|
||||
NavigationService.navigatorKey.currentContext!)
|
||||
.add(ToggleDay(_getDayFromIndex(i)));
|
||||
}
|
||||
}
|
||||
|
||||
emit(AddSceneTask(
|
||||
automationTasksList: automationTasksList,
|
||||
tasksList: tasksList,
|
||||
@ -433,8 +431,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
));
|
||||
} else {
|
||||
tasksList = List<SceneStaticFunction>.from(
|
||||
getTaskListFunctionsFromApi(
|
||||
actions: response.actions, isAutomation: false));
|
||||
getTaskListFunctionsFromApi(actions: response.actions, isAutomation: false));
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList,
|
||||
condition: conditionRule,
|
||||
@ -453,8 +450,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
return days[index];
|
||||
}
|
||||
|
||||
FutureOr<void> _clearTempTaskList(
|
||||
ClearTempTaskListEvent event, Emitter<CreateSceneState> emit) {
|
||||
FutureOr<void> _clearTempTaskList(ClearTempTaskListEvent event, Emitter<CreateSceneState> emit) {
|
||||
emit(CreateSceneLoading());
|
||||
if (event.isAutomation == true) {
|
||||
automationTempTasksList.clear();
|
||||
@ -498,17 +494,13 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _deleteScene(
|
||||
DeleteSceneEvent event, Emitter<CreateSceneState> emit) async {
|
||||
FutureOr<void> _deleteScene(DeleteSceneEvent event, Emitter<CreateSceneState> emit) async {
|
||||
emit(DeleteSceneLoading());
|
||||
|
||||
try {
|
||||
final response =
|
||||
sceneType.name == CreateSceneEnum.deviceStatusChanges.name
|
||||
? await SceneApi.deleteAutomation(
|
||||
automationId: event.sceneId, unitUuid: event.unitUuid)
|
||||
: await SceneApi.deleteScene(
|
||||
sceneId: event.sceneId, unitUuid: event.unitUuid);
|
||||
final response = sceneType.name == CreateSceneEnum.deviceStatusChanges.name
|
||||
? await SceneApi.deleteAutomation(automationId: event.sceneId, unitUuid: event.unitUuid)
|
||||
: await SceneApi.deleteScene(sceneId: event.sceneId, unitUuid: event.unitUuid);
|
||||
if (response == true) {
|
||||
emit(const DeleteSceneSuccess(true));
|
||||
} else {
|
||||
@ -519,8 +511,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _updateTaskValue(
|
||||
UpdateTaskEvent event, Emitter<CreateSceneState> emit) {
|
||||
FutureOr<void> _updateTaskValue(UpdateTaskEvent event, Emitter<CreateSceneState> emit) {
|
||||
emit(CreateSceneLoading());
|
||||
if (event.isAutomation == true) {
|
||||
for (var i = 0; i < automationTasksList.length; i++) {
|
||||
@ -531,6 +522,14 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < tasksList.length; i++) {
|
||||
if (tasksList[i].uniqueCustomId == event.taskId) {
|
||||
tasksList[i] = tasksList[i].copyWith(
|
||||
functionValue: event.newValue,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var i = 0; i < tasksList.length; i++) {
|
||||
if (tasksList[i].uniqueCustomId == event.taskId) {
|
||||
@ -548,8 +547,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
));
|
||||
}
|
||||
|
||||
FutureOr<void> _selectConditionRule(
|
||||
SelectConditionEvent event, Emitter<CreateSceneState> emit) {
|
||||
FutureOr<void> _selectConditionRule(SelectConditionEvent event, Emitter<CreateSceneState> emit) {
|
||||
emit(CreateSceneInitial());
|
||||
if (event.condition.contains('any')) {
|
||||
conditionRule = 'or';
|
||||
@ -564,9 +562,8 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
));
|
||||
}
|
||||
|
||||
FutureOr<void> _sceneTypeEvent(
|
||||
SceneTypeEvent event, Emitter<CreateSceneState> emit) {
|
||||
emit(CreateSceneInitial());
|
||||
FutureOr<void> _sceneTypeEvent(SceneTypeEvent event, Emitter<CreateSceneState> emit) {
|
||||
// emit(CreateSceneInitial());
|
||||
|
||||
if (event.type == CreateSceneEnum.tabToRun) {
|
||||
sceneType = CreateSceneEnum.tabToRun;
|
||||
@ -576,7 +573,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
sceneType = CreateSceneEnum.none;
|
||||
}
|
||||
|
||||
emit(SceneTypeState(event.type));
|
||||
// emit(SceneTypeState(event.type));
|
||||
}
|
||||
|
||||
FutureOr<void> _onEffectiveTimeEvent(
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||
@ -14,6 +16,7 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
|
||||
on<SetCustomTime>(_onSetCustomTime);
|
||||
on<ResetEffectivePeriod>(_onResetEffectivePeriod);
|
||||
on<ResetDays>(_onResetDays);
|
||||
on<SetDays>(_setAllDays);
|
||||
}
|
||||
|
||||
void _onSetPeriod(SetPeriod event, Emitter<EffectPeriodState> emit) {
|
||||
@ -120,4 +123,8 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
|
||||
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||
return days.indexOf(day);
|
||||
}
|
||||
|
||||
FutureOr<void> _setAllDays(SetDays event, Emitter<EffectPeriodState> emit) {
|
||||
emit(state.copyWith(selectedDaysBinary: event.daysBinary));
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,3 +42,9 @@ class ResetDays extends EffectPeriodEvent {
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class SetDays extends EffectPeriodEvent {
|
||||
final String daysBinary;
|
||||
|
||||
const SetDays(this.daysBinary);
|
||||
}
|
||||
|
||||
@ -16,10 +16,8 @@ class DoorLockHelperFunctions {
|
||||
code: 'normal_open_switch',
|
||||
operationDialogType: OperationDialogType.onOff,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsAcPower, description: "ON", value: true),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||
SceneOperationalValue(icon: Assets.assetsAcPower, description: "ON", value: true),
|
||||
SceneOperationalValue(icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||
],
|
||||
),
|
||||
];
|
||||
@ -98,7 +96,7 @@ class DoorLockHelperFunctions {
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsFingerprintUnlock,
|
||||
description: "Fingerprint Mismatch",
|
||||
value: 0,
|
||||
value: 'wrong_finger',
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@ -15,9 +15,13 @@ import 'package:syncrow_app/utils/context_extension.dart';
|
||||
|
||||
mixin SceneLogicHelper {
|
||||
bool isOnlyDelayOrDelayLast(List<SceneStaticFunction> tasks) {
|
||||
final lastTask = tasks.last;
|
||||
return tasks.every((task) => task.code == 'delay') ||
|
||||
lastTask.code == 'delay';
|
||||
final lastTask = tasks.isNotEmpty ? tasks.last : null;
|
||||
|
||||
return tasks.isNotEmpty
|
||||
? tasks.every((task) => task.code == 'delay') ||
|
||||
lastTask!.code == 'delay' ||
|
||||
lastTask.deviceId == 'delay'
|
||||
: false;
|
||||
}
|
||||
|
||||
void handleSaveButtonPress(
|
||||
@ -155,24 +159,21 @@ mixin SceneLogicHelper {
|
||||
}
|
||||
}
|
||||
|
||||
Widget getTheCorrectDialogBody(
|
||||
SceneStaticFunction taskItem, dynamic functionValue,
|
||||
Widget getTheCorrectDialogBody(SceneStaticFunction taskItem, dynamic functionValue,
|
||||
{required bool isAutomation}) {
|
||||
if (taskItem.operationDialogType == OperationDialogType.temperature) {
|
||||
return AlertDialogTemperatureBody(
|
||||
taskItem: taskItem,
|
||||
functionValue: functionValue ?? taskItem.functionValue,
|
||||
);
|
||||
} else if ((taskItem.operationDialogType ==
|
||||
OperationDialogType.countdown) ||
|
||||
} else if ((taskItem.operationDialogType == OperationDialogType.countdown) ||
|
||||
(taskItem.operationDialogType == OperationDialogType.delay)) {
|
||||
return AlertDialogCountdown(
|
||||
durationValue: taskItem.functionValue ?? 0,
|
||||
functionValue: functionValue ?? taskItem.functionValue,
|
||||
function: taskItem,
|
||||
);
|
||||
} else if (taskItem.operationDialogType ==
|
||||
OperationDialogType.integerSteps) {
|
||||
} else if (taskItem.operationDialogType == OperationDialogType.integerSteps) {
|
||||
return AlertDialogSliderSteps(
|
||||
taskItem: taskItem,
|
||||
functionValue: functionValue ?? taskItem.functionValue,
|
||||
|
||||
@ -14,9 +14,8 @@ import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
mixin SceneOperationsDataHelper {
|
||||
final Map<DeviceType,
|
||||
Function(List<FunctionModel>, String, String, dynamic, bool)>
|
||||
_functionMap = {
|
||||
final Map<DeviceType, Function(List<FunctionModel>, String, String, dynamic, bool)> _functionMap =
|
||||
{
|
||||
DeviceType.LightBulb: lightBulbFunctions,
|
||||
DeviceType.CeilingSensor: ceilingSensorFunctions,
|
||||
DeviceType.WallSensor: wallSensorFunctions,
|
||||
@ -46,22 +45,16 @@ mixin SceneOperationsDataHelper {
|
||||
required bool isAutomation,
|
||||
}) {
|
||||
final functionValue = null;
|
||||
return _functionMap[type]?.call(
|
||||
functions, deviceId, deviceName, functionValue, isAutomation) ??
|
||||
lightBulbFunctions(
|
||||
functions, deviceId, deviceName, functionValue, isAutomation);
|
||||
return _functionMap[type]?.call(functions, deviceId, deviceName, functionValue, isAutomation) ??
|
||||
lightBulbFunctions(functions, deviceId, deviceName, functionValue, isAutomation);
|
||||
}
|
||||
|
||||
String getTitle({DeviceType? type}) {
|
||||
return _titleMap[type] ?? '';
|
||||
}
|
||||
|
||||
static List<SceneStaticFunction> ceilingSensorFunctions(
|
||||
List<FunctionModel> functions,
|
||||
String deviceId,
|
||||
String deviceName,
|
||||
dynamic functionValue,
|
||||
bool isAutomation) {
|
||||
static List<SceneStaticFunction> ceilingSensorFunctions(List<FunctionModel> functions,
|
||||
String deviceId, String deviceName, dynamic functionValue, bool isAutomation) {
|
||||
if (isAutomation) {
|
||||
return PresenceSensorHelperFunctions.automationPresenceSensorFunctions(
|
||||
deviceId, deviceName, functionValue);
|
||||
@ -70,35 +63,22 @@ mixin SceneOperationsDataHelper {
|
||||
deviceId, deviceName, functionValue);
|
||||
}
|
||||
|
||||
static List<SceneStaticFunction> curtainFunctions(
|
||||
List<FunctionModel> functions,
|
||||
String deviceId,
|
||||
String deviceName,
|
||||
dynamic functionValue,
|
||||
bool isAutomation) {
|
||||
static List<SceneStaticFunction> curtainFunctions(List<FunctionModel> functions, String deviceId,
|
||||
String deviceName, dynamic functionValue, bool isAutomation) {
|
||||
return [];
|
||||
}
|
||||
|
||||
static List<SceneStaticFunction> doorLockFunctions(
|
||||
List<FunctionModel> functions,
|
||||
String deviceId,
|
||||
String deviceName,
|
||||
dynamic functionValue,
|
||||
bool isAutomation) {
|
||||
static List<SceneStaticFunction> doorLockFunctions(List<FunctionModel> functions, String deviceId,
|
||||
String deviceName, dynamic functionValue, bool isAutomation) {
|
||||
if (isAutomation) {
|
||||
return DoorLockHelperFunctions.doorLockAutomationFunctions(
|
||||
deviceId, deviceName, functionValue);
|
||||
}
|
||||
return DoorLockHelperFunctions.doorLockTapToRunFunctions(
|
||||
deviceId, deviceName, functionValue);
|
||||
return DoorLockHelperFunctions.doorLockTapToRunFunctions(deviceId, deviceName, functionValue);
|
||||
}
|
||||
|
||||
static List<SceneStaticFunction> wallSensorFunctions(
|
||||
List<FunctionModel> functions,
|
||||
String deviceId,
|
||||
String deviceName,
|
||||
dynamic functionValue,
|
||||
bool isAutomation) {
|
||||
static List<SceneStaticFunction> wallSensorFunctions(List<FunctionModel> functions,
|
||||
String deviceId, String deviceName, dynamic functionValue, bool isAutomation) {
|
||||
if (isAutomation) {
|
||||
return HumanPresenceHelperFunctions.automationHumanPresenceFunctions(
|
||||
deviceId, deviceName, functionValue);
|
||||
@ -107,51 +87,31 @@ mixin SceneOperationsDataHelper {
|
||||
deviceId, deviceName, functionValue);
|
||||
}
|
||||
|
||||
static List<SceneStaticFunction> lightBulbFunctions(
|
||||
List<FunctionModel> functions,
|
||||
String deviceId,
|
||||
String deviceName,
|
||||
dynamic functionValue,
|
||||
bool isAutomation) {
|
||||
static List<SceneStaticFunction> lightBulbFunctions(List<FunctionModel> functions,
|
||||
String deviceId, String deviceName, dynamic functionValue, bool isAutomation) {
|
||||
return [];
|
||||
}
|
||||
|
||||
static List<SceneStaticFunction> gatewayFunctions(
|
||||
List<FunctionModel> functions,
|
||||
String deviceId,
|
||||
String deviceName,
|
||||
dynamic functionValue,
|
||||
bool isAutomation) {
|
||||
return GatewayHelperFunctions.tabToRunGatewayFunctions(
|
||||
deviceId, deviceName, functionValue);
|
||||
static List<SceneStaticFunction> gatewayFunctions(List<FunctionModel> functions, String deviceId,
|
||||
String deviceName, dynamic functionValue, bool isAutomation) {
|
||||
return GatewayHelperFunctions.tabToRunGatewayFunctions(deviceId, deviceName, functionValue);
|
||||
}
|
||||
|
||||
static List<SceneStaticFunction> threeGangFunctions(
|
||||
List<FunctionModel> functions,
|
||||
String deviceId,
|
||||
String deviceName,
|
||||
dynamic functionValue,
|
||||
bool isAutomation) {
|
||||
static List<SceneStaticFunction> threeGangFunctions(List<FunctionModel> functions,
|
||||
String deviceId, String deviceName, dynamic functionValue, bool isAutomation) {
|
||||
if (isAutomation) {
|
||||
return ThreeGangHelperFunctions.threeGangAutomationFunctions(
|
||||
deviceId, deviceName, functionValue);
|
||||
}
|
||||
return ThreeGangHelperFunctions.threeGangHelperFunctions(
|
||||
deviceId, deviceName, functionValue);
|
||||
return ThreeGangHelperFunctions.threeGangHelperFunctions(deviceId, deviceName, functionValue);
|
||||
}
|
||||
|
||||
static List<SceneStaticFunction> acFunctions(
|
||||
List<FunctionModel> functions,
|
||||
String deviceId,
|
||||
String deviceName,
|
||||
dynamic functionValue,
|
||||
bool isAutomation) {
|
||||
static List<SceneStaticFunction> acFunctions(List<FunctionModel> functions, String deviceId,
|
||||
String deviceName, dynamic functionValue, bool isAutomation) {
|
||||
if (isAutomation) {
|
||||
return ACFunctionsHelper.automationAcFunctions(
|
||||
deviceId, deviceName, functionValue);
|
||||
return ACFunctionsHelper.automationAcFunctions(deviceId, deviceName, functionValue);
|
||||
}
|
||||
return ACFunctionsHelper.tabToRunAcFunctions(
|
||||
deviceId, deviceName, functionValue);
|
||||
return ACFunctionsHelper.tabToRunAcFunctions(deviceId, deviceName, functionValue);
|
||||
}
|
||||
|
||||
List<SceneStaticFunction> getTaskListFunctionsFromApi({
|
||||
@ -189,12 +149,8 @@ mixin SceneOperationsDataHelper {
|
||||
SceneStaticFunction(
|
||||
deviceId: action.entityId,
|
||||
deviceName: action.name.toString(),
|
||||
deviceIcon: action.type == 'automation'
|
||||
? Assets.player
|
||||
: Assets.handClickIcon,
|
||||
icon: action.type == 'automation'
|
||||
? Assets.player
|
||||
: Assets.handClickIcon,
|
||||
deviceIcon: action.type == 'automation' ? Assets.player : Assets.handClickIcon,
|
||||
icon: action.type == 'automation' ? Assets.player : Assets.handClickIcon,
|
||||
operationName: action.type.toString(),
|
||||
operationDialogType: OperationDialogType.onOff,
|
||||
functionValue: action.actionExecutor,
|
||||
@ -214,8 +170,7 @@ mixin SceneOperationsDataHelper {
|
||||
),
|
||||
);
|
||||
} else {
|
||||
functions
|
||||
.add(_mapExecutorPropertyToSceneFunction(action, isAutomation));
|
||||
functions.add(_mapExecutorPropertyToSceneFunction(action, isAutomation));
|
||||
}
|
||||
}
|
||||
|
||||
@ -247,11 +202,11 @@ mixin SceneOperationsDataHelper {
|
||||
Action action,
|
||||
bool isAutomation, {
|
||||
String? comparator,
|
||||
String? uniqueCustomId,
|
||||
}) {
|
||||
final executorProperty = action.executorProperty;
|
||||
|
||||
final Map<String, SceneStaticFunction Function(Action, bool, String?)>
|
||||
functionMap = {
|
||||
final Map<String, SceneStaticFunction Function(Action, bool, String?, String?)> functionMap = {
|
||||
'sensitivity': _createSensitivityFunction,
|
||||
'normal_open_switch': _createNormalOpenSwitchFunction,
|
||||
'unlock_fingerprint': _createUnlockFingerprintFunction,
|
||||
@ -294,7 +249,7 @@ mixin SceneOperationsDataHelper {
|
||||
final functionCode = executorProperty?.functionCode ?? '';
|
||||
final createFunction = functionMap[functionCode];
|
||||
if (createFunction != null) {
|
||||
return createFunction(action, isAutomation, comparator);
|
||||
return createFunction(action, isAutomation, comparator, uniqueCustomId);
|
||||
} else {
|
||||
throw ArgumentError('Unsupported function code: $functionCode');
|
||||
}
|
||||
@ -309,9 +264,11 @@ mixin SceneOperationsDataHelper {
|
||||
List<SceneOperationalValue> operationalValues,
|
||||
bool isAutomation, [
|
||||
String? comparator,
|
||||
String? uniqueCustomId,
|
||||
]) {
|
||||
final functionValue = action.executorProperty?.functionValue;
|
||||
return SceneStaticFunction(
|
||||
uniqueCustomId: uniqueCustomId,
|
||||
deviceId: action.entityId,
|
||||
deviceName: deviceName,
|
||||
deviceIcon: icon,
|
||||
@ -326,23 +283,22 @@ mixin SceneOperationsDataHelper {
|
||||
}
|
||||
|
||||
SceneStaticFunction _createSensitivityFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Presence Sensor',
|
||||
Assets.assetsIconsSensors,
|
||||
'Sensitivity',
|
||||
isAutomation
|
||||
? OperationDialogType.integerSteps
|
||||
: OperationDialogType.listOfOptions,
|
||||
isAutomation ? OperationDialogType.integerSteps : OperationDialogType.listOfOptions,
|
||||
isAutomation ? _createIntegerStepsOptions() : _createSensitivityOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createNormalOpenSwitchFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'WIFI LOCK PRO',
|
||||
@ -352,6 +308,7 @@ mixin SceneOperationsDataHelper {
|
||||
_createOnOffOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
@ -395,7 +352,7 @@ mixin SceneOperationsDataHelper {
|
||||
}
|
||||
|
||||
SceneStaticFunction _createUnlockFingerprintFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'WIFI LOCK PRO',
|
||||
@ -405,11 +362,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createFingerprintUnlockOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createUnlockPasswordFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'WIFI LOCK PRO',
|
||||
@ -419,11 +377,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createPasswordUnlockOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createUnlockCardFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'WIFI LOCK PRO',
|
||||
@ -433,11 +392,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createCardUnlockOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createAlarmLockFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'WIFI LOCK PRO',
|
||||
@ -447,11 +407,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createLockAlarmOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createUnlockRequestFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'WIFI LOCK PRO',
|
||||
@ -461,11 +422,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createUnlockRequestOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createResidualElectricityFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'WIFI LOCK PRO',
|
||||
@ -475,11 +437,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createResidualElectricityOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createReverseLockFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'WIFI LOCK PRO',
|
||||
@ -489,11 +452,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createOnOffOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createUnlockAppFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'WIFI LOCK PRO',
|
||||
@ -503,11 +467,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createUnlockAppOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createHijackFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'WIFI LOCK PRO',
|
||||
@ -517,11 +482,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createOnOffOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createDoorbellFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'WIFI LOCK PRO',
|
||||
@ -531,11 +497,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createOnOffOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createUnlockTemporaryFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'WIFI LOCK PRO',
|
||||
@ -545,11 +512,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createTemporaryPasswordUnlockOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createFarDetectionFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Human Presence Sensor',
|
||||
@ -559,11 +527,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createFarDetectionOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createMotionSensitivityFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Human Presence Sensor',
|
||||
@ -573,11 +542,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createSensitivityOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createMotionlessSensitivityFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Human Presence Sensor',
|
||||
@ -587,11 +557,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createSensitivityOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createIndicatorFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Human Presence Sensor',
|
||||
@ -601,11 +572,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createOnOffOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createPresenceTimeFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Human Presence Sensor',
|
||||
@ -615,11 +587,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createCountdownOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createPresenceStateFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Human Presence Sensor',
|
||||
@ -629,27 +602,27 @@ mixin SceneOperationsDataHelper {
|
||||
_createPresenceStateOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createDisCurrentFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Human Presence Sensor',
|
||||
Assets.assetsIconsSensors,
|
||||
'Current Distance',
|
||||
isAutomation
|
||||
? OperationDialogType.integerSteps
|
||||
: OperationDialogType.countdown,
|
||||
isAutomation ? OperationDialogType.integerSteps : OperationDialogType.countdown,
|
||||
_createCurrentDistanceOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createIlluminanceValueFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Human Presence Sensor',
|
||||
@ -659,11 +632,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createIlluminanceValueOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createCheckingResultFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Human Presence Sensor',
|
||||
@ -673,11 +647,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createSelfTestResultOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createSwitchFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Smart AC Thermostat - Grey - Model A',
|
||||
@ -687,29 +662,27 @@ mixin SceneOperationsDataHelper {
|
||||
_createOnOffOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createTempSetFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Smart AC Thermostat - Grey - Model A',
|
||||
Assets.assetsIconsAC,
|
||||
'Set Temperature',
|
||||
isAutomation
|
||||
? OperationDialogType.integerSteps
|
||||
: OperationDialogType.temperature,
|
||||
isAutomation
|
||||
? _createAutomationTemperatureOptions()
|
||||
: _createTemperatureOptions(),
|
||||
isAutomation ? OperationDialogType.integerSteps : OperationDialogType.temperature,
|
||||
isAutomation ? _createAutomationTemperatureOptions() : _createTemperatureOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createTempCurrentFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Smart AC Thermostat - Grey - Model A',
|
||||
@ -719,11 +692,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createCurrentTemperatureOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createModeFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Smart AC Thermostat - Grey - Model A',
|
||||
@ -733,11 +707,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createAcModeOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createLevelFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Smart AC Thermostat - Grey - Model A',
|
||||
@ -747,11 +722,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createFanSpeedOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createChildLockFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Smart AC Thermostat - Grey - Model A',
|
||||
@ -761,11 +737,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createOnOffOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createSwitch1Function(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'3 Gang Button Switch L-L',
|
||||
@ -775,11 +752,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createOnOffOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createSwitch2Function(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'3 Gang Button Switch L-L',
|
||||
@ -789,11 +767,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createOnOffOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createSwitch3Function(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'3 Gang Button Switch L-L',
|
||||
@ -803,65 +782,57 @@ mixin SceneOperationsDataHelper {
|
||||
_createOnOffOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createCountdown1Function(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'3 Gang Button Switch L-L',
|
||||
Assets.assetsIcons3GangSwitch,
|
||||
'Light 1 CountDown',
|
||||
isAutomation
|
||||
? OperationDialogType.integerSteps
|
||||
: OperationDialogType.countdown,
|
||||
isAutomation
|
||||
? _createAutomationCountDownOptions()
|
||||
: _createCountdownOptions(),
|
||||
isAutomation ? OperationDialogType.integerSteps : OperationDialogType.countdown,
|
||||
isAutomation ? _createAutomationCountDownOptions() : _createCountdownOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createCountdown2Function(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'3 Gang Button Switch L-L',
|
||||
Assets.assetsIcons3GangSwitch,
|
||||
'Light 2 CountDown',
|
||||
isAutomation
|
||||
? OperationDialogType.integerSteps
|
||||
: OperationDialogType.countdown,
|
||||
isAutomation
|
||||
? _createAutomationCountDownOptions()
|
||||
: _createCountdownOptions(),
|
||||
isAutomation ? OperationDialogType.integerSteps : OperationDialogType.countdown,
|
||||
isAutomation ? _createAutomationCountDownOptions() : _createCountdownOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createCountdown3Function(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'3 Gang Button Switch L-L',
|
||||
Assets.assetsIcons3GangSwitch,
|
||||
'Light 3 CountDown',
|
||||
isAutomation
|
||||
? OperationDialogType.integerSteps
|
||||
: OperationDialogType.countdown,
|
||||
isAutomation
|
||||
? _createAutomationCountDownOptions()
|
||||
: _createCountdownOptions(),
|
||||
isAutomation ? OperationDialogType.integerSteps : OperationDialogType.countdown,
|
||||
isAutomation ? _createAutomationCountDownOptions() : _createCountdownOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createSwitchAlarmSoundFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Gateway',
|
||||
@ -871,11 +842,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createOnOffOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createMasterStateFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Gateway',
|
||||
@ -885,11 +857,12 @@ mixin SceneOperationsDataHelper {
|
||||
_createMasterStateOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
SceneStaticFunction _createFactoryResetFunction(
|
||||
Action action, bool isAutomation, String? comparator) {
|
||||
Action action, bool isAutomation, String? comparator, String? uniqueCustomId) {
|
||||
return _createSceneFunction(
|
||||
action,
|
||||
'Gateway',
|
||||
@ -899,6 +872,7 @@ mixin SceneOperationsDataHelper {
|
||||
_createOnOffOptions(),
|
||||
isAutomation,
|
||||
comparator,
|
||||
uniqueCustomId,
|
||||
);
|
||||
}
|
||||
|
||||
@ -946,7 +920,7 @@ mixin SceneOperationsDataHelper {
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsFingerprintUnlock,
|
||||
description: "Fingerprint Mismatch",
|
||||
value: 0,
|
||||
value: 'wrong_finger',
|
||||
),
|
||||
];
|
||||
}
|
||||
@ -1181,6 +1155,7 @@ mixin SceneOperationsDataHelper {
|
||||
if (deviceId.contains('delay')) {
|
||||
return [
|
||||
SceneStaticFunction(
|
||||
uniqueCustomId: taskItem.uniqueCustomId,
|
||||
deviceId: taskItem.deviceId,
|
||||
deviceName: 'delay',
|
||||
deviceIcon: Assets.delay,
|
||||
@ -1202,14 +1177,11 @@ mixin SceneOperationsDataHelper {
|
||||
if (taskItem.code == CreateSceneEnum.smartSceneSelect.name) {
|
||||
return [
|
||||
SceneStaticFunction(
|
||||
uniqueCustomId: taskItem.uniqueCustomId,
|
||||
deviceId: taskItem.deviceId,
|
||||
deviceName: taskItem.deviceName.toString(),
|
||||
deviceIcon: taskItem.operationName == 'automation'
|
||||
? Assets.player
|
||||
: Assets.handClickIcon,
|
||||
icon: taskItem.operationName == 'automation'
|
||||
? Assets.player
|
||||
: Assets.handClickIcon,
|
||||
deviceIcon: taskItem.operationName == 'automation' ? Assets.player : Assets.handClickIcon,
|
||||
icon: taskItem.operationName == 'automation' ? Assets.player : Assets.handClickIcon,
|
||||
operationName: taskItem.operationName,
|
||||
operationDialogType: OperationDialogType.onOff,
|
||||
functionValue: taskItem.functionValue == 'rule_enable' ? true : false,
|
||||
@ -1241,6 +1213,7 @@ mixin SceneOperationsDataHelper {
|
||||
),
|
||||
isAutomation,
|
||||
comparator: taskItem.comparator,
|
||||
uniqueCustomId: taskItem.uniqueCustomId,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ class SceneStaticFunction {
|
||||
final List<SceneOperationalValue> operationalValues;
|
||||
final String deviceId;
|
||||
final String operationName;
|
||||
final String uniqueCustomId;
|
||||
final String? uniqueCustomId;
|
||||
final dynamic functionValue;
|
||||
final String? deviceIcon;
|
||||
final OperationDialogType operationDialogType;
|
||||
@ -28,7 +28,8 @@ class SceneStaticFunction {
|
||||
this.deviceIcon,
|
||||
required this.operationDialogType,
|
||||
this.comparator,
|
||||
}) : uniqueCustomId = const Uuid().v4();
|
||||
String? uniqueCustomId,
|
||||
}) : uniqueCustomId = uniqueCustomId ?? const Uuid().v4();
|
||||
|
||||
SceneStaticFunction copyWith({
|
||||
String? icon,
|
||||
@ -42,6 +43,7 @@ class SceneStaticFunction {
|
||||
String? deviceName,
|
||||
OperationDialogType? operationDialogType,
|
||||
String? comparator,
|
||||
String? uniqueCustomId,
|
||||
}) {
|
||||
return SceneStaticFunction(
|
||||
icon: icon ?? this.icon,
|
||||
@ -54,6 +56,7 @@ class SceneStaticFunction {
|
||||
deviceIcon: deviceIcon ?? this.deviceIcon,
|
||||
operationDialogType: operationDialogType ?? this.operationDialogType,
|
||||
comparator: comparator ?? this.comparator,
|
||||
uniqueCustomId: uniqueCustomId ?? const Uuid().v4(),
|
||||
);
|
||||
}
|
||||
|
||||
@ -68,7 +71,8 @@ class SceneStaticFunction {
|
||||
'functionValue': functionValue,
|
||||
'deviceIcon': deviceIcon,
|
||||
'operationDialogType': operationDialogType.name,
|
||||
'comparator': comparator
|
||||
'comparator': comparator,
|
||||
'uniqueCustomId': uniqueCustomId,
|
||||
};
|
||||
}
|
||||
|
||||
@ -88,6 +92,7 @@ class SceneStaticFunction {
|
||||
? OperationDialogType.values.byName(map['operationDialogType'])
|
||||
: OperationDialogType.none,
|
||||
comparator: map['comparator'],
|
||||
uniqueCustomId: map['uniqueCustomId'] ?? const Uuid().v4(),
|
||||
);
|
||||
}
|
||||
|
||||
@ -98,7 +103,7 @@ class SceneStaticFunction {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SceneStaticFunction(icon: $icon, name: $deviceName, code: $code, operationalValues: $operationalValues, deviceId: $deviceId, operationName: $operationName, functionValue: $functionValue, deviceIcon: $deviceIcon, operationDialogType: $operationDialogType, comparator: $comparator)';
|
||||
return 'SceneStaticFunction(icon: $icon, name: $deviceName, code: $code, operationalValues: $operationalValues, deviceId: $deviceId, operationName: $operationName, functionValue: $functionValue, deviceIcon: $deviceIcon, operationDialogType: $operationDialogType, comparator: $comparator, uniqueCustomId: $uniqueCustomId)';
|
||||
}
|
||||
|
||||
@override
|
||||
@ -113,6 +118,7 @@ class SceneStaticFunction {
|
||||
other.functionValue == functionValue &&
|
||||
other.deviceIcon == deviceIcon &&
|
||||
other.comparator == comparator &&
|
||||
other.uniqueCustomId == uniqueCustomId &&
|
||||
other.operationDialogType == operationDialogType &&
|
||||
listEquals(other.operationalValues, operationalValues) &&
|
||||
other.deviceId == deviceId;
|
||||
@ -128,6 +134,7 @@ class SceneStaticFunction {
|
||||
functionValue.hashCode ^
|
||||
deviceIcon.hashCode ^
|
||||
comparator.hashCode ^
|
||||
uniqueCustomId.hashCode ^
|
||||
operationDialogType.hashCode ^
|
||||
operationalValues.hashCode;
|
||||
}
|
||||
|
||||
@ -202,7 +202,7 @@ class DeviceFunctionsView extends StatelessWidget
|
||||
operation: function.operationName,
|
||||
icon: device.icon ?? '',
|
||||
deviceName: device.name ?? '',
|
||||
uniqueId: function.uniqueCustomId,
|
||||
uniqueId: function.uniqueCustomId!,
|
||||
operationType: function.operationDialogType,
|
||||
));
|
||||
Navigator.pop(context);
|
||||
@ -253,7 +253,7 @@ class DeviceFunctionsView extends StatelessWidget
|
||||
operation: function.operationName,
|
||||
icon: device.icon ?? '',
|
||||
deviceName: device.name ?? '',
|
||||
uniqueId: function.uniqueCustomId,
|
||||
uniqueId: function.uniqueCustomId!,
|
||||
operationType: function.operationDialogType,
|
||||
isAutomation: true,
|
||||
));
|
||||
|
||||
@ -29,6 +29,9 @@ class SceneTasksView extends StatelessWidget {
|
||||
|
||||
final isAutomation =
|
||||
sceneSettings.sceneType == CreateSceneEnum.deviceStatusChanges.name;
|
||||
// context.read<CreateSceneBloc>().add(SceneTypeEvent(isAutomation
|
||||
// ? CreateSceneEnum.deviceStatusChanges
|
||||
// : CreateSceneEnum.tabToRun));
|
||||
|
||||
return DefaultScaffold(
|
||||
title: sceneSettings.sceneName.isNotEmpty
|
||||
|
||||
@ -19,6 +19,7 @@ class SmartAutomationSelectView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final sceneType = context.read<CreateSceneBloc>().sceneType;
|
||||
final sceneId = ModalRoute.of(context)!.settings.arguments as String;
|
||||
return DefaultScaffold(
|
||||
title: "Select Smart Scene",
|
||||
padding: const EdgeInsets.only(top: 24),
|
||||
@ -41,7 +42,8 @@ class SmartAutomationSelectView extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Visibility(
|
||||
visible: sceneType.name == CreateSceneEnum.deviceStatusChanges.name,
|
||||
visible: sceneType.name ==
|
||||
CreateSceneEnum.deviceStatusChanges.name,
|
||||
child: SceneListTile(
|
||||
assetPath: Assets.handClickIcon,
|
||||
titleString: "Tap To Run",
|
||||
@ -58,7 +60,8 @@ class SmartAutomationSelectView extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: sceneType.name == CreateSceneEnum.deviceStatusChanges.name,
|
||||
visible: sceneType.name ==
|
||||
CreateSceneEnum.deviceStatusChanges.name,
|
||||
child: const Divider(
|
||||
color: ColorsManager.dividerColor,
|
||||
),
|
||||
@ -73,7 +76,7 @@ class SmartAutomationSelectView extends StatelessWidget {
|
||||
),
|
||||
onPressed: () {
|
||||
context.customBottomSheet(
|
||||
child: const SmartEnableAutomation(),
|
||||
child: SmartEnableAutomation(automationId: sceneId),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
@ -31,6 +31,10 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
|
||||
super.didChangeDependencies();
|
||||
final createSceneBloc = context.read<CreateSceneBloc>();
|
||||
|
||||
if (widget.taskItem.comparator != null) {
|
||||
selectedToggleIndex = _comparatorToIndex(widget.taskItem.comparator);
|
||||
}
|
||||
|
||||
if (widget.isAutomation) {
|
||||
final automationTempTaskList = createSceneBloc.automationTempTasksList;
|
||||
final automationComparatorValues =
|
||||
@ -52,15 +56,20 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
|
||||
_normalizeValue(widget.taskItem.operationalValues[0].minValue);
|
||||
}
|
||||
|
||||
if (widget.taskItem.comparator != null) {
|
||||
selectedToggleIndex = _comparatorToIndex(widget.taskItem.comparator);
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
|
||||
context.read<CreateSceneBloc>().add(
|
||||
SelectedValueEvent(
|
||||
value: _deNormalizeValue(groupValue),
|
||||
code: widget.taskItem.code,
|
||||
isAutomation: widget.isAutomation,
|
||||
comparator: _indexToComparator(selectedToggleIndex),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
double _normalizeValue(dynamic value) {
|
||||
if (((widget.taskItem.code == "temp_set" && value > 200) ||
|
||||
if (((widget.taskItem.code == "temp_set" && value > 199) ||
|
||||
widget.taskItem.code == "temp_current")) {
|
||||
return (value) / 10;
|
||||
}
|
||||
|
||||
@ -49,13 +49,18 @@ class _AlertDialogTemperatureBodyState
|
||||
temperature = _normalizeTemperature(widget.functionValue);
|
||||
});
|
||||
}
|
||||
|
||||
// context.read<CreateSceneBloc>().add(SelectedValueEvent(
|
||||
// value: temperature * 10,
|
||||
// code: widget.taskItem.code,
|
||||
// ));
|
||||
}
|
||||
|
||||
int _normalizeTemperature(dynamic value) {
|
||||
if (value is int && value >= 100) {
|
||||
if (value >= 100) {
|
||||
return value ~/ 10;
|
||||
}
|
||||
return value as int? ?? 24;
|
||||
return value ?? 24;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -17,7 +17,9 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
class CustomBottomSheetWidget extends StatelessWidget {
|
||||
const CustomBottomSheetWidget({
|
||||
super.key,
|
||||
required this.sceneId,
|
||||
});
|
||||
final String sceneId;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -58,7 +60,7 @@ class CustomBottomSheetWidget extends StatelessWidget {
|
||||
),
|
||||
SceneListTile(
|
||||
assetPath: Assets.player,
|
||||
titleString: 'Select Automation',
|
||||
titleString: 'Select Smart Scene',
|
||||
minLeadingWidth: 30,
|
||||
assetHeight: 24,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
@ -68,7 +70,7 @@ class CustomBottomSheetWidget extends StatelessWidget {
|
||||
color: ColorsManager.greyColor,
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, Routes.smartAutomationSelectRoute);
|
||||
Navigator.pushNamed(context, Routes.smartAutomationSelectRoute, arguments: sceneId);
|
||||
},
|
||||
),
|
||||
SceneListTile(
|
||||
@ -90,8 +92,7 @@ class CustomBottomSheetWidget extends StatelessWidget {
|
||||
}
|
||||
|
||||
void _onDelayActionPressed(BuildContext context) {
|
||||
final functionValues =
|
||||
context.read<CreateSceneBloc>().selectedValues['delay'];
|
||||
final functionValues = context.read<CreateSceneBloc>().selectedValues['delay'];
|
||||
final functions = [
|
||||
SceneStaticFunction(
|
||||
deviceId: 'delay',
|
||||
@ -114,8 +115,7 @@ class CustomBottomSheetWidget extends StatelessWidget {
|
||||
),
|
||||
title: functions[0].operationName,
|
||||
onConfirm: () {
|
||||
final selectedValue =
|
||||
context.read<CreateSceneBloc>().selectedValues['delay'];
|
||||
final selectedValue = context.read<CreateSceneBloc>().selectedValues['delay'];
|
||||
context.read<CreateSceneBloc>().add(TempHoldSceneTasksEvent(
|
||||
deviceControlModel: DeviceControlModel(
|
||||
deviceId: '',
|
||||
@ -126,7 +126,7 @@ class CustomBottomSheetWidget extends StatelessWidget {
|
||||
operation: functions[0].operationName,
|
||||
icon: Assets.delay,
|
||||
deviceName: 'Delay The Action',
|
||||
uniqueId: functions[0].uniqueCustomId,
|
||||
uniqueId: functions[0].uniqueCustomId!,
|
||||
operationType: functions[0].operationDialogType,
|
||||
));
|
||||
context.read<CreateSceneBloc>().add(const AddTaskEvent());
|
||||
@ -138,9 +138,7 @@ class CustomBottomSheetWidget extends StatelessWidget {
|
||||
|
||||
for (var element in tempTaskList) {
|
||||
if (element.code == functions[0].code) {
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(RemoveTempTaskByIdEvent(code: functions[0].code));
|
||||
context.read<CreateSceneBloc>().add(RemoveTempTaskByIdEvent(code: functions[0].code));
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(RemoveFromSelectedValueById(code: functions[0].code));
|
||||
|
||||
@ -24,14 +24,13 @@ class CreateSceneSaveButton extends StatefulWidget {
|
||||
State<CreateSceneSaveButton> createState() => _CreateSceneSaveButtonState();
|
||||
}
|
||||
|
||||
class _CreateSceneSaveButtonState extends State<CreateSceneSaveButton>
|
||||
with SceneLogicHelper {
|
||||
class _CreateSceneSaveButtonState extends State<CreateSceneSaveButton> with SceneLogicHelper {
|
||||
late TextEditingController sceneNameController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
sceneNameController = TextEditingController(
|
||||
text: widget.sceneName.isNotEmpty ? widget.sceneName : '');
|
||||
sceneNameController =
|
||||
TextEditingController(text: widget.sceneName.isNotEmpty ? widget.sceneName : '');
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@ -46,15 +45,8 @@ class _CreateSceneSaveButtonState extends State<CreateSceneSaveButton>
|
||||
return BlocConsumer<CreateSceneBloc, CreateSceneState>(
|
||||
listener: (context, state) {
|
||||
if (state is CreateSceneWithTasks) {
|
||||
if (state.success == true) {
|
||||
if (state.success) {
|
||||
navigateToRoute(context, Routes.homeRoute);
|
||||
context.showCustomSnackbar(
|
||||
message: 'Scene created successfully',
|
||||
icon: const Icon(
|
||||
Icons.check,
|
||||
color: Colors.green,
|
||||
),
|
||||
);
|
||||
sceneNameController.text = '';
|
||||
}
|
||||
} else if (state is CreateSceneError) {
|
||||
@ -65,8 +57,24 @@ class _CreateSceneSaveButtonState extends State<CreateSceneSaveButton>
|
||||
return DefaultButton(
|
||||
onPressed: () {
|
||||
final sceneBloc = context.read<CreateSceneBloc>();
|
||||
final isAutomation =
|
||||
sceneBloc.sceneType == CreateSceneEnum.deviceStatusChanges;
|
||||
if (sceneBloc.tasksList.isEmpty && sceneBloc.automationTasksList.isEmpty) {
|
||||
return;
|
||||
}
|
||||
final isAutomation = sceneBloc.sceneType == CreateSceneEnum.deviceStatusChanges;
|
||||
|
||||
if (isAutomation && sceneBloc.automationTasksList.isEmpty) {
|
||||
CustomSnackBar.displaySnackBar(
|
||||
'Conditions Must not be empty!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAutomation && sceneBloc.tasksList.isEmpty) {
|
||||
CustomSnackBar.displaySnackBar(
|
||||
'Actions Must not be empty!',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (widget.sceneName.isNotEmpty) {
|
||||
handleSaveButtonPress(
|
||||
@ -89,13 +97,11 @@ class _CreateSceneSaveButtonState extends State<CreateSceneSaveButton>
|
||||
elevation: WidgetStateProperty.all(0),
|
||||
textStyle: WidgetStateProperty.all(context.bodyMedium),
|
||||
hintStyle: WidgetStateProperty.all(
|
||||
context.bodyMedium.copyWith(
|
||||
fontSize: 14,
|
||||
color: ColorsManager.secondaryTextColor),
|
||||
context.bodyMedium
|
||||
.copyWith(fontSize: 14, color: ColorsManager.secondaryTextColor),
|
||||
),
|
||||
hintText: 'Enter scene name',
|
||||
backgroundColor: WidgetStateProperty.all(
|
||||
ColorsManager.backgroundColor),
|
||||
backgroundColor: WidgetStateProperty.all(ColorsManager.backgroundColor),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@ -19,6 +19,8 @@ import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
import '../../../../navigation/navigation_service.dart';
|
||||
|
||||
class ThenAddedTasksContainer extends StatelessWidget
|
||||
with SceneOperationsDataHelper, SceneLogicHelper {
|
||||
ThenAddedTasksContainer({
|
||||
@ -48,9 +50,9 @@ class ThenAddedTasksContainer extends StatelessWidget
|
||||
"${duration.inHours}h ${duration.inMinutes.remainder(60)}m ";
|
||||
} else if (taskItem.code.contains('temp_set') ||
|
||||
taskItem.code.contains('temp_current')) {
|
||||
if (taskItem.functionValue != null || taskItem.functionValue != 0) {
|
||||
if ((taskItem.functionValue != null || taskItem.functionValue != 0)) {
|
||||
operationValue =
|
||||
'${((taskItem.functionValue / 10) as double).round().toString()}°C';
|
||||
'${((taskItem.functionValue / 10) as double).toStringAsFixed(1)}°C';
|
||||
} else {
|
||||
operationValue = '0°C';
|
||||
}
|
||||
@ -121,7 +123,7 @@ class ThenAddedTasksContainer extends StatelessWidget
|
||||
createSceneBloc.add(
|
||||
UpdateTaskEvent(
|
||||
newValue: automationSelectedValue,
|
||||
taskId: taskItem.uniqueCustomId,
|
||||
taskId: taskItem.uniqueCustomId!,
|
||||
isAutomation: true,
|
||||
),
|
||||
);
|
||||
@ -136,7 +138,7 @@ class ThenAddedTasksContainer extends StatelessWidget
|
||||
createSceneBloc.add(
|
||||
UpdateTaskEvent(
|
||||
newValue: selectedValue,
|
||||
taskId: taskItem.uniqueCustomId,
|
||||
taskId: taskItem.uniqueCustomId!,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
@ -144,7 +146,10 @@ class ThenAddedTasksContainer extends StatelessWidget
|
||||
}
|
||||
}
|
||||
|
||||
Navigator.pop(context);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
Navigator.pop(
|
||||
NavigationService.navigatorKey.currentContext!);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -172,7 +177,7 @@ class ThenAddedTasksContainer extends StatelessWidget
|
||||
),
|
||||
direction: DismissDirection.endToStart,
|
||||
onDismissed: (direction) {
|
||||
String removeFunctionById = taskItem.uniqueCustomId;
|
||||
String removeFunctionById = taskItem.uniqueCustomId!;
|
||||
|
||||
if (isAutomation == true) {
|
||||
context.read<CreateSceneBloc>().add(RemoveTaskByIdEvent(
|
||||
|
||||
@ -47,7 +47,7 @@ class ThenDefaultContainer extends StatelessWidget {
|
||||
return GestureDetector(
|
||||
onTap: isClickable
|
||||
? () => context.customBottomSheet(
|
||||
child: const CustomBottomSheetWidget(),
|
||||
child: CustomBottomSheetWidget(sceneId: sceneId),
|
||||
)
|
||||
: null,
|
||||
child: SvgPicture.asset(
|
||||
@ -99,7 +99,9 @@ class ThenDefaultContainer extends StatelessWidget {
|
||||
builder: (context) => const CreateSceneView()));
|
||||
} else {
|
||||
context.customBottomSheet(
|
||||
child: const CustomBottomSheetWidget(),
|
||||
child: CustomBottomSheetWidget(
|
||||
sceneId: sceneId,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
@ -118,7 +118,7 @@ class SceneDevicesBody extends StatelessWidget {
|
||||
},
|
||||
);
|
||||
} else if (state.error != null) {
|
||||
return Center(child: Text(state.error!));
|
||||
return const Center(child: Text('Something went wrong'));
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
|
||||
@ -35,6 +35,23 @@ class SceneItem extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return DefaultContainer(
|
||||
onTap: () {
|
||||
context.read<SmartSceneSelectBloc>().add(const SmartSceneClearEvent());
|
||||
if (disablePlayButton == false) {
|
||||
BlocProvider.of<CreateSceneBloc>(context).add(
|
||||
FetchSceneTasksEvent(sceneId: scene.id, isAutomation: false));
|
||||
|
||||
/// the state to set the scene type must be after the fetch
|
||||
BlocProvider.of<CreateSceneBloc>(context)
|
||||
.add(const SceneTypeEvent(CreateSceneEnum.tabToRun));
|
||||
} else {
|
||||
BlocProvider.of<CreateSceneBloc>(context)
|
||||
.add(FetchSceneTasksEvent(sceneId: scene.id, isAutomation: true));
|
||||
|
||||
/// the state to set the scene type must be after the fetch
|
||||
BlocProvider.of<CreateSceneBloc>(context)
|
||||
.add(const SceneTypeEvent(CreateSceneEnum.deviceStatusChanges));
|
||||
}
|
||||
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
Routes.sceneTasksRoute,
|
||||
@ -46,18 +63,6 @@ class SceneItem extends StatelessWidget {
|
||||
sceneName: scene.name,
|
||||
),
|
||||
);
|
||||
context.read<SmartSceneSelectBloc>().add(const SmartSceneClearEvent());
|
||||
if (disablePlayButton == false) {
|
||||
BlocProvider.of<CreateSceneBloc>(context)
|
||||
.add(const SceneTypeEvent(CreateSceneEnum.tabToRun));
|
||||
BlocProvider.of<CreateSceneBloc>(context).add(
|
||||
FetchSceneTasksEvent(sceneId: scene.id, isAutomation: false));
|
||||
} else {
|
||||
BlocProvider.of<CreateSceneBloc>(context)
|
||||
.add(const SceneTypeEvent(CreateSceneEnum.deviceStatusChanges));
|
||||
BlocProvider.of<CreateSceneBloc>(context)
|
||||
.add(FetchSceneTasksEvent(sceneId: scene.id, isAutomation: true));
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
@ -15,15 +15,19 @@ class SmartSceneSelectAutomationList extends StatefulWidget {
|
||||
const SmartSceneSelectAutomationList({
|
||||
super.key,
|
||||
required this.automationList,
|
||||
required this.automationId,
|
||||
});
|
||||
|
||||
final List<ScenesModel> automationList;
|
||||
final String automationId;
|
||||
|
||||
@override
|
||||
State<SmartSceneSelectAutomationList> createState() => _SmartSceneSelectAutomationListState();
|
||||
State<SmartSceneSelectAutomationList> createState() =>
|
||||
_SmartSceneSelectAutomationListState();
|
||||
}
|
||||
|
||||
class _SmartSceneSelectAutomationListState extends State<SmartSceneSelectAutomationList> {
|
||||
class _SmartSceneSelectAutomationListState
|
||||
extends State<SmartSceneSelectAutomationList> {
|
||||
final List<Color> colorList = _generateDarkColors(100);
|
||||
|
||||
static List<Color> _generateDarkColors(int count) {
|
||||
@ -31,7 +35,8 @@ class _SmartSceneSelectAutomationListState extends State<SmartSceneSelectAutomat
|
||||
final colors = <Color>[];
|
||||
|
||||
while (colors.length < count) {
|
||||
final color = Color((random.nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
|
||||
final color =
|
||||
Color((random.nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
|
||||
if (_isDark(color)) {
|
||||
colors.add(color);
|
||||
}
|
||||
@ -40,12 +45,17 @@ class _SmartSceneSelectAutomationListState extends State<SmartSceneSelectAutomat
|
||||
}
|
||||
|
||||
static bool _isDark(Color color) {
|
||||
final brightness = ((color.red * 299) + (color.green * 587) + (color.blue * 114)) / 1000;
|
||||
final brightness =
|
||||
((color.red * 299) + (color.green * 587) + (color.blue * 114)) / 1000;
|
||||
return brightness < 128;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Filter the automation list to exclude the sceneId
|
||||
final filteredAutomationList = widget.automationList
|
||||
.where((e) => e.id != widget.automationId.toString())
|
||||
.toList();
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@ -70,7 +80,8 @@ class _SmartSceneSelectAutomationListState extends State<SmartSceneSelectAutomat
|
||||
text: 'Automation',
|
||||
textAlign: TextAlign.center,
|
||||
style: context.bodyMedium.copyWith(
|
||||
color: ColorsManager.primaryColorWithOpacity, fontWeight: FontWeight.bold),
|
||||
color: ColorsManager.primaryColorWithOpacity,
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -89,12 +100,15 @@ class _SmartSceneSelectAutomationListState extends State<SmartSceneSelectAutomat
|
||||
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: widget.automationList.length,
|
||||
itemCount: filteredAutomationList.length,
|
||||
itemBuilder: (context, index) {
|
||||
final automation = widget.automationList[index];
|
||||
final isSelected = smartSceneEnable?.entityId == automation.id;
|
||||
final automation = filteredAutomationList[index];
|
||||
final isSelected =
|
||||
smartSceneEnable?.entityId == automation.id;
|
||||
final descriptionSelected = isSelected
|
||||
? (smartSceneEnable?.actionExecutor == 'rule_enable' ? 'Enable' : 'Disable')
|
||||
? (smartSceneEnable?.actionExecutor == 'rule_enable'
|
||||
? 'Enable'
|
||||
: 'Disable')
|
||||
: automation.status == 'enable'
|
||||
? 'Enable'
|
||||
: 'Disable';
|
||||
@ -128,14 +142,17 @@ class _SmartSceneSelectAutomationListState extends State<SmartSceneSelectAutomat
|
||||
Navigator.pop(context);
|
||||
},
|
||||
onDismiss: () {
|
||||
context.read<SmartSceneSelectBloc>().add(const SmartSceneClearEvent());
|
||||
context
|
||||
.read<SmartSceneSelectBloc>()
|
||||
.add(const SmartSceneClearEvent());
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
label: BodyMedium(
|
||||
text: _capitalizeFirst(descriptionSelected),
|
||||
style: context.bodyMedium.copyWith(color: ColorsManager.greyColor),
|
||||
style: context.bodyMedium
|
||||
.copyWith(color: ColorsManager.greyColor),
|
||||
),
|
||||
icon: const Icon(
|
||||
Icons.arrow_forward_ios_rounded,
|
||||
@ -162,7 +179,9 @@ class _SmartSceneSelectAutomationListState extends State<SmartSceneSelectAutomat
|
||||
Navigator.pop(context);
|
||||
},
|
||||
onDismiss: () {
|
||||
context.read<SmartSceneSelectBloc>().add(const SmartSceneClearEvent());
|
||||
context
|
||||
.read<SmartSceneSelectBloc>()
|
||||
.add(const SmartSceneClearEvent());
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
@ -198,10 +217,12 @@ class EnableDisableAutomationDialog extends StatefulWidget {
|
||||
final String type;
|
||||
|
||||
@override
|
||||
State<EnableDisableAutomationDialog> createState() => _EnableDisableAutomationDialogState();
|
||||
State<EnableDisableAutomationDialog> createState() =>
|
||||
_EnableDisableAutomationDialogState();
|
||||
}
|
||||
|
||||
class _EnableDisableAutomationDialogState extends State<EnableDisableAutomationDialog> {
|
||||
class _EnableDisableAutomationDialogState
|
||||
extends State<EnableDisableAutomationDialog> {
|
||||
String? groupValue;
|
||||
final List<SceneOperationalValue> values = [
|
||||
SceneOperationalValue(
|
||||
@ -219,14 +240,16 @@ class _EnableDisableAutomationDialogState extends State<EnableDisableAutomationD
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
groupValue = widget.descriptionSelected == 'Enable' ? 'rule_enable' : 'rule_disable';
|
||||
groupValue =
|
||||
widget.descriptionSelected == 'Enable' ? 'rule_enable' : 'rule_disable';
|
||||
|
||||
context.read<SmartSceneSelectBloc>().add(SmartSceneEnableEvent(SmartSceneEnable(
|
||||
entityId: widget.automationId,
|
||||
actionExecutor: groupValue!,
|
||||
sceneORAutomationName: widget.sceneORAutomationName,
|
||||
type: widget.type,
|
||||
isAutomation: true)));
|
||||
context.read<SmartSceneSelectBloc>().add(SmartSceneEnableEvent(
|
||||
SmartSceneEnable(
|
||||
entityId: widget.automationId,
|
||||
actionExecutor: groupValue!,
|
||||
sceneORAutomationName: widget.sceneORAutomationName,
|
||||
type: widget.type,
|
||||
isAutomation: true)));
|
||||
}
|
||||
|
||||
@override
|
||||
@ -252,11 +275,14 @@ class _EnableDisableAutomationDialogState extends State<EnableDisableAutomationD
|
||||
setState(() {
|
||||
groupValue = value;
|
||||
});
|
||||
context.read<SmartSceneSelectBloc>().add(SmartSceneEnableEvent(
|
||||
context
|
||||
.read<SmartSceneSelectBloc>()
|
||||
.add(SmartSceneEnableEvent(
|
||||
SmartSceneEnable(
|
||||
entityId: widget.automationId,
|
||||
actionExecutor: value!,
|
||||
sceneORAutomationName: widget.sceneORAutomationName,
|
||||
sceneORAutomationName:
|
||||
widget.sceneORAutomationName,
|
||||
type: widget.type,
|
||||
isAutomation: true),
|
||||
));
|
||||
@ -266,7 +292,9 @@ class _EnableDisableAutomationDialogState extends State<EnableDisableAutomationD
|
||||
setState(() {
|
||||
groupValue = operation.value;
|
||||
});
|
||||
context.read<SmartSceneSelectBloc>().add(SmartSceneEnableEvent(
|
||||
context
|
||||
.read<SmartSceneSelectBloc>()
|
||||
.add(SmartSceneEnableEvent(
|
||||
SmartSceneEnable(
|
||||
entityId: widget.automationId,
|
||||
actionExecutor: operation.value,
|
||||
|
||||
@ -10,7 +10,9 @@ import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
|
||||
class SmartEnableAutomation extends StatelessWidget {
|
||||
const SmartEnableAutomation({super.key});
|
||||
const SmartEnableAutomation({super.key, required this.automationId});
|
||||
|
||||
final String automationId;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -29,6 +31,7 @@ class SmartEnableAutomation extends StatelessWidget {
|
||||
}
|
||||
if (state is SceneLoaded) {
|
||||
return SmartSceneSelectAutomationList(
|
||||
automationId: automationId,
|
||||
automationList: state.automationList);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
|
||||
@ -13,6 +13,7 @@ class HomeManagementAPI {
|
||||
var userId = await storage.read(key: UserModel.userUuidKey) ?? '';
|
||||
|
||||
List<DeviceModel> list = [];
|
||||
|
||||
await _httpService.get(
|
||||
path: ApiEndpoints.getDevicesByUserId.replaceAll("{userId}", userId),
|
||||
showServerMessage: false,
|
||||
@ -21,14 +22,15 @@ class HomeManagementAPI {
|
||||
list.add(DeviceModel.fromJson(value));
|
||||
});
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
static Future<List<DeviceModel>> fetchDevicesByUnitId() async {
|
||||
List<DeviceModel> list = [];
|
||||
await _httpService.get(
|
||||
path: ApiEndpoints.getDevicesByUnitId
|
||||
.replaceAll("{unitUuid}", HomeCubit.getInstance().selectedSpace?.id ?? ''),
|
||||
path: ApiEndpoints.getDevicesByUnitId.replaceAll(
|
||||
"{unitUuid}", HomeCubit.getInstance().selectedSpace?.id ?? ''),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
json.forEach((value) {
|
||||
@ -38,7 +40,8 @@ class HomeManagementAPI {
|
||||
return list;
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> assignDeviceToRoom(Map<String, String> body) async {
|
||||
static Future<Map<String, dynamic>> assignDeviceToRoom(
|
||||
Map<String, String> body) async {
|
||||
try {
|
||||
final response = await _httpService.put(
|
||||
path: ApiEndpoints.assignDeviceToRoom,
|
||||
|
||||
@ -30,7 +30,7 @@ class CustomSnackBar {
|
||||
Text(
|
||||
message,
|
||||
style: Theme.of(currentContext).textTheme.bodySmall!.copyWith(
|
||||
fontSize: 14, fontWeight: FontWeight.w500, color: Colors.green),
|
||||
fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white),
|
||||
)
|
||||
]),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user