From 0a4ec1c6de0eef4628d1e16afd27c00916ca6a5c Mon Sep 17 00:00:00 2001 From: mohammad Date: Mon, 12 May 2025 10:18:02 +0300 Subject: [PATCH] Refactor API endpoint for getting device reports and fix the record title --- .../flush_sensor_bloc/flush_sensor_bloc.dart | 2 +- .../flush_sensor/flush_persence_records.dart | 2 +- .../flush_sensor/flush_sensor_interface.dart | 2 +- .../water_heater_functions.dart | 4 ++-- lib/services/api/api_links_endpoints.dart | 5 +++-- lib/services/api/devices_api.dart | 16 ++++++++++++++++ 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_bloc.dart b/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_bloc.dart index 4b98da7..5202fb3 100644 --- a/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_bloc.dart +++ b/lib/features/devices/bloc/flush_sensor_bloc/flush_sensor_bloc.dart @@ -119,7 +119,7 @@ class FlushSensorBloc extends Bloc { Emitter emit) async { emit(FlushSensorLoadingInitialState()); try { - await DevicesAPI.getDeviceReports(deviceId, event.code).then((value) { + await DevicesAPI.getReports(deviceId, event.code).then((value) { emit(FlushSensorDeviceReportsState( deviceReport: value, code: event.code)); }); diff --git a/lib/features/devices/view/widgets/flush_sensor/flush_persence_records.dart b/lib/features/devices/view/widgets/flush_sensor/flush_persence_records.dart index a86a160..5f93c68 100644 --- a/lib/features/devices/view/widgets/flush_sensor/flush_persence_records.dart +++ b/lib/features/devices/view/widgets/flush_sensor/flush_persence_records.dart @@ -23,7 +23,7 @@ class FlushPresenceRecords extends StatelessWidget { @override Widget build(BuildContext context) { return DefaultScaffold( - title: title, + title: 'Presence Record', child: BlocProvider( create: (context) => FlushSensorBloc(deviceId: deviceId) ..add(FlushSensorGetDeviceReportsEvent( diff --git a/lib/features/devices/view/widgets/flush_sensor/flush_sensor_interface.dart b/lib/features/devices/view/widgets/flush_sensor/flush_sensor_interface.dart index c41c781..c0f31d2 100644 --- a/lib/features/devices/view/widgets/flush_sensor/flush_sensor_interface.dart +++ b/lib/features/devices/view/widgets/flush_sensor/flush_sensor_interface.dart @@ -61,7 +61,7 @@ class FlushMountedInterface extends StatelessWidget { statusBarIconBrightness: Brightness.light, ), child: DefaultScaffold( - title: deviceModel.name!, + title: FlushSensorBloc.deviceName, actions: [ InkWell( onTap: () async { diff --git a/lib/features/scene/helper/functions_per_device/water_heater_functions.dart b/lib/features/scene/helper/functions_per_device/water_heater_functions.dart index 8a65eb1..411845b 100644 --- a/lib/features/scene/helper/functions_per_device/water_heater_functions.dart +++ b/lib/features/scene/helper/functions_per_device/water_heater_functions.dart @@ -11,7 +11,7 @@ class WaterHeaterFunctionsHelper { deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsAcPower, - operationName: 'Reverse Switch', + operationName: 'Switch', code: 'switch_1', functionValue: functionValue, operationDialogType: OperationDialogType.onOff, @@ -32,7 +32,7 @@ class WaterHeaterFunctionsHelper { deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsLightCountdown, - operationName: 'CountDown', + operationName: 'Timer', code: 'countdown_1', functionValue: functionValue, operationDialogType: OperationDialogType.countdown, diff --git a/lib/services/api/api_links_endpoints.dart b/lib/services/api/api_links_endpoints.dart index b263a33..f8cd72f 100644 --- a/lib/services/api/api_links_endpoints.dart +++ b/lib/services/api/api_links_endpoints.dart @@ -126,8 +126,7 @@ abstract class ApiEndpoints { static const String gatewayApi = '/devices/gateway/{gatewayUuid}/devices'; static const String deviceFunctionsStatus = '/devices/{deviceUuid}/functions/status'; - static const String powerClamp = - '/devices/{deviceUuid}/functions/status'; + static const String powerClamp = '/devices/{deviceUuid}/functions/status'; ///Device Permission Module //POST @@ -233,4 +232,6 @@ abstract class ApiEndpoints { static const String getPermission = '/permission/{roleUuid}'; static const String getAllDevices = '/projects/{projectUuid}/communities/{communityUuid}/spaces/{spaceUuid}/devices'; + + static const String getReportLogs = '/devices/{uuid}/report-logs?code={code}'; } diff --git a/lib/services/api/devices_api.dart b/lib/services/api/devices_api.dart index 35b390e..96ec14a 100644 --- a/lib/services/api/devices_api.dart +++ b/lib/services/api/devices_api.dart @@ -569,6 +569,22 @@ class DevicesAPI { return response; } + static Future getReports( + String uuid, + String code, + ) async { + final response = await HTTPService().get( + path: ApiEndpoints.getReportLogs + .replaceAll('{uuid}', uuid) + .replaceAll('{code}', code), + showServerMessage: false, + expectedResponseModel: (json) { + return DeviceReport.fromJson(json); + }, + ); + return response; + } + static Future> getAllDevices({ required String communityUuid, required String spaceUuid,