mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-26 08:14:55 +00:00
added unit devices
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
@ -130,23 +129,43 @@ class DevicesAPI {
|
||||
return response;
|
||||
}
|
||||
|
||||
static Future<List<DeviceModel>> getDevicesByRoomId(String roomId) async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.deviceByRoom,
|
||||
queryParameters: {"roomUuid": roomId},
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
if (json == null || json.isEmpty || json == []) {
|
||||
return <DeviceModel>[];
|
||||
}
|
||||
List<DeviceModel> devices = [];
|
||||
for (var device in json) {
|
||||
devices.add(DeviceModel.fromJson(device));
|
||||
}
|
||||
return devices;
|
||||
},
|
||||
);
|
||||
return response;
|
||||
static Future<List<DeviceModel>> getDevicesByRoomId({
|
||||
required String communityUuid,
|
||||
required String spaceUuid,
|
||||
required String roomId,
|
||||
}) async {
|
||||
try {
|
||||
final String path = ApiEndpoints.deviceByRoom
|
||||
.replaceAll(':communityUuid', communityUuid)
|
||||
.replaceAll(':spaceUuid', spaceUuid)
|
||||
.replaceAll(':subSpaceUuid', roomId);
|
||||
|
||||
final response = await _httpService.get(
|
||||
path: path,
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (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
|
||||
print("Error fetching devices for room: $e");
|
||||
|
||||
// Return an empty list in case of error
|
||||
return <DeviceModel>[];
|
||||
}
|
||||
}
|
||||
|
||||
static Future<List<DeviceModel>> getDevicesByGatewayId(
|
||||
|
||||
Reference in New Issue
Block a user