From 8b3e64d311d82a9a94f04576e2372fa2e5de33a1 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Mon, 18 Dec 2023 11:54:15 +0200 Subject: [PATCH] Improved class naming --- .../app_communication_repository.dart | 12 +++--- .../cbj_web_server_repository.dart | 12 +++--- .../mqtt_server_repository.dart | 40 +++++++++---------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/infrastructure/app_communication/app_communication_repository.dart b/lib/infrastructure/app_communication/app_communication_repository.dart index a53f698..6cd40f3 100644 --- a/lib/infrastructure/app_communication/app_communication_repository.dart +++ b/lib/infrastructure/app_communication/app_communication_repository.dart @@ -15,8 +15,8 @@ import 'package:cbj_integrations_controller/domain/scene/value_objects_scene_cbj import 'package:cbj_integrations_controller/infrastructure/core/injection.dart'; import 'package:cbj_integrations_controller/infrastructure/devices/device_helper/device_helper.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_dto_abstract.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_base.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_dto_base.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_entities/generic_empty_entity/generic_empty_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_client.dart'; import 'package:grpc/grpc.dart'; @@ -89,7 +89,7 @@ class AppCommunicationRepository extends IAppCommunicationRepository { ISavedDevicesRepo.instance .getAllDevices() .forEach((String id, deviceEntityToSend) { - final DeviceEntityDtoAbstract deviceDtoAbstract = + final DeviceEntityDtoBase deviceDtoAbstract = DeviceHelper.convertDomainToDto(deviceEntityToSend); HubRequestsToApp.streamRequestsToApp.sink.add(deviceDtoAbstract); }); @@ -177,7 +177,7 @@ class AppCommunicationRepository extends IAppCommunicationRepository { /// HubRequestsToApp stream @override Future sendAllDevicesFromHubRequestsStream() async { - final Map allDevices = + final Map allDevices = ISavedDevicesRepo.instance.getAllDevices(); final Map allRooms = @@ -185,7 +185,7 @@ class AppCommunicationRepository extends IAppCommunicationRepository { if (allRooms.isEmpty) { logger.w("Can't find smart devices in the local DB, sending empty"); - final DeviceEntityAbstract emptyEntity = GenericUnsupportedDE.empty(); + final DeviceEntityBase emptyEntity = GenericUnsupportedDE.empty(); HubRequestsToApp.streamRequestsToApp.sink .add(emptyEntity.toInfrastructure()); return; @@ -198,7 +198,7 @@ class AppCommunicationRepository extends IAppCommunicationRepository { return MapEntry(id, jsonEncode(d.toInfrastructure().toJson())); }); - allDevices.map((String id, DeviceEntityAbstract d) { + allDevices.map((String id, DeviceEntityBase d) { HubRequestsToApp.streamRequestsToApp.sink.add(d.toInfrastructure()); return MapEntry(id, DeviceHelper.convertDomainToJsonString(d)); }); diff --git a/lib/infrastructure/cbj_web_server_repository.dart b/lib/infrastructure/cbj_web_server_repository.dart index ce747a4..46a6a70 100644 --- a/lib/infrastructure/cbj_web_server_repository.dart +++ b/lib/infrastructure/cbj_web_server_repository.dart @@ -3,8 +3,8 @@ import 'dart:io'; import 'package:cbj_hub/domain/i_cbj_web_server_repository.dart'; import 'package:cbj_hub/utils.dart'; import 'package:cbj_integrations_controller/domain/i_saved_devices_repo.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_dto_abstract.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_base.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_dto_base.dart'; /// A cbj web server to interact with get current state requests from mqtt as /// well as website to change devices state locally on the network without @@ -29,12 +29,12 @@ class CbjWebServerRepository extends ICbjWebServerRepository { final ISavedDevicesRepo savedDevicesRepo = ISavedDevicesRepo.instance; - final Map allDevices = + final Map allDevices = savedDevicesRepo.getAllDevices(); - DeviceEntityAbstract? deviceObjectOfDeviceId; + DeviceEntityBase? deviceObjectOfDeviceId; - for (final DeviceEntityAbstract d in allDevices.values) { + for (final DeviceEntityBase d in allDevices.values) { if (d.getDeviceId() == deviceId) { deviceObjectOfDeviceId = d; break; @@ -42,7 +42,7 @@ class CbjWebServerRepository extends ICbjWebServerRepository { } if (deviceObjectOfDeviceId != null) { final String requestedDeviceProperty = pathArgs[2]; - final DeviceEntityDtoAbstract deviceEntityDtoAbstract = + final DeviceEntityDtoBase deviceEntityDtoAbstract = deviceObjectOfDeviceId.toInfrastructure(); final Map deviceEntityJson = deviceEntityDtoAbstract.toJson(); diff --git a/lib/infrastructure/mqtt_server_repository.dart b/lib/infrastructure/mqtt_server_repository.dart index a388546..5dc5f9e 100644 --- a/lib/infrastructure/mqtt_server_repository.dart +++ b/lib/infrastructure/mqtt_server_repository.dart @@ -4,8 +4,8 @@ import 'package:cbj_hub/utils.dart'; import 'package:cbj_integrations_controller/domain/connector.dart'; import 'package:cbj_integrations_controller/domain/i_mqtt_server_repository.dart'; import 'package:cbj_integrations_controller/domain/i_saved_devices_repo.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_dto_abstract.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_base.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/device_entity_dto_base.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_entities/abstract_entity/value_objects_core.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_entities/generic_blinds_entity/generic_blinds_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_entities/generic_boiler_entity/generic_boiler_entity.dart'; @@ -221,10 +221,10 @@ class MqttServerRepository extends IMqttServerRepository { final ISavedDevicesRepo savedDevicesRepo = ISavedDevicesRepo.instance; - final Map allDevices = + final Map allDevices = savedDevicesRepo.getAllDevices(); - for (final DeviceEntityAbstract d in allDevices.values) { + for (final DeviceEntityBase d in allDevices.values) { if (d.getDeviceId() == deviceId) { final Map deviceAsJson = d.toInfrastructure().toJson(); @@ -251,8 +251,8 @@ class MqttServerRepository extends IMqttServerRepository { } else { deviceAsJson[property] = propertyValueString; } - final DeviceEntityDtoAbstract savedDeviceWithSameIdAsMqtt = - DeviceEntityDtoAbstract.fromJson(deviceAsJson); + final DeviceEntityDtoBase savedDeviceWithSameIdAsMqtt = + DeviceEntityDtoBase.fromJson(deviceAsJson); HubRequestsToApp.streamRequestsToApp.sink .add(savedDeviceWithSameIdAsMqtt); @@ -275,8 +275,8 @@ class MqttServerRepository extends IMqttServerRepository { } @override - Future publishDeviceEntity(DeviceEntityAbstract deviceEntity) async { - final DeviceEntityDtoAbstract deviceAsDto = deviceEntity.toInfrastructure(); + Future publishDeviceEntity(DeviceEntityBase deviceEntity) async { + final DeviceEntityDtoBase deviceAsDto = deviceEntity.toInfrastructure(); final Map devicePropertiesAsMqttTopicsAndValues = deviceEntityPropertiesToListOfTopicAndValue(deviceAsDto); @@ -341,7 +341,7 @@ class MqttServerRepository extends IMqttServerRepository { /// Convert device entity properties to mqtt topic and massage Map deviceEntityPropertiesToListOfTopicAndValue( - DeviceEntityDtoAbstract deviceEntity, + DeviceEntityDtoBase deviceEntity, ) { final Map json = deviceEntity.toJson(); final String deviceId = json['id'].toString(); @@ -364,7 +364,7 @@ class MqttServerRepository extends IMqttServerRepository { } /// Get saved device dto from mqtt by device id - Future getDeviceDtoFromMqtt( + Future getDeviceDtoFromMqtt( String deviceId, { String? deviceComponentKey, }) async { @@ -376,19 +376,19 @@ class MqttServerRepository extends IMqttServerRepository { final List? a = await readingFromMqttOnce('$pathToDeviceTopic/type'); logger.t('This is a $a'); - return DeviceEntityDtoAbstract(); + return DeviceEntityDtoBase(); } /// Resend the device object throw mqtt Future findDeviceAndResendItToMqtt(String deviceId) async { final ISavedDevicesRepo savedDevicesRepo = ISavedDevicesRepo.instance; - final Map allDevices = + final Map allDevices = savedDevicesRepo.getAllDevices(); - DeviceEntityAbstract? deviceObjectOfDeviceId; + DeviceEntityBase? deviceObjectOfDeviceId; - for (final DeviceEntityAbstract d in allDevices.values) { + for (final DeviceEntityBase d in allDevices.values) { if (d.getDeviceId() == deviceId) { deviceObjectOfDeviceId = d; break; @@ -409,10 +409,10 @@ class MqttServerRepository extends IMqttServerRepository { dynamic entityFromTheApp, bool? gotFromApp, }) async { - if (entityFromTheApp is DeviceEntityAbstract) { - final Map allDevices = + if (entityFromTheApp is DeviceEntityBase) { + final Map allDevices = ISavedDevicesRepo.instance.getAllDevices(); - final DeviceEntityAbstract? savedDeviceEntity = + final DeviceEntityBase? savedDeviceEntity = allDevices[entityFromTheApp.getDeviceId()]; if (savedDeviceEntity == null) { @@ -420,7 +420,7 @@ class MqttServerRepository extends IMqttServerRepository { return; } - MapEntry deviceFromApp; + MapEntry deviceFromApp; if (savedDeviceEntity is GenericLightDE && entityFromTheApp is GenericLightDE) { @@ -534,7 +534,7 @@ class MqttServerRepository extends IMqttServerRepository { @override Future postToAppMqtt({ - required DeviceEntityAbstract entityFromTheHub, + required DeviceEntityBase entityFromTheHub, }) async { // if (entityFromTheHub is Map) { // if (entityFromTheHub['entityStateGRPC'] != @@ -563,7 +563,7 @@ class MqttServerRepository extends IMqttServerRepository { @override Future postSmartDeviceToAppMqtt({ - required DeviceEntityAbstract entityFromTheHub, + required DeviceEntityBase entityFromTheHub, }) async { postToAppMqtt(entityFromTheHub: entityFromTheHub); }