mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-26 03:57:55 +00:00
added unit devices
This commit is contained in:
@@ -19,10 +19,12 @@ class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
||||
on<AddNewRoom>(_addNewRoom);
|
||||
}
|
||||
|
||||
void _fetchRoomsAndDevices(FetchRoomsEvent event, Emitter<ManageUnitState> emit) async {
|
||||
void _fetchRoomsAndDevices(
|
||||
FetchRoomsEvent event, Emitter<ManageUnitState> emit) async {
|
||||
try {
|
||||
emit(LoadingState());
|
||||
final roomsList = await SpacesAPI.getSubSpaceBySpaceId(event.unit.community.uuid, event.unit.id);
|
||||
final roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
||||
event.unit.community.uuid, event.unit.id);
|
||||
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
||||
} catch (e) {
|
||||
emit(const ErrorState(message: 'Something went wrong'));
|
||||
@@ -30,11 +32,15 @@ class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _fetchDevicesByRoomId(FetchDevicesByRoomIdEvent event, Emitter<ManageUnitState> emit) async {
|
||||
void _fetchDevicesByRoomId(
|
||||
FetchDevicesByRoomIdEvent event, Emitter<ManageUnitState> emit) async {
|
||||
try {
|
||||
Map<String, bool> roomDevicesId = {};
|
||||
emit(LoadingState());
|
||||
final devicesList = await DevicesAPI.getDevicesByRoomId(event.roomId);
|
||||
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
||||
communityUuid: event.unit.community.uuid,
|
||||
spaceUuid: event.unit.id,
|
||||
roomId: event.roomId);
|
||||
allDevices = await HomeManagementAPI.fetchDevicesByUserId();
|
||||
|
||||
List<String> allDevicesIds = [];
|
||||
@@ -61,13 +67,20 @@ class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _assignDevice(AssignRoomEvent event, Emitter<ManageUnitState> emit) async {
|
||||
void _assignDevice(
|
||||
AssignRoomEvent event, Emitter<ManageUnitState> emit) async {
|
||||
try {
|
||||
Map<String, bool> roomDevicesId = {};
|
||||
emit(LoadingState());
|
||||
Map<String, String> body = {"deviceUuid": event.deviceId, "roomUuid": event.roomId};
|
||||
Map<String, String> body = {
|
||||
"deviceUuid": event.deviceId,
|
||||
"roomUuid": event.roomId
|
||||
};
|
||||
await HomeManagementAPI.assignDeviceToRoom(body);
|
||||
final devicesList = await DevicesAPI.getDevicesByRoomId(event.roomId);
|
||||
final devicesList = await DevicesAPI.getDevicesByRoomId(
|
||||
communityUuid: event.unit.community.uuid,
|
||||
spaceUuid: event.unit.id,
|
||||
roomId: event.roomId);
|
||||
|
||||
List<String> allDevicesIds = [];
|
||||
|
||||
@@ -99,7 +112,8 @@ class ManageUnitBloc extends Bloc<ManageUnitEvent, ManageUnitState> {
|
||||
emit(LoadingState());
|
||||
final response = await HomeCreation.createRoom(body);
|
||||
if (response['data']['uuid'] != '') {
|
||||
final roomsList = await SpacesAPI.getSubSpaceBySpaceId(event.unit.community.uuid, event.unit.id);
|
||||
final roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
||||
event.unit.community.uuid, event.unit.id);
|
||||
allDevices = await HomeManagementAPI.fetchDevicesByUserId();
|
||||
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
||||
await HomeCubit.getInstance().fetchUnitsByUserId();
|
||||
|
||||
@@ -23,11 +23,12 @@ class FetchRoomsEvent extends ManageUnitEvent {
|
||||
|
||||
class FetchDevicesByRoomIdEvent extends ManageUnitEvent {
|
||||
final String roomId;
|
||||
final SpaceModel unit;
|
||||
|
||||
const FetchDevicesByRoomIdEvent({required this.roomId});
|
||||
const FetchDevicesByRoomIdEvent({required this.roomId, required this.unit});
|
||||
|
||||
@override
|
||||
List<Object> get props => [roomId];
|
||||
List<Object> get props => [roomId, unit];
|
||||
}
|
||||
|
||||
class AddNewRoom extends ManageUnitEvent {
|
||||
@@ -43,9 +44,11 @@ class AddNewRoom extends ManageUnitEvent {
|
||||
class AssignRoomEvent extends ManageUnitEvent {
|
||||
final String roomId;
|
||||
final String deviceId;
|
||||
final SpaceModel unit;
|
||||
|
||||
const AssignRoomEvent({required this.roomId, required this.deviceId});
|
||||
const AssignRoomEvent(
|
||||
{required this.roomId, required this.deviceId, required this.unit});
|
||||
|
||||
@override
|
||||
List<Object> get props => [roomId];
|
||||
List<Object> get props => [roomId, unit];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user