Skip to content

Commit

Permalink
Merge pull request #326 from CyBear-Jinni/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
guyluz11 authored Nov 10, 2023
2 parents 762de4a + 7e4abf8 commit fe6556b
Show file tree
Hide file tree
Showing 350 changed files with 198 additions and 43,222 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,7 @@ saved_cast_state.json
lib/infrastructure/core/constant_credentials.dart

# Web related
lib/generated_plugin_registrant.dart
lib/generated_plugin_registrant.dart

# Network tools
network_tools_db/*
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,3 @@ linter:
avoid_classes_with_only_static_members: false

sort_constructors_first: true

# Good packages document everything
public_member_api_docs: true
59 changes: 36 additions & 23 deletions bin/cbj_hub.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
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: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';

Future<void> main(List<String> arguments) async {
// arguments[0] is the location of the project
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();
configureNetworkTools('network_tools_db');

logger.v('');
setInstancesOfRepos(arguments.firstOrNull ?? Directory.current.path);
// arguments[0] is the location of the project
await initializeIntegrationsController(
projectRootDirectoryPath: arguments.firstOrNull ?? Directory.current.path,
env: Env.devPc,
);

await BootUp.setup();
}

/// All instances of Repos
void setInstancesOfRepos(String projectRootDirectoryPath) {
SystemCommandsManager();
MqttServerRepository();
CbjWebServerRepository();
SavedRoomsRepo();
SavedDevicesRepo();
RoutineCbjRepository();
HiveRepository();
NodeRedRepository();
BindingCbjRepository();
SceneCbjRepository();
SharedVariables(projectRootDirectoryPath);
}
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

0 comments on commit fe6556b

Please sign in to comment.