fixed automation

This commit is contained in:
hannathkadher
2024-11-02 23:10:24 +04:00
parent dcccc4db3a
commit 87a4a88417
13 changed files with 240 additions and 132 deletions
+3 -3
View File
@@ -150,9 +150,9 @@ class DevicesAPI {
}) async {
try {
final String path = ApiEndpoints.deviceByRoom
.replaceAll(':communityUuid', communityUuid)
.replaceAll(':spaceUuid', spaceUuid)
.replaceAll(':subSpaceUuid', roomId);
.replaceAll('{communityUuid}', communityUuid)
.replaceAll('{spaceUuid}', spaceUuid)
.replaceAll('{subSpaceUuid}', roomId);
final response = await _httpService.get(
path: path,
+7 -5
View File
@@ -37,15 +37,17 @@ class HomeManagementAPI {
// Ensure both placeholders are replaced
final path = ApiEndpoints.spaceDevices
.replaceAll("{communityUuid}", communityUuid)
.replaceAll("{spaceUuid}", spaceUuid);
.replaceAll('{communityUuid}', communityUuid)
.replaceAll('{spaceUuid}', spaceUuid);
await _httpService.get(
path: path,
showServerMessage: false,
expectedResponseModel: (json) {
json.forEach((value) {
list.add(DeviceModel.fromJson(value));
});
if (json['data'] != null) {
json['data'].forEach((value) {
list.add(DeviceModel.fromJson(value));
});
}
},
);
+38 -18
View File
@@ -1,3 +1,5 @@
import 'dart:convert';
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';
@@ -11,7 +13,8 @@ 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,
@@ -47,15 +50,21 @@ class SceneApi {
//get scene by unit id
static Future<List<ScenesModel>> getScenesByUnitId(String unitId, {showInDevice = false}) async {
static Future<List<ScenesModel>> getScenesByUnitId(
String unitId, String communityId,
{showInDevice = false}) async {
try {
final response = await _httpService.get(
path: ApiEndpoints.getUnitScenes.replaceAll('{unitUuid}', unitId),
path: ApiEndpoints.getUnitScenes
.replaceAll('{spaceUuid}', unitId)
.replaceAll('{communityUuid}', communityId),
queryParameters: {'showInHomePage': showInDevice},
showServerMessage: false,
expectedResponseModel: (json) {
final scenesJson = json['data'] as List;
List<ScenesModel> scenes = [];
for (var scene in json) {
for (var scene in scenesJson) {
scenes.add(ScenesModel.fromJson(scene));
}
return scenes;
@@ -102,10 +111,12 @@ 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),
);
@@ -116,11 +127,12 @@ 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'],
);
@@ -135,7 +147,13 @@ class SceneApi {
final response = await _httpService.get(
path: ApiEndpoints.getScene.replaceAll('{sceneId}', sceneId),
showServerMessage: false,
expectedResponseModel: (json) => SceneDetailsModel.fromJson(json),
expectedResponseModel: (json) {
if (json != null && json['data'] != null) {
return SceneDetailsModel.fromJson(json['data']);
} else {
throw Exception('Data field is null');
}
},
);
return response;
} catch (e) {
@@ -163,7 +181,8 @@ 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;
},
@@ -175,11 +194,14 @@ 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;
},
@@ -192,12 +214,10 @@ class SceneApi {
//delete Scene
static Future<bool> deleteScene({required String unitUuid, required String sceneId}) async {
static Future<bool> deleteScene({required String sceneId}) async {
try {
final response = await _httpService.delete(
path: ApiEndpoints.deleteScene
.replaceAll('{sceneId}', sceneId)
.replaceAll('{unitUuid}', unitUuid),
path: ApiEndpoints.deleteScene.replaceAll('{sceneId}', sceneId),
showServerMessage: false,
expectedResponseModel: (json) => json['statusCode'] == 200,
);