mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 06:07:55 +00:00
updated add to room, and verify to space
This commit is contained in:
@@ -17,6 +17,7 @@ class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
||||
on<FetchDevicesByRoomIdEvent>(_fetchDevicesByRoomId);
|
||||
on<AssignRoomEvent>(_assignDevice);
|
||||
on<AddNewRoom>(_addNewRoom);
|
||||
on<UnassignRoomEvent>(_unassignDevice);
|
||||
}
|
||||
|
||||
void _fetchRoomsAndDevices(
|
||||
@@ -72,11 +73,9 @@ class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
||||
try {
|
||||
Map<String, bool> roomDevicesId = {};
|
||||
emit(LoadingState());
|
||||
Map<String, String> body = {
|
||||
"deviceUuid": event.deviceId,
|
||||
"roomUuid": event.roomId
|
||||
};
|
||||
await HomeManagementAPI.assignDeviceToRoom(body);
|
||||
|
||||
await HomeManagementAPI.assignDeviceToRoom(
|
||||
event.unit.community.uuid, event.unit.id, event.roomId, event.deviceId);
|
||||
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
||||
communityUuid: event.unit.community.uuid,
|
||||
spaceUuid: event.unit.id,
|
||||
@@ -106,6 +105,45 @@ class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void _unassignDevice(
|
||||
UnassignRoomEvent event, Emitter<ManageUnitState> emit) async {
|
||||
try {
|
||||
Map<String, bool> roomDevicesId = {};
|
||||
emit(LoadingState());
|
||||
|
||||
await HomeManagementAPI.unAssignDeviceToRoom(
|
||||
event.unit.community.uuid, event.unit.id, event.roomId, event.deviceId);
|
||||
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
||||
communityUuid: event.unit.community.uuid,
|
||||
spaceUuid: event.unit.id,
|
||||
roomId: event.roomId);
|
||||
|
||||
List<String> allDevicesIds = [];
|
||||
|
||||
allDevices.forEach((element) {
|
||||
allDevicesIds.add(element.uuid!);
|
||||
});
|
||||
|
||||
devicesList.forEach((e) {
|
||||
if (allDevicesIds.contains(e.uuid!)) {
|
||||
roomDevicesId[e.uuid!] = true;
|
||||
} else {
|
||||
roomDevicesId[e.uuid!] = false;
|
||||
}
|
||||
});
|
||||
emit(FetchDeviceByRoomIdState(
|
||||
roomDevices: devicesList,
|
||||
allDevices: allDevices,
|
||||
roomDevicesId: roomDevicesId,
|
||||
roomId: event.roomId));
|
||||
} catch (e) {
|
||||
emit(const ErrorState(message: 'Something went wrong'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_addNewRoom(AddNewRoom event, Emitter<ManageUnitState> emit) async {
|
||||
Map<String, String> body = {'subspaceName': event.roomName};
|
||||
try {
|
||||
|
||||
@@ -52,3 +52,15 @@ class AssignRoomEvent extends ManageUnitEvent {
|
||||
@override
|
||||
List<Object> get props => [roomId, unit];
|
||||
}
|
||||
|
||||
class UnassignRoomEvent extends ManageUnitEvent {
|
||||
final String roomId;
|
||||
final String deviceId;
|
||||
final SpaceModel unit;
|
||||
|
||||
const UnassignRoomEvent(
|
||||
{required this.roomId, required this.deviceId, required this.unit});
|
||||
|
||||
@override
|
||||
List<Object> get props => [roomId, unit];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user