mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 11:37:56 +00:00
four_scene&6scene
This commit is contained in:
@@ -4,9 +4,11 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_state.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_report_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/group_devices_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/scene_switch_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/sex_scene_question_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/six_scene_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
||||
@@ -15,40 +17,100 @@ import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/services/api/devices_api.dart';
|
||||
import 'package:syncrow_app/services/api/scene_api.dart';
|
||||
import 'package:syncrow_app/services/api/spaces_api.dart';
|
||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||
|
||||
class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
final String sixSceneId;
|
||||
SixSceneBloc({
|
||||
required this.sixSceneId,
|
||||
}) : super(const SixSceneState()) {
|
||||
on<SixSceneInitial>(_fetchStatus);
|
||||
on<ReportLogsInitial>(fetchLogsForLastMonth);
|
||||
on<SixSceneInitial>(_fetchDeviceStatus);
|
||||
on<ToggleNotificationEvent>(_toggleNotification);
|
||||
on<ChangeNameEvent>(_changeName);
|
||||
on<SearchFaqEvent>(_onSearchFaq);
|
||||
on<FetchRoomsEvent>(_fetchRoomsAndDevices);
|
||||
on<ChangeSwitchStatusEvent>(changeSwitchStatus);
|
||||
on<LoadScenes>(_onLoadScenes);
|
||||
on<SelectSceneEvent>(_selectScene);
|
||||
on<SearchScenesEvent>(searchScene);
|
||||
on<SaveSelectionEvent>(_onSaveSelection);
|
||||
on<SelectOptionEvent>(_onOptionSelected);
|
||||
on<AddDeviceToGroup>(_addDeviceToGroup); // Register handler here
|
||||
on<RemoveDeviceFromGroup>(_removeDeviceFromGroup);
|
||||
on<SexSceneSwitchInitial>(_fetchFourSceneSwitches);
|
||||
on<AssignDeviceScene>(assignScene);
|
||||
on<GetSceneBySwitchName>(getSceneByName);
|
||||
on<SelectSceneEvent>(_selectScene);
|
||||
on<SixSceneInitialInfo>(fetchDeviceInfo);
|
||||
on<ControlDeviceScene>(_controlDevice);
|
||||
}
|
||||
|
||||
final TextEditingController nameController =
|
||||
TextEditingController(text: '${'firstName'}');
|
||||
TextEditingController(text: deviceName);
|
||||
bool isSaving = false;
|
||||
bool editName = false;
|
||||
final FocusNode focusNode = FocusNode();
|
||||
bool closingReminder = false;
|
||||
bool waterAlarm = false;
|
||||
static String deviceName = '';
|
||||
|
||||
SixSceneModel deviceStatus =
|
||||
SixSceneModel(waterContactState: 'normal', batteryPercentage: 0);
|
||||
SixSceneModel deviceStatus = SixSceneModel(
|
||||
scene_1: '',
|
||||
scene_2: '',
|
||||
scene_3: '',
|
||||
scene_4: '',
|
||||
scene_5: '',
|
||||
scene_6: '',
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: false);
|
||||
|
||||
void _fetchStatus(SixSceneInitial event, Emitter<SixSceneState> emit) async {
|
||||
SceneSwitch deviceInfo = SceneSwitch(
|
||||
activeTime: 0,
|
||||
category: "",
|
||||
categoryName: "",
|
||||
createTime: 0,
|
||||
gatewayId: "",
|
||||
icon: "",
|
||||
ip: "",
|
||||
lat: "",
|
||||
localKey: "",
|
||||
lon: "",
|
||||
model: "",
|
||||
name: "",
|
||||
nodeId: "",
|
||||
online: false,
|
||||
ownerId: "",
|
||||
productName: "",
|
||||
sub: false,
|
||||
timeZone: "",
|
||||
updateTime: 0,
|
||||
uuid: "",
|
||||
productUuid: "",
|
||||
productType: "",
|
||||
permissionType: "",
|
||||
macAddress: "",
|
||||
subspace: Subspace(
|
||||
uuid: "",
|
||||
createdAt: "",
|
||||
updatedAt: "",
|
||||
subspaceName: "",
|
||||
),
|
||||
);
|
||||
|
||||
Future fetchDeviceInfo(
|
||||
SixSceneInitialInfo event, Emitter<SixSceneState> emit) async {
|
||||
try {
|
||||
emit(SixSceneLoadingState());
|
||||
var response = await DevicesAPI.getDeviceInfo(sixSceneId);
|
||||
deviceInfo = SceneSwitch.fromJson(response);
|
||||
deviceName = deviceInfo.name;
|
||||
emit(LoadingDeviceInfo(deviceInfo: deviceInfo));
|
||||
} catch (e) {
|
||||
emit(SixSceneFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
void _fetchDeviceStatus(
|
||||
SixSceneInitial event, Emitter<SixSceneState> emit) async {
|
||||
emit(SixSceneLoadingState());
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(sixSceneId);
|
||||
@@ -59,16 +121,90 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
deviceStatus = SixSceneModel.fromJson(
|
||||
statusModelList,
|
||||
);
|
||||
add(const SexSceneSwitchInitial());
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
|
||||
Future.delayed(const Duration(milliseconds: 500));
|
||||
// _listenToChanges();
|
||||
} catch (e) {
|
||||
emit(SixSceneFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String selectedFormApiSceneId = '';
|
||||
|
||||
void getSceneByName(
|
||||
GetSceneBySwitchName event, Emitter<SixSceneState> emit) async {
|
||||
emit(SixSceneLoadingState());
|
||||
try {
|
||||
final response = await DevicesAPI.getSceneBySwitchName(
|
||||
deviceId: sixSceneId, switchName: event.switchName);
|
||||
selectedFormApiSceneId = response['scene']['uuid'];
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(SixSceneFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
String selectedSceneId = '';
|
||||
|
||||
_selectScene(SelectSceneEvent event, Emitter<SixSceneState> emit) {
|
||||
emit(SixSceneLoadingState());
|
||||
selectedSceneId = event.unitId;
|
||||
emit(SceneSelectionUpdatedState(selectedSceneId: selectedSceneId));
|
||||
}
|
||||
|
||||
List<SixSceneModel> fourScene = [];
|
||||
|
||||
void _fetchFourSceneSwitches(
|
||||
SexSceneSwitchInitial event, Emitter<SixSceneState> emit) async {
|
||||
emit(SixSceneLoadingState());
|
||||
try {
|
||||
var response = await DevicesAPI.getFourSceneInfo(sixSceneId);
|
||||
Map<String, String> sceneTitles = {
|
||||
"scene_1": '',
|
||||
"scene_2": '',
|
||||
"scene_3": '',
|
||||
"scene_4": '',
|
||||
"scene_5": '',
|
||||
"scene_6": '',
|
||||
};
|
||||
for (var item in response) {
|
||||
if (item["switchName"] != null) {
|
||||
sceneTitles[item["switchName"]] = item["scene"]["name"] ?? '';
|
||||
}
|
||||
}
|
||||
SixSceneModel deviceStatus = SixSceneModel(
|
||||
scene_1: sceneTitles["scene_1"] ?? '',
|
||||
scene_2: sceneTitles["scene_2"] ?? '',
|
||||
scene_3: sceneTitles["scene_3"] ?? '',
|
||||
scene_4: sceneTitles["scene_4"] ?? '',
|
||||
scene_5: sceneTitles["scene_5"] ?? '',
|
||||
scene_6: sceneTitles["scene_6"] ?? '',
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '',
|
||||
);
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(SixSceneFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void assignScene(AssignDeviceScene event, Emitter<SixSceneState> emit) async {
|
||||
emit(SixSceneLoadingState());
|
||||
try {
|
||||
final response = await DevicesAPI.postFourSceneInfo(
|
||||
deviceId: sixSceneId,
|
||||
sceneUuid: event.sceneUuid,
|
||||
spaceUuid: event.unit!.id,
|
||||
switchName: event.switchName);
|
||||
|
||||
emit(SaveSelectionSuccessState());
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
} catch (e) {
|
||||
emit(SixSceneFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
void _onSearchFaq(SearchFaqEvent event, Emitter<SixSceneState> emit) {
|
||||
emit(SixSceneLoadingState());
|
||||
// Filter FAQ questions based on search query
|
||||
@@ -77,8 +213,6 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
.toLowerCase()
|
||||
.contains(event.query.toLowerCase());
|
||||
}).toList();
|
||||
|
||||
print(_faqQuestions);
|
||||
emit(FaqSearchState(filteredFaqQuestions: _faqQuestions));
|
||||
}
|
||||
|
||||
@@ -101,16 +235,6 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
try {
|
||||
closingReminder = event.isClosingEnabled;
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
|
||||
// API call to update the state, if necessary
|
||||
// await DevicesAPI.controlDevice(
|
||||
// DeviceControlModel(
|
||||
// deviceId: sosId,
|
||||
// code: 'closing_reminder',
|
||||
// value: closingReminder,
|
||||
// ),
|
||||
// sosId,
|
||||
// );
|
||||
} catch (e) {
|
||||
emit(SixSceneFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
@@ -119,29 +243,6 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
DeviceReport recordGroups =
|
||||
DeviceReport(startTime: '0', endTime: '0', data: []);
|
||||
|
||||
Future<void> fetchLogsForLastMonth(
|
||||
ReportLogsInitial event, Emitter<SixSceneState> emit) async {
|
||||
DateTime now = DateTime.now();
|
||||
DateTime lastMonth = DateTime(now.year, now.month - 1, now.day);
|
||||
int startTime = lastMonth.millisecondsSinceEpoch;
|
||||
int endTime = now.millisecondsSinceEpoch;
|
||||
try {
|
||||
emit(SixSceneLoadingState());
|
||||
var response = await DevicesAPI.getReportLogs(
|
||||
startTime: startTime.toString(),
|
||||
endTime: endTime.toString(),
|
||||
deviceUuid: sixSceneId,
|
||||
code: 'sossensor_state',
|
||||
);
|
||||
recordGroups = response;
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
} on DioException catch (e) {
|
||||
final errorData = e.response!.data;
|
||||
String errorMessage = errorData['message'];
|
||||
emit(SixSceneFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
final List<SixSceneQuestionModel> faqQuestions = [
|
||||
SixSceneQuestionModel(
|
||||
id: 1,
|
||||
@@ -196,15 +297,28 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
}
|
||||
|
||||
bool switchStatus = true;
|
||||
void changeSwitchStatus(
|
||||
ChangeSwitchStatusEvent event, Emitter<SixSceneState> emit) {
|
||||
emit(SixSceneLoadingState());
|
||||
switchStatus = !switchStatus;
|
||||
emit(ChangeSwitchState(isEnable: switchStatus));
|
||||
Future<void> changeSwitchStatus(
|
||||
ChangeSwitchStatusEvent event, Emitter<SixSceneState> emit) async {
|
||||
try {
|
||||
emit(SixSceneLoadingState());
|
||||
switchStatus = deviceStatus.switch_backlight;
|
||||
switchStatus = !switchStatus;
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: sixSceneId,
|
||||
code: 'switch_backlight',
|
||||
value: switchStatus),
|
||||
sixSceneId);
|
||||
deviceStatus.switch_backlight = switchStatus;
|
||||
if (!response['success']) {
|
||||
add(const SixSceneInitial());
|
||||
}
|
||||
emit(ChangeSwitchState(isEnable: switchStatus));
|
||||
} catch (_) {
|
||||
add(const SixSceneInitial());
|
||||
}
|
||||
}
|
||||
|
||||
// List<ScenesModel> allScenes = [];
|
||||
|
||||
Future<void> _onLoadScenes(
|
||||
LoadScenes event, Emitter<SixSceneState> emit) async {
|
||||
emit(SixSceneLoadingState());
|
||||
@@ -226,12 +340,6 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
}
|
||||
|
||||
bool selecedScene = false;
|
||||
String selectedSceneId = '';
|
||||
_selectScene(SelectSceneEvent event, Emitter<SixSceneState> emit) {
|
||||
emit(SixSceneLoadingState());
|
||||
selecedScene = !selecedScene;
|
||||
emit(SelectedSceneState());
|
||||
}
|
||||
|
||||
List<ScenesModel> allScenes = [];
|
||||
List<ScenesModel> filteredScenes = [];
|
||||
@@ -278,19 +386,6 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
dec: 'Syncroom', icon: Assets.addDevicesIcon, name: '6 Scene Switch')
|
||||
];
|
||||
|
||||
// @override
|
||||
// Stream<SixSceneState> mapEventToState(SixSceneEvent event) async* {
|
||||
// if (event is AddDeviceToGroup) {
|
||||
// devices.remove(event.device);
|
||||
// groupDevices.add(event.device);
|
||||
// yield UpdateStateList(groupDevices: groupDevices, devices: devices);
|
||||
// } else if (event is RemoveDeviceFromGroup) {
|
||||
// groupDevices.remove(event.device);
|
||||
// devices.add(event.device);
|
||||
// yield UpdateStateList(groupDevices: groupDevices, devices: devices);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Handler for AddDeviceToGroup
|
||||
void _addDeviceToGroup(AddDeviceToGroup event, Emitter<SixSceneState> emit) {
|
||||
devices.remove(event.device);
|
||||
@@ -306,9 +401,30 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
RemoveDeviceFromGroup event, Emitter<SixSceneState> emit) {
|
||||
groupDevices.remove(event.device);
|
||||
devices.add(event.device);
|
||||
for (var device in groupDevices) {
|
||||
for (var device in groupDevices) {
|
||||
device.icon = event.icon;
|
||||
}
|
||||
emit(UpdateStateList(groupDevices: groupDevices, devices: devices));
|
||||
}
|
||||
|
||||
void _controlDevice(
|
||||
ControlDeviceScene event, Emitter<SixSceneState> emit) async {
|
||||
emit(SixSceneLoadingState());
|
||||
try {
|
||||
deviceStatus.switch_backlight = !event.backLight!;
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: sixSceneId,
|
||||
code: 'switch_backlight',
|
||||
value: !event.backLight!),
|
||||
sixSceneId);
|
||||
|
||||
if (!response['success']) {
|
||||
// add(InitialEvent(groupScreen: oneTouchGroup));
|
||||
}
|
||||
} catch (_) {
|
||||
// add(InitialEvent(groupScreen: oneTouchGroup));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,24 @@ class SixSceneSwitch extends SixSceneEvent {
|
||||
|
||||
class SixSceneUpdated extends SixSceneEvent {}
|
||||
|
||||
class GetSceneBySwitchName extends SixSceneEvent {
|
||||
final String? switchName;
|
||||
|
||||
const GetSceneBySwitchName({this.switchName});
|
||||
}
|
||||
|
||||
class SixSceneInitial extends SixSceneEvent {
|
||||
const SixSceneInitial();
|
||||
}
|
||||
|
||||
class SixSceneInitialInfo extends SixSceneEvent {
|
||||
const SixSceneInitialInfo();
|
||||
}
|
||||
|
||||
class SexSceneSwitchInitial extends SixSceneEvent {
|
||||
const SexSceneSwitchInitial();
|
||||
}
|
||||
|
||||
class ReportLogsInitial extends SixSceneEvent {
|
||||
const ReportLogsInitial();
|
||||
}
|
||||
@@ -171,3 +185,19 @@ class RemoveDeviceFromGroup extends SixSceneEvent {
|
||||
|
||||
RemoveDeviceFromGroup(this.device, this.icon);
|
||||
}
|
||||
|
||||
class AssignDeviceScene extends SixSceneEvent {
|
||||
final String? sceneUuid;
|
||||
final String? switchName;
|
||||
final SpaceModel? unit;
|
||||
const AssignDeviceScene({
|
||||
this.sceneUuid,
|
||||
this.unit,
|
||||
this.switchName,
|
||||
});
|
||||
}
|
||||
|
||||
class ControlDeviceScene extends SixSceneEvent {
|
||||
final bool? backLight;
|
||||
const ControlDeviceScene({this.backLight});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/group_devices_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/scene_switch_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/sex_scene_question_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/six_scene_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
||||
@@ -111,3 +112,17 @@ class OptionSelectedState extends SixSceneState {
|
||||
@override
|
||||
List<Object> get props => [selectedOption, hasSelectionChanged];
|
||||
}
|
||||
|
||||
class SceneSelectionUpdatedState extends SixSceneState {
|
||||
final String selectedSceneId;
|
||||
|
||||
SceneSelectionUpdatedState({required this.selectedSceneId});
|
||||
}
|
||||
|
||||
class LoadingDeviceInfo extends SixSceneState {
|
||||
final SceneSwitch deviceInfo;
|
||||
const LoadingDeviceInfo({required this.deviceInfo});
|
||||
|
||||
@override
|
||||
List<Object> get props => [deviceInfo];
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
on<FetchRoomsEvent>(_fetchRoomsAndDevices);
|
||||
on<ChangeSwitchStatusEvent>(changeSwitchStatus);
|
||||
on<LoadScenes>(_onLoadScenes);
|
||||
on<SelectSceneEvent>(_selectScene);
|
||||
on<SearchScenesEvent>(searchScene);
|
||||
on<AssignRoomEvent>(_assignDevice);
|
||||
on<SelectOptionEvent>(_onOptionSelected);
|
||||
@@ -47,6 +46,7 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
on<FourSceneSwitchInitial>(_fetchFourSceneSwitches);
|
||||
on<AssignDeviceScene>(assignScene);
|
||||
on<GetSceneBySwitchName>(getSceneByName);
|
||||
on<SelectSceneEvent>(_selectScene);
|
||||
}
|
||||
|
||||
final TextEditingController nameController =
|
||||
@@ -99,7 +99,17 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
subspaceName: "",
|
||||
),
|
||||
);
|
||||
String sceneId = '';
|
||||
String selectedFormApiSceneId = '';
|
||||
|
||||
String selectedSceneId = '';
|
||||
|
||||
_selectScene(SelectSceneEvent event, Emitter<FourSceneState> emit) {
|
||||
emit(FourSceneLoadingState());
|
||||
|
||||
selectedSceneId = event.selectedSceneId;
|
||||
emit(SceneSelectionUpdatedState(selectedSceneId: selectedSceneId));
|
||||
}
|
||||
|
||||
Future<void> saveName(
|
||||
SaveNameEvent event, Emitter<FourSceneState> emit) async {
|
||||
if (_validateInputs()) return;
|
||||
@@ -119,6 +129,34 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
}
|
||||
}
|
||||
|
||||
void getSceneByName(
|
||||
GetSceneBySwitchName event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
try {
|
||||
final response = await DevicesAPI.getSceneBySwitchName(
|
||||
deviceId: fourSceneId, switchName: event.switchName);
|
||||
selectedFormApiSceneId = response['scene']['uuid'];
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
bool selecedScene = false;
|
||||
|
||||
String _selectedOption = '';
|
||||
bool _hasSelectionChanged = false;
|
||||
|
||||
void _onOptionSelected(
|
||||
SelectOptionEvent event, Emitter<FourSceneState> emit) {
|
||||
emit(FourSceneLoadingState());
|
||||
_selectedOption = event.selectedOption;
|
||||
_hasSelectionChanged = true;
|
||||
emit(OptionSelectedState(
|
||||
selectedOption: _selectedOption,
|
||||
hasSelectionChanged: _hasSelectionChanged));
|
||||
}
|
||||
|
||||
List<FourSceneSwitchModel> fourScene = [];
|
||||
|
||||
void _fetchFourSceneSwitches(
|
||||
@@ -130,15 +168,13 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
"scene_1": '',
|
||||
"scene_2": '',
|
||||
"scene_3": '',
|
||||
"scene_4": ''
|
||||
"scene_4": '',
|
||||
};
|
||||
for (var item in response) {
|
||||
if (item["switchName"] != null) {
|
||||
sceneTitles[item["switchName"]] = item["scene"]["name"] ?? '';
|
||||
}
|
||||
}
|
||||
print('object======4${response}');
|
||||
|
||||
FourSceneModelState deviceStatus = FourSceneModelState(
|
||||
scene_1: sceneTitles["scene_1"] ?? '',
|
||||
scene_2: sceneTitles["scene_2"] ?? '',
|
||||
@@ -182,20 +218,9 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
sceneUuid: event.sceneUuid,
|
||||
spaceUuid: event.unit!.id,
|
||||
switchName: event.switchName);
|
||||
emit(SaveSelectionSuccessState());
|
||||
} catch (e) {
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
void getSceneByName(
|
||||
GetSceneBySwitchName event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
try {
|
||||
final response = await DevicesAPI.getSceneBySwitchName(
|
||||
deviceId: fourSceneId, switchName: event.switchName);
|
||||
sceneId = response['scene']['uuid'];
|
||||
emit(SaveSelectionSuccessState());
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
} catch (e) {
|
||||
emit(FourSceneFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
@@ -398,14 +423,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
}
|
||||
}
|
||||
|
||||
bool selecedScene = false;
|
||||
String selectedSceneId = '';
|
||||
_selectScene(SelectSceneEvent event, Emitter<FourSceneState> emit) {
|
||||
emit(FourSceneLoadingState());
|
||||
selecedScene = !selecedScene;
|
||||
emit(SelectedSceneState());
|
||||
}
|
||||
|
||||
List<ScenesModel> allScenes = [];
|
||||
List<ScenesModel> filteredScenes = [];
|
||||
|
||||
@@ -420,19 +437,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
emit(SearchResultsState());
|
||||
}
|
||||
|
||||
String _selectedOption = '';
|
||||
bool _hasSelectionChanged = false;
|
||||
|
||||
void _onOptionSelected(
|
||||
SelectOptionEvent event, Emitter<FourSceneState> emit) {
|
||||
emit(FourSceneLoadingState());
|
||||
_selectedOption = event.selectedOption;
|
||||
_hasSelectionChanged = true;
|
||||
emit(OptionSelectedState(
|
||||
selectedOption: _selectedOption,
|
||||
hasSelectionChanged: _hasSelectionChanged));
|
||||
}
|
||||
|
||||
List<GroupDevicesModel> groupDevices = [
|
||||
GroupDevicesModel(
|
||||
dec: 'Syncroom', icon: Assets.minusIcon, name: '6 Scene Switch')
|
||||
|
||||
@@ -148,9 +148,11 @@ class LoadScenes extends FourSceneEvent {
|
||||
}
|
||||
|
||||
class SelectSceneEvent extends FourSceneEvent {
|
||||
final String unitId;
|
||||
final String selectedSceneId;
|
||||
// final String unitId;
|
||||
const SelectSceneEvent({
|
||||
required this.unitId,
|
||||
// required this.unitId,
|
||||
required this.selectedSceneId,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -212,6 +214,7 @@ class ControlDeviceScene extends FourSceneEvent {
|
||||
class FourSceneSwitchInitial extends FourSceneEvent {
|
||||
const FourSceneSwitchInitial();
|
||||
}
|
||||
|
||||
class SaveSelectionSceneEvent extends FourSceneEvent {
|
||||
const SaveSelectionSceneEvent();
|
||||
}
|
||||
@@ -220,12 +223,15 @@ class AssignDeviceScene extends FourSceneEvent {
|
||||
final String? sceneUuid;
|
||||
final String? switchName;
|
||||
final SpaceModel? unit;
|
||||
const AssignDeviceScene({this.sceneUuid, this.unit,this.switchName});
|
||||
const AssignDeviceScene({
|
||||
this.sceneUuid,
|
||||
this.unit,
|
||||
this.switchName,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
class GetSceneBySwitchName extends FourSceneEvent {
|
||||
final String? switchName;
|
||||
final String? switchName;
|
||||
|
||||
const GetSceneBySwitchName({this.switchName});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,3 +122,9 @@ class LoadingDeviceInfo extends FourSceneState {
|
||||
@override
|
||||
List<Object> get props => [deviceInfo];
|
||||
}
|
||||
|
||||
class SceneSelectionUpdatedState extends FourSceneState {
|
||||
final String selectedSceneId;
|
||||
|
||||
SceneSelectionUpdatedState({required this.selectedSceneId});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user