Skip to content

Commit

Permalink
Merge pull request #331 from CyBear-Jinni/grpc_changes_hub
Browse files Browse the repository at this point in the history
Grpc changes hub
  • Loading branch information
guyluz11 authored Dec 23, 2023
2 parents 2599a3d + e8ddf59 commit e84b170
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 241 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,10 @@ lib/infrastructure/core/constant_credentials.dart
lib/generated_plugin_registrant.dart

# Network tools
network_tools_db/*
network_tools_db/*

# melos
pubspec_overrides.yaml

# Linux
.directory
15 changes: 7 additions & 8 deletions bin/cbj_hub.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
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';
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<void> main(List<String> arguments) async {
configureNetworkTools('network_tools_db');
// configureNetworkTools('network_tools_db');

setInstancesOfRepos(arguments.firstOrNull ?? Directory.current.path);
// arguments[0] is the location of the project
Expand All @@ -27,5 +26,5 @@ void setInstancesOfRepos(String projectRootDirectoryPath) {
MqttServerRepository();
CbjWebServerRepository();
NodeRedRepository();
SharedVariables().projectRootDirectoryPath = projectRootDirectoryPath;
SharedVariables().asyncConstructor(projectRootDirectoryPath);
}
17 changes: 17 additions & 0 deletions lib/application/boot_up.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:cbj_hub/infrastructure/app_communication/app_communication_repository.dart';
import 'package:cbj_integrations_controller/domain/connector.dart';
import 'package:cbj_integrations_controller/infrastructure/core/initialize_integrations_controller.dart';

class BootUp {
BootUp() {
setup();
}

Future<void> setup() async {
await setupIntegrationsController();
Connector().startConnector();
Future.delayed(const Duration(milliseconds: 3000)).whenComplete(() {
AppCommunicationRepository();
});
}
}
13 changes: 0 additions & 13 deletions lib/application/boot_up/boot_up.dart

This file was deleted.

137 changes: 0 additions & 137 deletions lib/application/connector/connector.dart

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ 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/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';
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_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: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';
Expand Down Expand Up @@ -82,15 +82,14 @@ class AppCommunicationRepository extends IAppCommunicationRepository {
startRemotePipesConnection(remotePipesDomain);
}

@override
void sendToApp(Stream<MqttPublishMessage> dataToSend) {
dataToSend.listen((MqttPublishMessage event) async {
logger.i('Got hub requests to app');

ISavedDevicesRepo.instance
.getAllDevices()
.forEach((String id, deviceEntityToSend) {
final DeviceEntityDtoAbstract deviceDtoAbstract =
final DeviceEntityDtoBase deviceDtoAbstract =
DeviceHelper.convertDomainToDto(deviceEntityToSend);
HubRequestsToApp.streamRequestsToApp.sink.add(deviceDtoAbstract);
});
Expand Down Expand Up @@ -178,15 +177,15 @@ class AppCommunicationRepository extends IAppCommunicationRepository {
/// HubRequestsToApp stream
@override
Future<void> sendAllDevicesFromHubRequestsStream() async {
final Map<String, DeviceEntityAbstract> allDevices =
final Map<String, DeviceEntityBase> allDevices =
ISavedDevicesRepo.instance.getAllDevices();

final Map<String, RoomEntity> allRooms =
ISavedRoomsRepo.instance.getAllRooms();

if (allRooms.isEmpty) {
logger.w("Can't find smart devices in the local DB, sending empty");
final DeviceEntityAbstract emptyEntity = GenericEmptyDE.empty();
final DeviceEntityBase emptyEntity = GenericUnsupportedDE.empty();
HubRequestsToApp.streamRequestsToApp.sink
.add(emptyEntity.toInfrastructure());
return;
Expand All @@ -199,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));
});
Expand Down
4 changes: 2 additions & 2 deletions lib/infrastructure/app_communication/hub_app_server.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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/infrastructure/devices/helper_methods/device_helper_methods.dart';
import 'package:cbj_integrations_controller/domain/i_app_communication_repository.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';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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/saved_devices/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/domain/i_saved_devices_repo.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
Expand All @@ -29,20 +29,20 @@ class CbjWebServerRepository extends ICbjWebServerRepository {
final ISavedDevicesRepo savedDevicesRepo =
ISavedDevicesRepo.instance;

final Map<String, DeviceEntityAbstract> allDevices =
await savedDevicesRepo.getAllDevices();
final Map<String, DeviceEntityBase> allDevices =
savedDevicesRepo.getAllDevices();

DeviceEntityAbstract? deviceObjectOfDeviceId;
DeviceEntityBase? deviceObjectOfDeviceId;

for (final DeviceEntityAbstract d in allDevices.values) {
if (d.getDeviceId() == deviceId) {
for (final DeviceEntityBase d in allDevices.values) {
if (d.getCbjDeviceId == deviceId) {
deviceObjectOfDeviceId = d;
break;
}
}
if (deviceObjectOfDeviceId != null) {
final String requestedDeviceProperty = pathArgs[2];
final DeviceEntityDtoAbstract deviceEntityDtoAbstract =
final DeviceEntityDtoBase deviceEntityDtoAbstract =
deviceObjectOfDeviceId.toInfrastructure();
final Map<String, dynamic> deviceEntityJson =
deviceEntityDtoAbstract.toJson();
Expand Down
Loading

0 comments on commit e84b170

Please sign in to comment.