From 8aceffa82e791000310c75ceecbb4020b6dda2a9 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Fri, 8 Dec 2023 12:13:50 +0200 Subject: [PATCH 01/12] Adding melos support to base project --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 08f3134..5783b50 100644 --- a/.gitignore +++ b/.gitignore @@ -93,4 +93,7 @@ lib/infrastructure/core/constant_credentials.dart lib/generated_plugin_registrant.dart # Network tools -network_tools_db/* \ No newline at end of file +network_tools_db/* + +# melos +pubspec_overrides.yaml \ No newline at end of file From beb35505ab1cae3ef56dbbc64166439cc8e8d17c Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Fri, 8 Dec 2023 14:25:50 +0200 Subject: [PATCH 02/12] Removed warrnings --- bin/cbj_hub.dart | 2 +- lib/application/connector/connector.dart | 4 ++-- .../cbj_web_server/cbj_web_server_repository.dart | 2 +- lib/infrastructure/mqtt_server/mqtt_server_repository.dart | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bin/cbj_hub.dart b/bin/cbj_hub.dart index bfea182..1dde1c5 100644 --- a/bin/cbj_hub.dart +++ b/bin/cbj_hub.dart @@ -27,5 +27,5 @@ void setInstancesOfRepos(String projectRootDirectoryPath) { MqttServerRepository(); CbjWebServerRepository(); NodeRedRepository(); - SharedVariables().projectRootDirectoryPath = projectRootDirectoryPath; + SharedVariables().asyncConstructor(projectRootDirectoryPath); } diff --git a/lib/application/connector/connector.dart b/lib/application/connector/connector.dart index 73d510e..fe41312 100644 --- a/lib/application/connector/connector.dart +++ b/lib/application/connector/connector.dart @@ -68,7 +68,7 @@ class Connector { final ISavedDevicesRepo savedDevicesRepo = ISavedDevicesRepo.instance; final Map allDevices = - await savedDevicesRepo.getAllDevices(); + savedDevicesRepo.getAllDevices(); final Map devicePropertyAndValues = deviceChangeFromMqtt.value; @@ -110,7 +110,7 @@ class Connector { if (property == 'entityStateGRPC' && propertyValueString == EntityStateGRPC.ack.toString()) { final Map rooms = - await ISavedRoomsRepo.instance.getAllRooms(); + ISavedRoomsRepo.instance.getAllRooms(); HubRequestsToApp.streamRequestsToApp.sink .add(savedDeviceWithSameIdAsMqtt.toInfrastructure()); diff --git a/lib/infrastructure/cbj_web_server/cbj_web_server_repository.dart b/lib/infrastructure/cbj_web_server/cbj_web_server_repository.dart index a13c367..c121ef4 100644 --- a/lib/infrastructure/cbj_web_server/cbj_web_server_repository.dart +++ b/lib/infrastructure/cbj_web_server/cbj_web_server_repository.dart @@ -30,7 +30,7 @@ class CbjWebServerRepository extends ICbjWebServerRepository { ISavedDevicesRepo.instance; final Map allDevices = - await savedDevicesRepo.getAllDevices(); + savedDevicesRepo.getAllDevices(); DeviceEntityAbstract? deviceObjectOfDeviceId; diff --git a/lib/infrastructure/mqtt_server/mqtt_server_repository.dart b/lib/infrastructure/mqtt_server/mqtt_server_repository.dart index 7bf7191..e258844 100644 --- a/lib/infrastructure/mqtt_server/mqtt_server_repository.dart +++ b/lib/infrastructure/mqtt_server/mqtt_server_repository.dart @@ -222,7 +222,7 @@ class MqttServerRepository extends IMqttServerRepository { final ISavedDevicesRepo savedDevicesRepo = ISavedDevicesRepo.instance; final Map allDevices = - await savedDevicesRepo.getAllDevices(); + savedDevicesRepo.getAllDevices(); for (final DeviceEntityAbstract d in allDevices.values) { if (d.getDeviceId() == deviceId) { @@ -385,7 +385,7 @@ class MqttServerRepository extends IMqttServerRepository { final ISavedDevicesRepo savedDevicesRepo = ISavedDevicesRepo.instance; final Map allDevices = - await savedDevicesRepo.getAllDevices(); + savedDevicesRepo.getAllDevices(); DeviceEntityAbstract? deviceObjectOfDeviceId; @@ -412,7 +412,7 @@ class MqttServerRepository extends IMqttServerRepository { }) async { if (entityFromTheApp is DeviceEntityAbstract) { final Map allDevices = - await ISavedDevicesRepo.instance.getAllDevices(); + ISavedDevicesRepo.instance.getAllDevices(); final DeviceEntityAbstract? savedDeviceEntity = allDevices[entityFromTheApp.getDeviceId()]; From 0d0911eb9764555addea93a67ebfbf12a8b76e00 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Fri, 8 Dec 2023 17:24:16 +0200 Subject: [PATCH 03/12] Removed redundent files --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5783b50..79bbbe9 100644 --- a/.gitignore +++ b/.gitignore @@ -96,4 +96,7 @@ lib/generated_plugin_registrant.dart network_tools_db/* # melos -pubspec_overrides.yaml \ No newline at end of file +pubspec_overrides.yaml + +# Linux +.directory \ No newline at end of file From 14452167e533c94af07b029e23e00d7a66550028 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Sat, 9 Dec 2023 12:10:06 +0200 Subject: [PATCH 04/12] Improved readability --- lib/application/boot_up/boot_up.dart | 8 +- lib/application/connector/connector.dart | 137 ------------------ .../app_communication_repository.dart | 6 +- .../app_communication/hub_app_server.dart | 2 +- .../cbj_web_server_repository.dart | 2 +- .../mqtt_server/mqtt_server_repository.dart | 14 +- .../remote_pipes/remote_pipes_client.dart | 7 +- 7 files changed, 20 insertions(+), 156 deletions(-) delete mode 100644 lib/application/connector/connector.dart diff --git a/lib/application/boot_up/boot_up.dart b/lib/application/boot_up/boot_up.dart index 20472a1..7abcb93 100644 --- a/lib/application/boot_up/boot_up.dart +++ b/lib/application/boot_up/boot_up.dart @@ -1,4 +1,5 @@ -import 'package:cbj_hub/application/connector/connector.dart'; +import 'package:cbj_hub/infrastructure/app_communication/app_communication_repository.dart'; +import 'package:cbj_integrations_controller/domain/connector.dart'; import 'package:cbj_integrations_controller/initialize_integrations_controller.dart'; class BootUp { @@ -8,6 +9,9 @@ class BootUp { Future setup() async { await setupIntegrationsController(); - Connector.startConnector(); + Connector().startConnector(); + Future.delayed(const Duration(milliseconds: 3000)).whenComplete(() { + AppCommunicationRepository(); + }); } } diff --git a/lib/application/connector/connector.dart b/lib/application/connector/connector.dart deleted file mode 100644 index fe41312..0000000 --- a/lib/application/connector/connector.dart +++ /dev/null @@ -1,137 +0,0 @@ -import 'dart:async'; -import 'dart:convert'; - -import 'package:cbj_hub/infrastructure/app_communication/app_communication_repository.dart'; -import 'package:cbj_integrations_controller/domain/mqtt_server/i_mqtt_server_repository.dart'; -import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cbj_integrations_controller/domain/room/value_objects_room.dart'; -import 'package:cbj_integrations_controller/domain/rooms/i_saved_rooms_repo.dart'; -import 'package:cbj_integrations_controller/domain/saved_devices/i_saved_devices_repo.dart'; -import 'package:cbj_integrations_controller/infrastructure/devices/companies_connector_conjecture.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_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_dto_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_client.dart'; -import 'package:cbj_integrations_controller/utils.dart'; -import 'package:mqtt_client/mqtt_client.dart'; - -class Connector { - static Future startConnector() async { - ConnectorStreamToMqtt.toMqttStream.listen((entityForMqtt) async { - if (entityForMqtt.value is DeviceEntityAbstract) { - /// Data will probably arrive to the function - /// updateAllDevicesReposWithDeviceChanges where we listen to request from - /// the mqtt with this path - await IMqttServerRepository.instance - .publishDeviceEntity(entityForMqtt.value as DeviceEntityAbstract); - } else if (entityForMqtt.value is RoomEntity) { - // TODO: Create MQTT support for rooms - logger.w('Please create MQTT support for Room Entity'); - } else { - logger.w('Entity type to send to MQTT is not supported'); - } - }); - - final ISavedDevicesRepo savedDevicesRepo = ISavedDevicesRepo.instance; - - final Map allDevices = - await savedDevicesRepo.getAllDevicesAfterInitialize(); - - for (final String deviceId in allDevices.keys) { - ConnectorStreamToMqtt.toMqttController.add( - allDevices.entries.firstWhere( - (MapEntry a) => a.key == deviceId, - ), - ); - } - - Future.delayed(const Duration(milliseconds: 3000)).whenComplete(() { - AppCommunicationRepository(); - }); - - IMqttServerRepository.instance.allHubDevicesSubscriptions(); - - IMqttServerRepository.instance.sendToApp(); - - CompaniesConnectorConjecture().updateAllDevicesReposWithDeviceChanges( - ConnectorDevicesStreamFromMqtt.fromMqttStream, - ); - - ConnectorDevicesStreamFromMqtt.fromMqttStream.listen((deviceFromMqtt) { - savedDevicesRepo.addOrUpdateFromMqtt(deviceFromMqtt); - }); - } - - static Future updateDevicesFromMqttDeviceChange( - MapEntry> deviceChangeFromMqtt, - ) async { - final ISavedDevicesRepo savedDevicesRepo = ISavedDevicesRepo.instance; - - final Map allDevices = - savedDevicesRepo.getAllDevices(); - - final Map devicePropertyAndValues = - deviceChangeFromMqtt.value; - - // String? deviceStateValue; - - for (final DeviceEntityAbstract d in allDevices.values) { - if (d.getDeviceId() == deviceChangeFromMqtt.key) { - final Map deviceAsJson = d.toInfrastructure().toJson(); - - for (final String property in devicePropertyAndValues.keys) { - // final String pt = - MqttPublishPayload.bytesToStringAsString( - (devicePropertyAndValues[property] as MqttPublishMessage) - .payload - .message, - ).replaceAll('\n', ''); - - final valueMessage = - (devicePropertyAndValues[property] as MqttPublishMessage) - .payload - .message; - final String propertyValueString = - utf8.decode(valueMessage, allowMalformed: true); - - if (propertyValueString.contains('value')) { - final Map propertyValueJson = - jsonDecode(propertyValueString) as Map; - deviceAsJson[property] = propertyValueJson['value']; - } else { - deviceAsJson[property] = propertyValueString; - } - final DeviceEntityAbstract savedDeviceWithSameIdAsMqtt = - DeviceEntityDtoAbstract.fromJson(deviceAsJson).toDomain(); - - ConnectorDevicesStreamFromMqtt.fromMqttStream.sink - .add(savedDeviceWithSameIdAsMqtt); - - if (property == 'entityStateGRPC' && - propertyValueString == EntityStateGRPC.ack.toString()) { - final Map rooms = - ISavedRoomsRepo.instance.getAllRooms(); - - HubRequestsToApp.streamRequestsToApp.sink - .add(savedDeviceWithSameIdAsMqtt.toInfrastructure()); - final RoomEntity? discoverRoom = - rooms[RoomUniqueId.discoveredRoomId().getOrCrash()]; - if (discoverRoom == null) { - continue; - } - - if (discoverRoom.roomDevicesId - .getOrCrash() - .contains(savedDeviceWithSameIdAsMqtt.uniqueId.getOrCrash())) { - HubRequestsToApp.streamRequestsToApp.sink.add( - rooms[RoomUniqueId.discoveredRoomId().getOrCrash()]! - .toInfrastructure(), - ); - } - } - return; - } - } - } - } -} diff --git a/lib/infrastructure/app_communication/app_communication_repository.dart b/lib/infrastructure/app_communication/app_communication_repository.dart index 443e704..efcc3f0 100644 --- a/lib/infrastructure/app_communication/app_communication_repository.dart +++ b/lib/infrastructure/app_communication/app_communication_repository.dart @@ -4,11 +4,11 @@ import 'dart:convert'; import 'package:cbj_hub/infrastructure/app_communication/hub_app_server.dart'; import 'package:cbj_hub/infrastructure/remote_pipes/remote_pipes_client.dart'; import 'package:cbj_hub/utils.dart'; -import 'package:cbj_integrations_controller/domain/app_communication/i_app_communication_repository.dart'; import 'package:cbj_integrations_controller/domain/core/value_objects.dart'; +import 'package:cbj_integrations_controller/domain/i_app_communication_repository.dart'; +import 'package:cbj_integrations_controller/domain/i_saved_devices_repo.dart'; +import 'package:cbj_integrations_controller/domain/i_saved_rooms_repo.dart'; import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; -import 'package:cbj_integrations_controller/domain/rooms/i_saved_rooms_repo.dart'; -import 'package:cbj_integrations_controller/domain/saved_devices/i_saved_devices_repo.dart'; import 'package:cbj_integrations_controller/domain/scene/i_scene_cbj_repository.dart'; import 'package:cbj_integrations_controller/domain/scene/scene_cbj_entity.dart'; import 'package:cbj_integrations_controller/domain/scene/value_objects_scene_cbj.dart'; diff --git a/lib/infrastructure/app_communication/hub_app_server.dart b/lib/infrastructure/app_communication/hub_app_server.dart index 57a3529..29e2e01 100644 --- a/lib/infrastructure/app_communication/hub_app_server.dart +++ b/lib/infrastructure/app_communication/hub_app_server.dart @@ -1,7 +1,7 @@ import 'dart:io'; import 'package:cbj_hub/utils.dart'; -import 'package:cbj_integrations_controller/domain/app_communication/i_app_communication_repository.dart'; +import 'package:cbj_integrations_controller/domain/i_app_communication_repository.dart'; import 'package:cbj_integrations_controller/infrastructure/devices/helper_methods/device_helper_methods.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/proto_gen_date.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart'; diff --git a/lib/infrastructure/cbj_web_server/cbj_web_server_repository.dart b/lib/infrastructure/cbj_web_server/cbj_web_server_repository.dart index c121ef4..5ad6c40 100644 --- a/lib/infrastructure/cbj_web_server/cbj_web_server_repository.dart +++ b/lib/infrastructure/cbj_web_server/cbj_web_server_repository.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:cbj_hub/domain/cbj_web_server/i_cbj_web_server_repository.dart'; import 'package:cbj_hub/utils.dart'; -import 'package:cbj_integrations_controller/domain/saved_devices/i_saved_devices_repo.dart'; +import 'package:cbj_integrations_controller/domain/i_saved_devices_repo.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_dto_abstract.dart'; diff --git a/lib/infrastructure/mqtt_server/mqtt_server_repository.dart b/lib/infrastructure/mqtt_server/mqtt_server_repository.dart index e258844..967ecec 100644 --- a/lib/infrastructure/mqtt_server/mqtt_server_repository.dart +++ b/lib/infrastructure/mqtt_server/mqtt_server_repository.dart @@ -1,9 +1,9 @@ import 'dart:convert'; -import 'package:cbj_hub/application/connector/connector.dart'; import 'package:cbj_hub/utils.dart'; -import 'package:cbj_integrations_controller/domain/mqtt_server/i_mqtt_server_repository.dart'; -import 'package:cbj_integrations_controller/domain/saved_devices/i_saved_devices_repo.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_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_dto_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/value_objects_core.dart'; @@ -194,7 +194,7 @@ class MqttServerRepository extends IMqttServerRepository { return; } - Connector.updateDevicesFromMqttDeviceChange( + Connector().updateDevicesFromMqttDeviceChange( MapEntry( deviceId, {deviceDeviceTypeThatChanged: mqttPublishMessage[0].payload}, @@ -296,7 +296,6 @@ class MqttServerRepository extends IMqttServerRepository { Future?> readingFromMqttOnce(String topic) async { final MqttClientTopicFilter mqttClientTopic = MqttClientTopicFilter(topic, client.updates); - // final Stream>> myValueStream = mqttClientTopic.updates.asBroadcastStream(); // myValueStream.listen((event) { @@ -524,8 +523,7 @@ class MqttServerRepository extends IMqttServerRepository { deviceFromApp.value.entityStateGRPC = EntityState(entityFromTheApp.entityStateGRPC.getOrCrash()); } - - ConnectorStreamToMqtt.toMqttController.sink.add(deviceFromApp); + Connector().fromMqtt(deviceFromApp); } else { logger.w( 'Entity from app type ${entityFromTheApp.runtimeType} not ' @@ -553,7 +551,7 @@ class MqttServerRepository extends IMqttServerRepository { entityFromTheHub, ); - ConnectorStreamToMqtt.toMqttController.sink.add(deviceInMapEntry); + Connector().fromMqtt(deviceInMapEntry); // } else { // logger.w( diff --git a/lib/infrastructure/remote_pipes/remote_pipes_client.dart b/lib/infrastructure/remote_pipes/remote_pipes_client.dart index dc27d62..eea98b1 100644 --- a/lib/infrastructure/remote_pipes/remote_pipes_client.dart +++ b/lib/infrastructure/remote_pipes/remote_pipes_client.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:cbj_integrations_controller/domain/app_communication/i_app_communication_repository.dart'; +import 'package:cbj_integrations_controller/domain/i_app_communication_repository.dart'; import 'package:cbj_integrations_controller/infrastructure/devices/helper_methods/device_helper_methods.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/hub_client/hub_client.dart'; @@ -21,10 +21,9 @@ class RemotePipesClient { channel = await _createCbjHubClient(addressToHub, hubPort); stub = CbjHubClient(channel!); - ResponseStream response; - try { - response = stub!.hubTransferEntities( + final ResponseStream response = + stub!.hubTransferEntities( /// Transfer all requests from hub to the remote pipes->app HubRequestsToApp.streamRequestsToApp .map(DeviceHelperMethods().dynamicToRequestsAndStatusFromHub) From 6d31877e8ded58a9db042c8769f73545a4a9de48 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Sat, 9 Dec 2023 19:19:48 +0200 Subject: [PATCH 05/12] Created core folder for cbj_integrations_controller --- bin/cbj_hub.dart | 4 ++-- lib/application/boot_up/boot_up.dart | 2 +- .../app_communication/app_communication_repository.dart | 3 +-- lib/infrastructure/remote_pipes/remote_pipes_client.dart | 6 +++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/bin/cbj_hub.dart b/bin/cbj_hub.dart index 1dde1c5..fcec42a 100644 --- a/bin/cbj_hub.dart +++ b/bin/cbj_hub.dart @@ -3,10 +3,10 @@ import 'dart:io'; import 'package:cbj_hub/application/boot_up/boot_up.dart'; import 'package:cbj_hub/infrastructure/cbj_web_server/cbj_web_server_repository.dart'; import 'package:cbj_hub/infrastructure/mqtt_server/mqtt_server_repository.dart'; +import 'package:cbj_integrations_controller/infrastructure/core/initialize_integrations_controller.dart'; +import 'package:cbj_integrations_controller/infrastructure/core/injection.dart'; import 'package:cbj_integrations_controller/infrastructure/node_red/node_red_repository.dart'; import 'package:cbj_integrations_controller/infrastructure/shared_variables.dart'; -import 'package:cbj_integrations_controller/initialize_integrations_controller.dart'; -import 'package:cbj_integrations_controller/injection.dart'; import 'package:network_tools/network_tools.dart'; Future main(List arguments) async { diff --git a/lib/application/boot_up/boot_up.dart b/lib/application/boot_up/boot_up.dart index 7abcb93..ee9b1f4 100644 --- a/lib/application/boot_up/boot_up.dart +++ b/lib/application/boot_up/boot_up.dart @@ -1,6 +1,6 @@ import 'package:cbj_hub/infrastructure/app_communication/app_communication_repository.dart'; import 'package:cbj_integrations_controller/domain/connector.dart'; -import 'package:cbj_integrations_controller/initialize_integrations_controller.dart'; +import 'package:cbj_integrations_controller/infrastructure/core/initialize_integrations_controller.dart'; class BootUp { BootUp() { diff --git a/lib/infrastructure/app_communication/app_communication_repository.dart b/lib/infrastructure/app_communication/app_communication_repository.dart index efcc3f0..1ad265d 100644 --- a/lib/infrastructure/app_communication/app_communication_repository.dart +++ b/lib/infrastructure/app_communication/app_communication_repository.dart @@ -12,13 +12,13 @@ import 'package:cbj_integrations_controller/domain/room/room_entity.dart'; import 'package:cbj_integrations_controller/domain/scene/i_scene_cbj_repository.dart'; import 'package:cbj_integrations_controller/domain/scene/scene_cbj_entity.dart'; import 'package:cbj_integrations_controller/domain/scene/value_objects_scene_cbj.dart'; +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_devices/abstract_device/device_entity_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_dto_abstract.dart'; import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_empty_device/generic_empty_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_client.dart'; -import 'package:cbj_integrations_controller/injection.dart'; import 'package:grpc/grpc.dart'; import 'package:internet_connection_checker/internet_connection_checker.dart'; import 'package:mqtt_client/mqtt_client.dart'; @@ -82,7 +82,6 @@ class AppCommunicationRepository extends IAppCommunicationRepository { startRemotePipesConnection(remotePipesDomain); } - @override void sendToApp(Stream dataToSend) { dataToSend.listen((MqttPublishMessage event) async { logger.i('Got hub requests to app'); diff --git a/lib/infrastructure/remote_pipes/remote_pipes_client.dart b/lib/infrastructure/remote_pipes/remote_pipes_client.dart index eea98b1..f6528a0 100644 --- a/lib/infrastructure/remote_pipes/remote_pipes_client.dart +++ b/lib/infrastructure/remote_pipes/remote_pipes_client.dart @@ -1,10 +1,10 @@ import 'dart:async'; import 'package:cbj_integrations_controller/domain/i_app_communication_repository.dart'; +import 'package:cbj_integrations_controller/infrastructure/core/utils.dart'; import 'package:cbj_integrations_controller/infrastructure/devices/helper_methods/device_helper_methods.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/hub_client/hub_client.dart'; -import 'package:cbj_integrations_controller/utils.dart'; import 'package:grpc/grpc.dart'; // TODO: Replace with HubClient @@ -28,7 +28,7 @@ class RemotePipesClient { HubRequestsToApp.streamRequestsToApp .map(DeviceHelperMethods().dynamicToRequestsAndStatusFromHub) .handleError((error) { - logger.e('Stream have error $error'); + icLogger.e('Stream have error $error'); }), ); @@ -39,7 +39,7 @@ class RemotePipesClient { isRemotePipes: true, ); } catch (e) { - logger.e('Caught error: $e'); + icLogger.e('Caught error: $e'); await channel?.terminate(); } } From 119caf73709a1f19ed01b15c9c0505235394a5d4 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Sun, 10 Dec 2023 20:55:28 +0200 Subject: [PATCH 06/12] facade for network tools --- .../app_communication_repository.dart | 3 ++- pubspec.yaml | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/infrastructure/app_communication/app_communication_repository.dart b/lib/infrastructure/app_communication/app_communication_repository.dart index 1ad265d..fe94796 100644 --- a/lib/infrastructure/app_communication/app_communication_repository.dart +++ b/lib/infrastructure/app_communication/app_communication_repository.dart @@ -185,7 +185,8 @@ class AppCommunicationRepository extends IAppCommunicationRepository { if (allRooms.isEmpty) { logger.w("Can't find smart devices in the local DB, sending empty"); - final DeviceEntityAbstract emptyEntity = GenericEmptyDE.empty(); + final DeviceEntityAbstract emptyEntity = + GenericGenericUnsupportedDE.empty(); HubRequestsToApp.streamRequestsToApp.sink .add(emptyEntity.toInfrastructure()); return; diff --git a/pubspec.yaml b/pubspec.yaml index 4dd752b..d0fe70d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,17 +2,17 @@ name: cbj_hub description: Easy to use open source Hub to control your smart devices from one app. version: 1.3.0+6 homepage: https://cybearjinni.com -issue_tracker: https://github.com/osociety/network_tools/issues +issue_tracker: https://github.com/CyBear-Jinni/cbj_hub/issues publish_to: none environment: - sdk: '>=3.0.0 <4.0.0' + sdk: ">=3.0.0 <4.0.0" dependencies: # Contains utility classes in the style of dart:async to work with asynchronous computations. async: ^2.11.0 cbj_integrations_controller: -# path: ../cbj_integrations_controller + # path: ../cbj_integrations_controller git: https://github.com/CyBear-Jinni/cbj_integrations_controller.git # Package to create, convert, alter, and compare colors in a variety of colorspaces. color: ^3.0.0 @@ -37,7 +37,7 @@ dependencies: # Utility library that checks for an Active Internet connection internet_connection_checker: ^1.0.0+1 # Extremely fast, easy to use, and fully async NoSQL database. -# isar: ^3.0.5 + # isar: ^3.0.5 # Defines the annotations used by json_serializable to create code for JSON serialization and deserialization. json_annotation: ^4.8.1 # Dart Build System builders for handling JSON. @@ -69,7 +69,7 @@ dev_dependencies: # Automatically generates Hive TypeAdapters to store any class hive_generator: ^2.0.1 # Code generator for the Isar Database. Finds classes annotated with @Collection. -# isar_generator: ^3.0.5 + # isar_generator: ^3.0.5 # Collection of lint rules for Dart and Flutter projects lint: ^2.2.0 # Library for mocks From 3ff00bf3b0b7a9b5912f2112f3de6be7e8dcf689 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Mon, 11 Dec 2023 23:08:32 +0200 Subject: [PATCH 07/12] Continue work on new architecture --- .../app_communication/app_communication_repository.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/infrastructure/app_communication/app_communication_repository.dart b/lib/infrastructure/app_communication/app_communication_repository.dart index fe94796..706f4dd 100644 --- a/lib/infrastructure/app_communication/app_communication_repository.dart +++ b/lib/infrastructure/app_communication/app_communication_repository.dart @@ -185,8 +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 = - GenericGenericUnsupportedDE.empty(); + final DeviceEntityAbstract emptyEntity = GenericUnsupportedDE.empty(); HubRequestsToApp.streamRequestsToApp.sink .add(emptyEntity.toInfrastructure()); return; From 9735734f10e46902fcff89f8a1fac22a53868560 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Fri, 15 Dec 2023 01:17:36 +0200 Subject: [PATCH 08/12] Moved single files out of the folder --- bin/cbj_hub.dart | 6 +++--- lib/application/{boot_up => }/boot_up.dart | 0 .../{cbj_web_server => }/i_cbj_web_server_repository.dart | 0 .../app_communication/app_communication_repository.dart | 2 +- .../{cbj_web_server => }/cbj_web_server_repository.dart | 2 +- .../{mqtt_server => }/mqtt_server_repository.dart | 0 .../{remote_pipes => }/remote_pipes_client.dart | 0 7 files changed, 5 insertions(+), 5 deletions(-) rename lib/application/{boot_up => }/boot_up.dart (100%) rename lib/domain/{cbj_web_server => }/i_cbj_web_server_repository.dart (100%) rename lib/infrastructure/{cbj_web_server => }/cbj_web_server_repository.dart (97%) rename lib/infrastructure/{mqtt_server => }/mqtt_server_repository.dart (100%) rename lib/infrastructure/{remote_pipes => }/remote_pipes_client.dart (100%) diff --git a/bin/cbj_hub.dart b/bin/cbj_hub.dart index fcec42a..b453a82 100644 --- a/bin/cbj_hub.dart +++ b/bin/cbj_hub.dart @@ -1,8 +1,8 @@ import 'dart:io'; -import 'package:cbj_hub/application/boot_up/boot_up.dart'; -import 'package:cbj_hub/infrastructure/cbj_web_server/cbj_web_server_repository.dart'; -import 'package:cbj_hub/infrastructure/mqtt_server/mqtt_server_repository.dart'; +import 'package:cbj_hub/application/boot_up.dart'; +import 'package:cbj_hub/infrastructure/cbj_web_server_repository.dart'; +import 'package:cbj_hub/infrastructure/mqtt_server_repository.dart'; import 'package:cbj_integrations_controller/infrastructure/core/initialize_integrations_controller.dart'; import 'package:cbj_integrations_controller/infrastructure/core/injection.dart'; import 'package:cbj_integrations_controller/infrastructure/node_red/node_red_repository.dart'; diff --git a/lib/application/boot_up/boot_up.dart b/lib/application/boot_up.dart similarity index 100% rename from lib/application/boot_up/boot_up.dart rename to lib/application/boot_up.dart diff --git a/lib/domain/cbj_web_server/i_cbj_web_server_repository.dart b/lib/domain/i_cbj_web_server_repository.dart similarity index 100% rename from lib/domain/cbj_web_server/i_cbj_web_server_repository.dart rename to lib/domain/i_cbj_web_server_repository.dart diff --git a/lib/infrastructure/app_communication/app_communication_repository.dart b/lib/infrastructure/app_communication/app_communication_repository.dart index 706f4dd..165cd8e 100644 --- a/lib/infrastructure/app_communication/app_communication_repository.dart +++ b/lib/infrastructure/app_communication/app_communication_repository.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'dart:convert'; import 'package:cbj_hub/infrastructure/app_communication/hub_app_server.dart'; -import 'package:cbj_hub/infrastructure/remote_pipes/remote_pipes_client.dart'; +import 'package:cbj_hub/infrastructure/remote_pipes_client.dart'; import 'package:cbj_hub/utils.dart'; import 'package:cbj_integrations_controller/domain/core/value_objects.dart'; import 'package:cbj_integrations_controller/domain/i_app_communication_repository.dart'; diff --git a/lib/infrastructure/cbj_web_server/cbj_web_server_repository.dart b/lib/infrastructure/cbj_web_server_repository.dart similarity index 97% rename from lib/infrastructure/cbj_web_server/cbj_web_server_repository.dart rename to lib/infrastructure/cbj_web_server_repository.dart index 5ad6c40..9643514 100644 --- a/lib/infrastructure/cbj_web_server/cbj_web_server_repository.dart +++ b/lib/infrastructure/cbj_web_server_repository.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:cbj_hub/domain/cbj_web_server/i_cbj_web_server_repository.dart'; +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_devices/abstract_device/device_entity_abstract.dart'; diff --git a/lib/infrastructure/mqtt_server/mqtt_server_repository.dart b/lib/infrastructure/mqtt_server_repository.dart similarity index 100% rename from lib/infrastructure/mqtt_server/mqtt_server_repository.dart rename to lib/infrastructure/mqtt_server_repository.dart diff --git a/lib/infrastructure/remote_pipes/remote_pipes_client.dart b/lib/infrastructure/remote_pipes_client.dart similarity index 100% rename from lib/infrastructure/remote_pipes/remote_pipes_client.dart rename to lib/infrastructure/remote_pipes_client.dart From cdefed8c5cbc62abc295a9ff020753b480522f66 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Fri, 15 Dec 2023 18:30:57 +0200 Subject: [PATCH 09/12] More work on the new architecture --- .../app_communication_repository.dart | 6 ++--- .../cbj_web_server_repository.dart | 4 ++-- .../mqtt_server_repository.dart | 24 +++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/infrastructure/app_communication/app_communication_repository.dart b/lib/infrastructure/app_communication/app_communication_repository.dart index 165cd8e..a53f698 100644 --- a/lib/infrastructure/app_communication/app_communication_repository.dart +++ b/lib/infrastructure/app_communication/app_communication_repository.dart @@ -15,9 +15,9 @@ 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_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_dto_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_empty_device/generic_empty_entity.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/generic_empty_entity/generic_empty_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_client.dart'; import 'package:grpc/grpc.dart'; import 'package:internet_connection_checker/internet_connection_checker.dart'; diff --git a/lib/infrastructure/cbj_web_server_repository.dart b/lib/infrastructure/cbj_web_server_repository.dart index 9643514..ce747a4 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_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_dto_abstract.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'; /// 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 diff --git a/lib/infrastructure/mqtt_server_repository.dart b/lib/infrastructure/mqtt_server_repository.dart index 967ecec..a388546 100644 --- a/lib/infrastructure/mqtt_server_repository.dart +++ b/lib/infrastructure/mqtt_server_repository.dart @@ -4,18 +4,18 @@ 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_devices/abstract_device/device_entity_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/device_entity_dto_abstract.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/value_objects_core.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_blinds_device/generic_blinds_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_boiler_device/generic_boiler_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_dimmable_light_device/generic_dimmable_light_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_rgbw_light_device/generic_rgbw_light_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_computer_device/generic_smart_computer_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_plug_device/generic_smart_plug_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_smart_tv/generic_smart_tv_entity.dart'; -import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_switch_device/generic_switch_entity.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/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'; +import 'package:cbj_integrations_controller/infrastructure/generic_entities/generic_dimmable_light_entity/generic_dimmable_light_entity.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_entities/generic_light_entity/generic_light_entity.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_entities/generic_rgbw_light_entity/generic_rgbw_light_entity.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_entities/generic_smart_computer_entity/generic_smart_computer_entity.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_entities/generic_smart_plug_entity/generic_smart_plug_entity.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_entities/generic_smart_tv_entity/generic_smart_tv_entity.dart'; +import 'package:cbj_integrations_controller/infrastructure/generic_entities/generic_switch_entity/generic_switch_entity.dart'; import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_client.dart'; import 'package:mqtt_client/mqtt_client.dart'; import 'package:mqtt_client/mqtt_server_client.dart'; From 31d4d6877263f81d88901dfa9c97c2a68e60ac3b Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Sun, 17 Dec 2023 00:49:22 +0200 Subject: [PATCH 10/12] Changed file location --- lib/infrastructure/app_communication/hub_app_server.dart | 2 +- lib/infrastructure/remote_pipes_client.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/infrastructure/app_communication/hub_app_server.dart b/lib/infrastructure/app_communication/hub_app_server.dart index 29e2e01..be9154b 100644 --- a/lib/infrastructure/app_communication/hub_app_server.dart +++ b/lib/infrastructure/app_communication/hub_app_server.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:cbj_hub/utils.dart'; import 'package:cbj_integrations_controller/domain/i_app_communication_repository.dart'; -import 'package:cbj_integrations_controller/infrastructure/devices/helper_methods/device_helper_methods.dart'; +import 'package:cbj_integrations_controller/infrastructure/devices/device_helper/device_helper_methods.dart'; import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/proto_gen_date.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/hub_client/hub_client.dart'; diff --git a/lib/infrastructure/remote_pipes_client.dart b/lib/infrastructure/remote_pipes_client.dart index f6528a0..bd2dfa2 100644 --- a/lib/infrastructure/remote_pipes_client.dart +++ b/lib/infrastructure/remote_pipes_client.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'package:cbj_integrations_controller/domain/i_app_communication_repository.dart'; import 'package:cbj_integrations_controller/infrastructure/core/utils.dart'; -import 'package:cbj_integrations_controller/infrastructure/devices/helper_methods/device_helper_methods.dart'; +import 'package:cbj_integrations_controller/infrastructure/devices/device_helper/device_helper_methods.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/hub_client/hub_client.dart'; import 'package:grpc/grpc.dart'; From 8b3e64d311d82a9a94f04576e2372fa2e5de33a1 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Mon, 18 Dec 2023 11:54:15 +0200 Subject: [PATCH 11/12] 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); } From e8ddf5904cf3a0e2fbdcfc07e38d712deb69a1ca Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Sat, 23 Dec 2023 02:36:50 +0200 Subject: [PATCH 12/12] Small changes to be compatible with the new architecture --- bin/cbj_hub.dart | 3 +-- lib/infrastructure/cbj_web_server_repository.dart | 2 +- lib/infrastructure/mqtt_server_repository.dart | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/bin/cbj_hub.dart b/bin/cbj_hub.dart index b453a82..89d6ef4 100644 --- a/bin/cbj_hub.dart +++ b/bin/cbj_hub.dart @@ -7,10 +7,9 @@ import 'package:cbj_integrations_controller/infrastructure/core/initialize_integ import 'package:cbj_integrations_controller/infrastructure/core/injection.dart'; import 'package:cbj_integrations_controller/infrastructure/node_red/node_red_repository.dart'; import 'package:cbj_integrations_controller/infrastructure/shared_variables.dart'; -import 'package:network_tools/network_tools.dart'; Future main(List arguments) async { - configureNetworkTools('network_tools_db'); + // configureNetworkTools('network_tools_db'); setInstancesOfRepos(arguments.firstOrNull ?? Directory.current.path); // arguments[0] is the location of the project diff --git a/lib/infrastructure/cbj_web_server_repository.dart b/lib/infrastructure/cbj_web_server_repository.dart index 46a6a70..b148118 100644 --- a/lib/infrastructure/cbj_web_server_repository.dart +++ b/lib/infrastructure/cbj_web_server_repository.dart @@ -35,7 +35,7 @@ class CbjWebServerRepository extends ICbjWebServerRepository { DeviceEntityBase? deviceObjectOfDeviceId; for (final DeviceEntityBase d in allDevices.values) { - if (d.getDeviceId() == deviceId) { + if (d.getCbjDeviceId == deviceId) { deviceObjectOfDeviceId = d; break; } diff --git a/lib/infrastructure/mqtt_server_repository.dart b/lib/infrastructure/mqtt_server_repository.dart index 5dc5f9e..d01d189 100644 --- a/lib/infrastructure/mqtt_server_repository.dart +++ b/lib/infrastructure/mqtt_server_repository.dart @@ -225,7 +225,7 @@ class MqttServerRepository extends IMqttServerRepository { savedDevicesRepo.getAllDevices(); for (final DeviceEntityBase d in allDevices.values) { - if (d.getDeviceId() == deviceId) { + if (d.getCbjDeviceId == deviceId) { final Map deviceAsJson = d.toInfrastructure().toJson(); @@ -389,7 +389,7 @@ class MqttServerRepository extends IMqttServerRepository { DeviceEntityBase? deviceObjectOfDeviceId; for (final DeviceEntityBase d in allDevices.values) { - if (d.getDeviceId() == deviceId) { + if (d.getCbjDeviceId == deviceId) { deviceObjectOfDeviceId = d; break; } @@ -413,7 +413,7 @@ class MqttServerRepository extends IMqttServerRepository { final Map allDevices = ISavedDevicesRepo.instance.getAllDevices(); final DeviceEntityBase? savedDeviceEntity = - allDevices[entityFromTheApp.getDeviceId()]; + allDevices[entityFromTheApp.getCbjDeviceId]; if (savedDeviceEntity == null) { logger.w('Device id does not match existing device');