mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
push get scenes and automation
This commit is contained in:
216
lib/services/routines_api.dart
Normal file
216
lib/services/routines_api.dart
Normal file
@ -0,0 +1,216 @@
|
||||
import 'package:syncrow_web/pages/routiens/models/routine_model.dart';
|
||||
import 'package:syncrow_web/services/api/http_service.dart';
|
||||
import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||
|
||||
class SceneApi {
|
||||
static final HTTPService _httpService = HTTPService();
|
||||
|
||||
// //create scene
|
||||
// static Future<Map<String, dynamic>> createScene(
|
||||
// CreateSceneModel createSceneModel) async {
|
||||
// try {
|
||||
// final response = await _httpService.post(
|
||||
// path: ApiEndpoints.createScene,
|
||||
// body: createSceneModel.toMap(),
|
||||
// showServerMessage: false,
|
||||
// expectedResponseModel: (json) {
|
||||
// return json;
|
||||
// },
|
||||
// );
|
||||
// return response;
|
||||
// } catch (e) {
|
||||
// rethrow;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // create automation
|
||||
// static Future<Map<String, dynamic>> createAutomation(
|
||||
// CreateAutomationModel createAutomationModel) async {
|
||||
// try {
|
||||
// final response = await _httpService.post(
|
||||
// path: ApiEndpoints.createAutomation,
|
||||
// body: createAutomationModel.toMap(),
|
||||
// showServerMessage: false,
|
||||
// expectedResponseModel: (json) {
|
||||
// return json;
|
||||
// },
|
||||
// );
|
||||
// return response;
|
||||
// } catch (e) {
|
||||
// rethrow;
|
||||
// }
|
||||
// }
|
||||
|
||||
//get scene by unit id
|
||||
|
||||
static Future<List<ScenesModel>> getScenesByUnitId(String unitId) async {
|
||||
try {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.getSpaceScenes.replaceAll('{unitUuid}', unitId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
List<ScenesModel> scenes = [];
|
||||
for (var scene in json) {
|
||||
scenes.add(ScenesModel.fromJson(scene));
|
||||
}
|
||||
return scenes;
|
||||
},
|
||||
);
|
||||
return response;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
//getAutomation
|
||||
|
||||
static Future<List<ScenesModel>> getAutomationByUnitId(String unitId) async {
|
||||
try {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.getSpaceAutomation.replaceAll('{unitUuid}', unitId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
List<ScenesModel> scenes = [];
|
||||
for (var scene in json) {
|
||||
scenes.add(ScenesModel.fromJson(scene));
|
||||
}
|
||||
return scenes;
|
||||
},
|
||||
);
|
||||
return response;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
// static Future<bool> triggerScene(String sceneId) async {
|
||||
// try {
|
||||
// final response = await _httpService.post(
|
||||
// path: ApiEndpoints.triggerScene.replaceAll('{sceneId}', sceneId),
|
||||
// showServerMessage: false,
|
||||
// expectedResponseModel: (json) => json['success'],
|
||||
// );
|
||||
// return response;
|
||||
// } catch (e) {
|
||||
// rethrow;
|
||||
// }
|
||||
// }
|
||||
|
||||
// //automation details
|
||||
// static Future<SceneDetailsModel> getAutomationDetails(
|
||||
// String automationId) async {
|
||||
// try {
|
||||
// final response = await _httpService.get(
|
||||
// path: ApiEndpoints.getAutomationDetails
|
||||
// .replaceAll('{automationId}', automationId),
|
||||
// showServerMessage: false,
|
||||
// expectedResponseModel: (json) => SceneDetailsModel.fromJson(json),
|
||||
// );
|
||||
// return response;
|
||||
// } catch (e) {
|
||||
// rethrow;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //updateAutomationStatus
|
||||
// static Future<bool> updateAutomationStatus(String automationId,
|
||||
// AutomationStatusUpdate createAutomationEnable) async {
|
||||
// try {
|
||||
// final response = await _httpService.put(
|
||||
// path: ApiEndpoints.updateAutomationStatus
|
||||
// .replaceAll('{automationId}', automationId),
|
||||
// body: createAutomationEnable.toMap(),
|
||||
// expectedResponseModel: (json) => json['success'],
|
||||
// );
|
||||
// return response;
|
||||
// } catch (e) {
|
||||
// rethrow;
|
||||
// }
|
||||
// }
|
||||
|
||||
// //getScene
|
||||
//
|
||||
// static Future<SceneDetailsModel> getSceneDetails(String sceneId) async {
|
||||
// try {
|
||||
// final response = await _httpService.get(
|
||||
// path: ApiEndpoints.getScene.replaceAll('{sceneId}', sceneId),
|
||||
// showServerMessage: false,
|
||||
// expectedResponseModel: (json) => SceneDetailsModel.fromJson(json),
|
||||
// );
|
||||
// return response;
|
||||
// } catch (e) {
|
||||
// rethrow;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //update Scene
|
||||
// static updateScene(CreateSceneModel createSceneModel, String sceneId) async {
|
||||
// try {
|
||||
// final response = await _httpService.put(
|
||||
// path: ApiEndpoints.updateScene.replaceAll('{sceneId}', sceneId),
|
||||
// body: createSceneModel
|
||||
// .toJson(sceneId.isNotEmpty == true ? sceneId : null),
|
||||
// expectedResponseModel: (json) {
|
||||
// return json;
|
||||
// },
|
||||
// );
|
||||
// return response;
|
||||
// } catch (e) {
|
||||
// rethrow;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //update automation
|
||||
// static updateAutomation(
|
||||
// CreateAutomationModel createAutomationModel, String automationId) async {
|
||||
// try {
|
||||
// final response = await _httpService.put(
|
||||
// path: ApiEndpoints.updateAutomation
|
||||
// .replaceAll('{automationId}', automationId),
|
||||
// body: createAutomationModel
|
||||
// .toJson(automationId.isNotEmpty == true ? automationId : null),
|
||||
// expectedResponseModel: (json) {
|
||||
// return json;
|
||||
// },
|
||||
// );
|
||||
// return response;
|
||||
// } catch (e) {
|
||||
// rethrow;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //delete Scene
|
||||
//
|
||||
// static Future<bool> deleteScene(
|
||||
// {required String unitUuid, required String sceneId}) async {
|
||||
// try {
|
||||
// final response = await _httpService.delete(
|
||||
// path: ApiEndpoints.deleteScene
|
||||
// .replaceAll('{sceneId}', sceneId)
|
||||
// .replaceAll('{unitUuid}', unitUuid),
|
||||
// showServerMessage: false,
|
||||
// expectedResponseModel: (json) => json['statusCode'] == 200,
|
||||
// );
|
||||
// return response;
|
||||
// } catch (e) {
|
||||
// rethrow;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // delete automation
|
||||
// static Future<bool> deleteAutomation(
|
||||
// {required String unitUuid, required String automationId}) async {
|
||||
// try {
|
||||
// final response = await _httpService.delete(
|
||||
// path: ApiEndpoints.deleteAutomation
|
||||
// .replaceAll('{automationId}', automationId)
|
||||
// .replaceAll('{unitUuid}', unitUuid),
|
||||
// showServerMessage: false,
|
||||
// expectedResponseModel: (json) => json['statusCode'] == 200,
|
||||
// );
|
||||
// return response;
|
||||
// } catch (e) {
|
||||
// rethrow;
|
||||
// }
|
||||
// }
|
||||
}
|
Reference in New Issue
Block a user