mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 01:35:23 +00:00
71 lines
2.1 KiB
Dart
71 lines
2.1 KiB
Dart
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';
|
|
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
|
import 'package:syncrow_app/services/api/http_service.dart';
|
|
|
|
class DevicesAPI {
|
|
static final HTTPService _httpService = HTTPService();
|
|
|
|
static Future<Map<String, dynamic>> controlDevice(
|
|
DeviceControlModel controlModel) async {
|
|
try {
|
|
final response = await _httpService.post(
|
|
path: ApiEndpoints.control,
|
|
body: controlModel.toJson(),
|
|
showServerMessage: false,
|
|
expectedResponseModel: (json) {
|
|
return json;
|
|
},
|
|
);
|
|
return response;
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
static Future<List<DevicesCategoryModel>> fetchGroups(int spaceId) async {
|
|
Map<String, dynamic> params = {
|
|
"homeId": spaceId,
|
|
"pageSize": 100,
|
|
"pageNo": 1
|
|
};
|
|
|
|
final response = await _httpService.get(
|
|
path: ApiEndpoints.groups,
|
|
queryParameters: params,
|
|
showServerMessage: false,
|
|
expectedResponseModel: (json) =>
|
|
DevicesCategoryModel.fromJsonList(json['groups']),
|
|
);
|
|
return response;
|
|
}
|
|
|
|
static Future<Map<String, dynamic>> getDeviceStatus(String deviceId) async {
|
|
final response = await _httpService.get(
|
|
path: '${ApiEndpoints.deviceStatus}/$deviceId/functions/status',
|
|
showServerMessage: false,
|
|
expectedResponseModel: (json) {
|
|
return json;
|
|
},
|
|
);
|
|
return response;
|
|
}
|
|
|
|
static Future<List<DeviceModel>> getDevicesByRoomId(int roomId) async {
|
|
final response = await _httpService.get(
|
|
path: ApiEndpoints.devicesByRoom,
|
|
queryParameters: {"roomId": roomId, "pageSize": 10},
|
|
showServerMessage: false,
|
|
expectedResponseModel: (json) {
|
|
List<DeviceModel> devices = [];
|
|
for (var device in json['devices']) {
|
|
devices.add(DeviceModel.fromJson(device));
|
|
}
|
|
return devices;
|
|
},
|
|
);
|
|
return response;
|
|
}
|
|
}
|