mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 20:27:55 +00:00
Updated the API Endpoints, API Calls, Data Models and cubits to the lateset changes from the backend
This commit is contained in:
@@ -25,7 +25,7 @@ part 'devices_state.dart';
|
||||
class DevicesCubit extends Cubit<DevicesState> {
|
||||
DevicesCubit._() : super(DevicesInitial()) {
|
||||
if (HomeCubit.getInstance().selectedSpace != null) {
|
||||
fetchGroups(HomeCubit.getInstance().selectedSpace!.id!);
|
||||
// fetchGroups(HomeCubit.getInstance().selectedSpace!.id!);
|
||||
for (var room in HomeCubit.getInstance().selectedSpace!.rooms!) {
|
||||
fetchDevicesByRoomId(room.id!);
|
||||
}
|
||||
@@ -257,7 +257,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
emitSafe(DeviceControlSuccess(code: control.code));
|
||||
//this delay is to give tuya server time to update the status
|
||||
Future.delayed(const Duration(milliseconds: 400), () {
|
||||
getDevicesStatues(
|
||||
fetchDevicesStatues(
|
||||
deviceId,
|
||||
HomeCubit.getInstance()
|
||||
.selectedSpace!
|
||||
@@ -274,7 +274,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
}
|
||||
}
|
||||
|
||||
fetchGroups(int spaceId) async {
|
||||
fetchGroups(String spaceId) async {
|
||||
emitSafe(DevicesCategoriesLoading());
|
||||
try {
|
||||
allCategories = await DevicesAPI.fetchGroups(spaceId);
|
||||
@@ -289,7 +289,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
}
|
||||
}
|
||||
|
||||
fetchDevicesByRoomId(int? roomId) async {
|
||||
fetchDevicesByRoomId(String? roomId) async {
|
||||
if (roomId == null) return;
|
||||
|
||||
emitSafe(GetDevicesLoading());
|
||||
@@ -308,23 +308,26 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
|
||||
//get status for each device
|
||||
//TODO get devices status per page via page controller instead of getting all devices status at once
|
||||
for (var device
|
||||
in HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices!) {
|
||||
getDevicesStatues(device.id!, roomIndex);
|
||||
List<DeviceModel> devices =
|
||||
HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices!;
|
||||
if (devices.isNotEmpty) {
|
||||
for (var device in devices) {
|
||||
fetchDevicesStatues(device.uuid!, roomIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getDevicesStatues(String deviceId, int roomIndex, {String? code}) async {
|
||||
fetchDevicesStatues(String deviceUuid, int roomIndex, {String? code}) async {
|
||||
emitSafe(GetDeviceStatusLoading(code: code));
|
||||
int deviceIndex = HomeCubit.getInstance()
|
||||
.selectedSpace!
|
||||
.rooms![roomIndex]
|
||||
.devices!
|
||||
.indexWhere((element) => element.id == deviceId);
|
||||
.indexWhere((element) => element.uuid == deviceUuid);
|
||||
List<StatusModel> statuses = [];
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(deviceId);
|
||||
for (var status in response['result']['status']) {
|
||||
var response = await DevicesAPI.getDeviceStatus(deviceUuid);
|
||||
for (var status in response['status']) {
|
||||
statuses.add(StatusModel.fromJson(status));
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user