Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving vendors controll to the pacakge cbj_integrations_controller #324

Merged
merged 5 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
59 changes: 32 additions & 27 deletions bin/cbj_hub.dart
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
import 'dart:io';

import 'package:cbj_hub/application/boot_up/boot_up.dart';
import 'package:cbj_hub/domain/local_db/i_local_db_repository.dart';
import 'package:cbj_hub/infrastructure/shared_variables.dart';
import 'package:cbj_hub/infrastructure/system_commands/device_pin_manager.dart';
import 'package:cbj_hub/injection.dart';
import 'package:cbj_hub/utils.dart';
import 'package:network_tools/network_tools.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/bindings/binding_repository.dart';
import 'package:cbj_integrations_controller/infrastructure/local_db/local_db_hive_repository.dart';
import 'package:cbj_integrations_controller/infrastructure/node_red/node_red_repository.dart';
import 'package:cbj_integrations_controller/infrastructure/room/saved_rooms_repo.dart';
import 'package:cbj_integrations_controller/infrastructure/routines/routine_repository.dart';
import 'package:cbj_integrations_controller/infrastructure/saved_devices/saved_devices_repo.dart';
import 'package:cbj_integrations_controller/infrastructure/scenes/scene_repository.dart';
import 'package:cbj_integrations_controller/infrastructure/shared_variables.dart';
import 'package:cbj_integrations_controller/infrastructure/system_commands/system_commands_manager_d.dart';
import 'package:cbj_integrations_controller/initialize_integrations_controller.dart';
import 'package:cbj_integrations_controller/injection.dart';
import 'package:network_tools/network_tools.dart' as network;

Future<void> main(List<String> arguments) async {
setInstancesOfRepos();
// arguments[0] is the location of the project
configureNetworkTools('network_tools_db');
configureInjection(Env.prod);

try {
if (arguments.length > 1) {
await getIt<SharedVariables>().asyncConstractor(arguments[0]);
} else {
await getIt<SharedVariables>().asyncConstractor(Directory.current.path);
}
} catch (error) {
logger.w('Path/argument 1 is not specified\n$error');
}

// Setting device model and checking if configuration for this model exist
await DevicePinListManager().setPhysicalDeviceType();

await getIt<ILocalDbRepository>().initializeDb();

logger.t('');
network.configureNetworkTools('network_tools_db');
await initializeIntegrationsController(arguments: arguments, env: Env.devPc);

await BootUp.setup();
}

/// All instances of Repos
void setInstancesOfRepos() {
SystemCommandsManager();
MqttServerRepository();
CbjWebServerRepository();
SavedRoomsRepo();
SavedDevicesRepo();
RoutineCbjRepository();
HiveRepository();
NodeRedRepository();
BindingCbjRepository();
SceneCbjRepository();
SharedVariables();
}
40 changes: 6 additions & 34 deletions lib/application/boot_up/boot_up.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import 'package:cbj_hub/application/connector/connector.dart';
import 'package:cbj_hub/domain/cbj_web_server/i_cbj_web_server_repository.dart';
import 'package:cbj_hub/domain/generic_devices/abstract_device/device_entity_abstract.dart';
import 'package:cbj_hub/domain/mqtt_server/i_mqtt_server_repository.dart';
import 'package:cbj_hub/domain/rooms/i_saved_rooms_repo.dart';
import 'package:cbj_hub/domain/saved_devices/i_saved_devices_repo.dart';
import 'package:cbj_hub/domain/scene/i_scene_cbj_repository.dart';
import 'package:cbj_hub/infrastructure/devices/companies_connector_conjector.dart';
import 'package:cbj_hub/injection.dart';
import 'package:cbj_integrations_controller/domain/rooms/i_saved_rooms_repo.dart';
import 'package:cbj_integrations_controller/domain/scene/i_scene_cbj_repository.dart';
import 'package:cbj_integrations_controller/initialize_integrations_controller.dart';

class BootUp {
BootUp() {
Expand All @@ -15,34 +10,11 @@ class BootUp {

static Future<void> setup() async {
// Return all saved rooms
final ISavedRoomsRepo savedRoomsRepo = getIt<ISavedRoomsRepo>();
final ISceneCbjRepository savedScenesRepo = getIt<ISceneCbjRepository>();
await ISavedRoomsRepo.instance.getAllRooms();

await savedRoomsRepo.getAllRooms();
await ISceneCbjRepository.instance.getAllScenesAsMap();

await savedScenesRepo.getAllScenesAsMap();

// Return all saved devices
final ISavedDevicesRepo savedDevicesRepo = getIt<ISavedDevicesRepo>();

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

CompaniesConnectorConjector.addAllDevicesToItsRepos(allDevices);

CompaniesConnectorConjector.searchAllMdnsDevicesAndSetThemUp();

CompaniesConnectorConjector.searchPingableDevicesAndSetThemUpByHostName();

CompaniesConnectorConjector.searchDevicesByBindingIntoSockets();

CompaniesConnectorConjector.searchDevicesByMqttPath();

CompaniesConnectorConjector.notImplementedDevicesSearch();

await getIt<IMqttServerRepository>().asyncConstractor();

getIt<ICbjWebServerRepository>();
await setupIntegrationsController();

Connector.startConnector();
}
Expand Down
46 changes: 24 additions & 22 deletions lib/application/connector/connector.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import 'dart:async';
import 'dart:convert';

import 'package:cbj_hub/domain/app_communication/i_app_communication_repository.dart';
import 'package:cbj_hub/domain/generic_devices/abstract_device/device_entity_abstract.dart';
import 'package:cbj_hub/domain/mqtt_server/i_mqtt_server_repository.dart';
import 'package:cbj_hub/domain/room/room_entity.dart';
import 'package:cbj_hub/domain/room/value_objects_room.dart';
import 'package:cbj_hub/domain/rooms/i_saved_rooms_repo.dart';
import 'package:cbj_hub/domain/saved_devices/i_saved_devices_repo.dart';
import 'package:cbj_hub/infrastructure/app_communication/app_communication_repository.dart';
import 'package:cbj_hub/infrastructure/devices/companies_connector_conjector.dart';
import 'package:cbj_hub/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart';
import 'package:cbj_hub/infrastructure/generic_devices/abstract_device/device_entity_dto_abstract.dart';
import 'package:cbj_hub/injection.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/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_conjector.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/utils.dart';
import 'package:mqtt_client/mqtt_client.dart';
import 'package:rxdart/rxdart.dart';

Expand All @@ -24,7 +22,7 @@ class Connector {
/// Data will probably arrive to the function
/// updateAllDevicesReposWithDeviceChanges where we listen to request from
/// the mqtt with this path
await getIt<IMqttServerRepository>()
await IMqttServerRepository.instance
.publishDeviceEntity(entityForMqtt.value as DeviceEntityAbstract);
} else if (entityForMqtt.value is RoomEntity) {
// TODO: Create MQTT support for rooms
Expand All @@ -34,7 +32,7 @@ class Connector {
}
});

final ISavedDevicesRepo savedDevicesRepo = getIt<ISavedDevicesRepo>();
final ISavedDevicesRepo savedDevicesRepo = ISavedDevicesRepo.instance;

final Map<String, DeviceEntityAbstract> allDevices =
await savedDevicesRepo.getAllDevices();
Expand All @@ -48,13 +46,12 @@ class Connector {
}

Future.delayed(const Duration(milliseconds: 3000)).whenComplete(() {
// final IAppCommunicationRepository appCommunication =
getIt<IAppCommunicationRepository>();
AppCommunicationRepository();
});

getIt<IMqttServerRepository>().allHubDevicesSubscriptions();
IMqttServerRepository.instance.allHubDevicesSubscriptions();

getIt<IMqttServerRepository>().sendToApp();
IMqttServerRepository.instance.sendToApp();

CompaniesConnectorConjector.updateAllDevicesReposWithDeviceChanges(
ConnectorDevicesStreamFromMqtt.fromMqttStream,
Expand All @@ -68,7 +65,7 @@ class Connector {
static Future<void> updateDevicesFromMqttDeviceChange(
MapEntry<String, Map<String, dynamic>> deviceChangeFromMqtt,
) async {
final ISavedDevicesRepo savedDevicesRepo = getIt<ISavedDevicesRepo>();
final ISavedDevicesRepo savedDevicesRepo = ISavedDevicesRepo.instance;

final Map<String, DeviceEntityAbstract> allDevices =
await savedDevicesRepo.getAllDevices();
Expand Down Expand Up @@ -113,12 +110,17 @@ class Connector {
if (property == 'entityStateGRPC' &&
propertyValueString == EntityStateGRPC.ack.toString()) {
final Map<String, RoomEntity> rooms =
await getIt<ISavedRoomsRepo>().getAllRooms();
await ISavedRoomsRepo.instance.getAllRooms();

HubRequestsToApp.streamRequestsToApp.sink
.add(savedDeviceWithSameIdAsMqtt.toInfrastructure());
if (rooms[RoomUniqueId.discoveredRoomId().getOrCrash()]!
.roomDevicesId
final RoomEntity? discoverRoom =
rooms[RoomUniqueId.discoveredRoomId().getOrCrash()];
if (discoverRoom == null) {
continue;
}

if (discoverRoom.roomDevicesId
.getOrCrash()
.contains(savedDeviceWithSameIdAsMqtt.uniqueId.getOrCrash())) {
HubRequestsToApp.streamRequestsToApp.sink.add(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:cbj_hub/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart';
import 'package:cbj_integrations_controller/infrastructure/gen/cbj_hub_server/protoc_as_dart/cbj_hub_server.pbgrpc.dart';
import 'package:mqtt_client/mqtt_client.dart';

abstract class IAppCommunicationRepository {
static late IAppCommunicationRepository instance;

Future<void> getFromApp({
required Stream<ClientStatusRequests> request,
required String requestUrl,
Expand Down
61 changes: 0 additions & 61 deletions lib/domain/binding/binding_cbj_entity.dart

This file was deleted.

16 changes: 0 additions & 16 deletions lib/domain/binding/binding_cbj_errors.dart

This file was deleted.

38 changes: 0 additions & 38 deletions lib/domain/binding/binding_cbj_failures.dart

This file was deleted.

Loading