mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-11 15:47:35 +00:00
Implemented tab to run setting
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:syncrow_app/features/scene/model/create_automation_model.dart';
|
||||
import 'package:syncrow_app/features/scene/model/create_scene_model.dart';
|
||||
import 'package:syncrow_app/features/scene/model/icon_model.dart';
|
||||
import 'package:syncrow_app/features/scene/model/scene_details_model.dart';
|
||||
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
||||
import 'package:syncrow_app/features/scene/model/update_automation.dart';
|
||||
@ -12,8 +11,7 @@ class SceneApi {
|
||||
static final HTTPService _httpService = HTTPService();
|
||||
|
||||
//create scene
|
||||
static Future<Map<String, dynamic>> createScene(
|
||||
CreateSceneModel createSceneModel) async {
|
||||
static Future<Map<String, dynamic>> createScene(CreateSceneModel createSceneModel) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.createScene,
|
||||
@ -49,10 +47,11 @@ class SceneApi {
|
||||
|
||||
//get scene by unit id
|
||||
|
||||
static Future<List<ScenesModel>> getScenesByUnitId(String unitId) async {
|
||||
static Future<List<ScenesModel>> getScenesByUnitId(String unitId, {showInDevice = false}) async {
|
||||
try {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.getUnitScenes.replaceAll('{unitUuid}', unitId),
|
||||
queryParameters: {'showInHomePage': showInDevice},
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
List<ScenesModel> scenes = [];
|
||||
@ -103,12 +102,10 @@ class SceneApi {
|
||||
}
|
||||
|
||||
//automation details
|
||||
static Future<SceneDetailsModel> getAutomationDetails(
|
||||
String automationId) async {
|
||||
static Future<SceneDetailsModel> getAutomationDetails(String automationId) async {
|
||||
try {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.getAutomationDetails
|
||||
.replaceAll('{automationId}', automationId),
|
||||
path: ApiEndpoints.getAutomationDetails.replaceAll('{automationId}', automationId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) => SceneDetailsModel.fromJson(json),
|
||||
);
|
||||
@ -119,12 +116,11 @@ class SceneApi {
|
||||
}
|
||||
|
||||
//updateAutomationStatus
|
||||
static Future<bool> updateAutomationStatus(String automationId,
|
||||
AutomationStatusUpdate createAutomationEnable) async {
|
||||
static Future<bool> updateAutomationStatus(
|
||||
String automationId, AutomationStatusUpdate createAutomationEnable) async {
|
||||
try {
|
||||
final response = await _httpService.put(
|
||||
path: ApiEndpoints.updateAutomationStatus
|
||||
.replaceAll('{automationId}', automationId),
|
||||
path: ApiEndpoints.updateAutomationStatus.replaceAll('{automationId}', automationId),
|
||||
body: createAutomationEnable.toMap(),
|
||||
expectedResponseModel: (json) => json['success'],
|
||||
);
|
||||
@ -133,6 +129,7 @@ class SceneApi {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<SceneDetailsModel> getSceneDetails(String sceneId) async {
|
||||
try {
|
||||
final response = await _httpService.get(
|
||||
@ -146,20 +143,19 @@ class SceneApi {
|
||||
}
|
||||
}
|
||||
|
||||
static Future getIcon() async {
|
||||
try {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.getIconScene,
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
log(json);
|
||||
return json;
|
||||
},
|
||||
);
|
||||
return response;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
static Future<List<IconModel>> getIcon() async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.getIconScene,
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
List<IconModel> iconsList = [];
|
||||
json.forEach((element) {
|
||||
iconsList.add(IconModel.fromJson(element));
|
||||
});
|
||||
return iconsList;
|
||||
},
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
//update Scene
|
||||
@ -167,8 +163,7 @@ class SceneApi {
|
||||
try {
|
||||
final response = await _httpService.put(
|
||||
path: ApiEndpoints.updateScene.replaceAll('{sceneId}', sceneId),
|
||||
body: createSceneModel
|
||||
.toJson(sceneId.isNotEmpty == true ? sceneId : null),
|
||||
body: createSceneModel.toJson(sceneId.isNotEmpty == true ? sceneId : null),
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
},
|
||||
@ -180,14 +175,11 @@ class SceneApi {
|
||||
}
|
||||
|
||||
//update automation
|
||||
static updateAutomation(
|
||||
CreateAutomationModel createAutomationModel, String automationId) async {
|
||||
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),
|
||||
path: ApiEndpoints.updateAutomation.replaceAll('{automationId}', automationId),
|
||||
body: createAutomationModel.toJson(automationId.isNotEmpty == true ? automationId : null),
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
},
|
||||
@ -200,8 +192,7 @@ class SceneApi {
|
||||
|
||||
//delete Scene
|
||||
|
||||
static Future<bool> deleteScene(
|
||||
{required String unitUuid, required String sceneId}) async {
|
||||
static Future<bool> deleteScene({required String unitUuid, required String sceneId}) async {
|
||||
try {
|
||||
final response = await _httpService.delete(
|
||||
path: ApiEndpoints.deleteScene
|
||||
|
Reference in New Issue
Block a user