mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 17:47:28 +00:00
all_devices and Restrict_user
This commit is contained in:
@ -51,11 +51,14 @@ class DevicesAPI {
|
||||
static Future<Map<String, dynamic>> controlDevice(
|
||||
DeviceControlModel controlModel, String deviceId) async {
|
||||
try {
|
||||
print('object-*/-*/-*/${controlModel.toJson()}');
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.controlDevice.replaceAll('{deviceUuid}', deviceId),
|
||||
body: controlModel.toJson(),
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
print('object-*/-*/-*/${json}');
|
||||
|
||||
return json;
|
||||
},
|
||||
);
|
||||
@ -561,4 +564,45 @@ class DevicesAPI {
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
static Future<List<DeviceModel>> getAllDevices({
|
||||
required String communityUuid,
|
||||
required String spaceUuid,
|
||||
}) async {
|
||||
print('communityUuid=$communityUuid');
|
||||
print('spaceUuid=$spaceUuid');
|
||||
print('projectUuid=${TempConst.projectId}');
|
||||
|
||||
try {
|
||||
final String path = ApiEndpoints.getAllDevices
|
||||
.replaceAll('{communityUuid}', communityUuid)
|
||||
.replaceAll('{spaceUuid}', spaceUuid)
|
||||
.replaceAll('{projectUuid}', TempConst.projectId);
|
||||
|
||||
final response = await _httpService.get(
|
||||
path: path,
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
print('response-*/-*/$json');
|
||||
final data = json['data'];
|
||||
|
||||
if (data == null || data.isEmpty) {
|
||||
return <DeviceModel>[];
|
||||
}
|
||||
if (json == null || json.isEmpty || json == []) {
|
||||
return <DeviceModel>[];
|
||||
}
|
||||
return data
|
||||
.map<DeviceModel>((device) => DeviceModel.fromJson(device))
|
||||
.toList();
|
||||
},
|
||||
);
|
||||
|
||||
return response;
|
||||
} catch (e) {
|
||||
// Log the error if needed
|
||||
// Return an empty list in case of error
|
||||
return <DeviceModel>[];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user