mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-26 18:04:54 +00:00
added unit devices
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user