added unit devices

This commit is contained in:
hannathkadher
2024-10-30 19:16:10 +04:00
parent 5c65bac076
commit 13a4bf25b3
15 changed files with 220 additions and 88 deletions

View File

@ -28,15 +28,38 @@ class HomeManagementAPI {
static Future<List<DeviceModel>> fetchDevicesByUnitId() async {
List<DeviceModel> list = [];
await _httpService.get(
path: ApiEndpoints.getDevicesByUnitId.replaceAll(
"{unitUuid}", HomeCubit.getInstance().selectedSpace?.id ?? ''),
try {
// Retrieve selected space details
final selectedSpace = HomeCubit.getInstance().selectedSpace;
final communityUuid = selectedSpace?.community?.uuid ?? '';
final spaceUuid = selectedSpace?.id ?? '';
// Ensure both placeholders are replaced
final path = ApiEndpoints.spaceDevices
.replaceAll("{communityUuid}", communityUuid)
.replaceAll("{spaceUuid}", spaceUuid);
// Debugging: Log the path
print("Fetching devices with path: $path");
await _httpService.get(
path: path,
showServerMessage: false,
expectedResponseModel: (json) {
json.forEach((value) {
list.add(DeviceModel.fromJson(value));
});
});
},
);
// Debugging: Log successful fetch
print("Successfully fetched ${list.length} devices.");
} catch (e) {
// Log the error for debugging
print("Error fetching devices for the unit: $e");
}
return list;
}