Files
syncrow-app/lib/services/api/devices_api.dart
Mohammad Salameh bff4b9493c Refactor device control logic and add temperature and fan speed enums
- Refactor device control logic in the app to improve readability and maintainability.
- Add temperature modes (hot, cold, wind) and fan speeds (auto, low, middle, high) enums.
- Update icon mappings and utility functions for temperature modes and fan speeds.
2024-04-03 18:54:21 +03:00

51 lines
1.6 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/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 {
// print(
// 'contoling [${controlModel.deviceId}] with code [${controlModel.code}] and value [${controlModel.value}');
final response = await _httpService.post(
path: ApiEndpoints.control,
body: controlModel.toJson(),
showServerMessage: false,
expectedResponseModel: (json) {
return json;
},
);
return response;
}
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;
}
}