Skip to content

Commit

Permalink
Created core folder for cbj_integrations_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
guyluz11 committed Dec 9, 2023
1 parent 7d7e532 commit b591dfd
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion lib/domain/i_hub_connection_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import 'package:cbj_integrations_controller/domain/hub/hub_entity.dart';
import 'package:cbj_integrations_controller/domain/hub/hub_failures.dart';
import 'package:cbj_integrations_controller/domain/hub/hub_value_objects.dart';
import 'package:cbj_integrations_controller/domain/local_db/local_db_failures.dart';
import 'package:cbj_integrations_controller/infrastructure/core/utils.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/infrastructure/hub_client/hub_client_demo.dart';
import 'package:cbj_integrations_controller/infrastructure/hub_client/hub_dtos.dart';
import 'package:cbj_integrations_controller/utils.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:cybear_jinni/domain/i_local_db_repository.dart';
import 'package:cybear_jinni/infrastructure/core/injection.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/infrastructure/core/injection.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:cbj_integrations_controller/injection.config.dart';
import 'package:cbj_integrations_controller/infrastructure/core/injection.config.dart';
import 'package:cybear_jinni/infrastructure/core/logger.dart';
import 'package:get_it/get_it.dart';
import 'package:injectable/injectable.dart';
Expand Down
54 changes: 27 additions & 27 deletions lib/infrastructure/hub_client/hub_connection_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class _HubConnectionRepository implements IHubConnectionRepository {
try {
connectivityResult = await Connectivity().checkConnectivity();
} catch (e) {
logger.w('Cant check connectivity this is probably PC, error\n$e');
icLogger.w('Cant check connectivity this is probably PC, error\n$e');
}

// Last Number of bssid can change fix?, need to check if more numbers
Expand All @@ -56,7 +56,7 @@ class _HubConnectionRepository implements IHubConnectionRepository {
wifiBSSIDWithoutLastNumber =
wifiBSSID?.substring(0, wifiBSSID.lastIndexOf(':'));
} catch (e) {
logger.w("Can't get WiFi BSSID");
icLogger.w("Can't get WiFi BSSID");
}
final Either<LocalDbFailures, String> remotePipesInformation =
await ILocalDbRepository.instance.getRemotePipesDnsName();
Expand All @@ -78,14 +78,14 @@ class _HubConnectionRepository implements IHubConnectionRepository {
(kIsWeb && savedWifiBssidWithoutLastNumber == 'no:Network:Bssid')) {
(await openAndroidWifiSettingIfPossible()).fold(
(l) {
logger
icLogger
.w('No way to establish connection with the Hub, WiFi or location'
' permission is closed for here');
return;
},
(r) async {},
);
logger.i('Connect using direct connection to Hub');
icLogger.i('Connect using direct connection to Hub');

await connectDirectlyToHub();
return;
Expand Down Expand Up @@ -123,15 +123,15 @@ class _HubConnectionRepository implements IHubConnectionRepository {
networkName: hubNetworkName!,
).toDomain();
} catch (e) {
logger.e('Crashed while setting Hub info from local db\n$e');
icLogger.e('Crashed while setting Hub info from local db\n$e');
}
}

ConnectivityResult? connectivityResult;
try {
connectivityResult = await Connectivity().checkConnectivity();
} catch (e) {
logger.w('Cant check connectivity this is probably PC, error\n$e');
icLogger.w('Cant check connectivity this is probably PC, error\n$e');
}

// Last Number of bssid can change fix?, need to check if more numbers
Expand All @@ -155,7 +155,7 @@ class _HubConnectionRepository implements IHubConnectionRepository {
savedWifiBssidWithoutLastNumber != null &&
wifiBSSIDWithoutLastNumber != null &&
savedWifiBssidWithoutLastNumber == wifiBSSIDWithoutLastNumber) {
logger.i('Connect using direct connection to Hub');
icLogger.i('Connect using direct connection to Hub');

if (IHubConnectionRepository.hubEntity?.lastKnownIp.getOrCrash() !=
null) {
Expand Down Expand Up @@ -188,16 +188,16 @@ class _HubConnectionRepository implements IHubConnectionRepository {
}
return right(compHubInfo);
} catch (e) {
logger.e('Error getting hubInfo\n$e');
icLogger.e('Error getting hubInfo\n$e');
return left(const HubFailures.unexpected());
}

// return;
} else {
logger.i('Connect using Remote Pipes');
icLogger.i('Connect using Remote Pipes');
return (await ILocalDbRepository.instance.getRemotePipesDnsName()).fold(
(l) {
logger.e('Cant find local Remote Pipes Dns name');
icLogger.e('Cant find local Remote Pipes Dns name');
return left(const HubFailures.unexpected());
}, (r) async {
try {
Expand All @@ -209,7 +209,7 @@ class _HubConnectionRepository implements IHubConnectionRepository {
}
return right(compHubInfo);
} catch (e) {
logger.e('Error getting hubInfo\n$e');
icLogger.e('Error getting hubInfo\n$e');
return left(const HubFailures.unexpected());
}
});
Expand Down Expand Up @@ -247,7 +247,7 @@ class _HubConnectionRepository implements IHubConnectionRepository {
ResourceRecordQuery.addressIPv4(mDnsName),
)) {
deviceIp = record.address.address;
logger.i('Found address (${record.address}).');
icLogger.i('Found address (${record.address}).');
}

// await for (final IPAddressResourceRecord record
Expand All @@ -258,7 +258,7 @@ class _HubConnectionRepository implements IHubConnectionRepository {

client.stop();

logger.t('Done.');
icLogger.t('Done.');

return deviceIp;
}
Expand All @@ -276,7 +276,7 @@ class _HubConnectionRepository implements IHubConnectionRepository {
return locationRequest;
}

logger.i('searchForHub');
icLogger.i('searchForHub');

String? currentDeviceIP;
String? networkBSSID;
Expand Down Expand Up @@ -311,7 +311,7 @@ class _HubConnectionRepository implements IHubConnectionRepository {
final String subnet =
currentDeviceIP!.substring(0, currentDeviceIP.lastIndexOf('.'));

logger.i('Hub Search subnet IP $subnet');
icLogger.i('Hub Search subnet IP $subnet');

final Stream<ActiveHost> devicesWithPort =
HostScanner.scanDevicesForSinglePort(
Expand All @@ -324,7 +324,7 @@ class _HubConnectionRepository implements IHubConnectionRepository {
);

await for (final ActiveHost activeHost in devicesWithPort) {
logger.i('Found Cbj Hub device: ${activeHost.address}');
icLogger.i('Found Cbj Hub device: ${activeHost.address}');
if (networkBSSID != null && networkName != null) {
return insertHubInfo(
networkIp: activeHost.address,
Expand All @@ -334,15 +334,15 @@ class _HubConnectionRepository implements IHubConnectionRepository {
}
}
} catch (e) {
logger.w('Exception searchForHub\n$e');
icLogger.w('Exception searchForHub\n$e');
}
await Future.delayed(const Duration(seconds: 5));
return left(const HubFailures.cantFindHubInNetwork());
}

@override
Future<void> saveHubIP(String hubIP) async {
logger.w('saveHubIP');
icLogger.w('saveHubIP');
}

Future<Either<HubFailures, Unit>> askLocationPermissionAndLocationOn() async {
Expand All @@ -364,7 +364,7 @@ class _HubConnectionRepository implements IHubConnectionRepository {
if (permissionGranted == PermissionStatus.denied) {
permissionGranted = await location.requestPermission();
if (permissionGranted != PermissionStatus.granted) {
logger.e('Permission to use location is denied');
icLogger.e('Permission to use location is denied');
await Future.delayed(const Duration(seconds: 10));

permissionCounter++;
Expand All @@ -385,7 +385,7 @@ class _HubConnectionRepository implements IHubConnectionRepository {
if (disabledCounter > 2) {
return const Left(HubFailures.unexpected());
}
logger.w('Location is disabled');
icLogger.w('Location is disabled');
await Future.delayed(const Duration(seconds: 5));
continue;
}
Expand Down Expand Up @@ -416,8 +416,8 @@ class _HubConnectionRepository implements IHubConnectionRepository {
lastKnownIp: hubDtos.lastKnownIp,
))
.fold(
(l) => logger.e('Cant find local Remote Pipes Dns name'),
(r) => logger.i('Found CyBear Jinni Hub'),
(l) => icLogger.e('Cant find local Remote Pipes Dns name'),
(r) => icLogger.i('Found CyBear Jinni Hub'),
);
return right(unit);
}
Expand Down Expand Up @@ -453,7 +453,7 @@ class _HubConnectionRepository implements IHubConnectionRepository {
networkName: hubNetworkName!,
).toDomain();
} catch (e) {
logger.e('Crashed while setting Hub info from local db\n$e');
icLogger.e('Crashed while setting Hub info from local db\n$e');
}
}

Expand Down Expand Up @@ -504,7 +504,7 @@ class _HubConnectionRepository implements IHubConnectionRepository {
(l) async {
(await openAndroidWifiSettingIfPossible()).fold(
(l) {
logger.w(
icLogger.w(
'No way to establish connection with the Hub, WiFi or location'
' permission is closed');
},
Expand All @@ -514,7 +514,7 @@ class _HubConnectionRepository implements IHubConnectionRepository {
);
},
(r) {
logger.i('Connect using Remote Pipes');
icLogger.i('Connect using Remote Pipes');
HubClient.createStreamWithHub(r, 50056);
tryAgainConnectToTheHubOnceMore = 0;
},
Expand Down Expand Up @@ -552,7 +552,7 @@ class _HubConnectionRepository implements IHubConnectionRepository {
// }
// }
} else {
logger.w(
icLogger.w(
'Will ask the user to open WiFi and gps to try local connection',
);
final bool wifiEnabled = await WiFiForIoTPlugin.isEnabled();
Expand All @@ -564,7 +564,7 @@ class _HubConnectionRepository implements IHubConnectionRepository {
}

(await askLocationPermissionAndLocationOn()).fold((l) {
logger.e(
icLogger.e(
'User does not allow opening location and does not have remote pipes info',
);
}, (r) async {
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'dart:io';

import 'package:cbj_integrations_controller/domain/i_saved_devices_repo.dart';
import 'package:cbj_integrations_controller/domain/local_db/i_local_devices_db_repository.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/system_commands/system_commands_manager_d.dart';
import 'package:cbj_integrations_controller/injection.dart';
import 'package:cbj_smart_device_flutter/commands/flutter_commands.dart';
import 'package:cybear_jinni/domain/i_local_db_repository.dart';
import 'package:cybear_jinni/domain/i_notification_service.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:another_flushbar/flushbar_helper.dart';
import 'package:cbj_integrations_controller/infrastructure/core/utils.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_devices/abstract_device/value_objects_core.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart';
import 'package:cbj_integrations_controller/utils.dart';
import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart';
import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_failures.dart';
import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_value_objects.dart';
Expand Down Expand Up @@ -63,7 +63,7 @@ class _ComputerConnectionCheckWidgetState
}

bool isConnectedToWifi = false;
logger.i('Waiting for user to get connected to WiFi');
icLogger.i('Waiting for user to get connected to WiFi');

while (true) {
isConnectedToWifi = await WiFiForIoTPlugin.isConnected();
Expand Down Expand Up @@ -126,7 +126,7 @@ class _ComputerConnectionCheckWidgetState
deviceE..cbjEntityName = CbjEntityName(deviceName),
);
} catch (e) {
logger.w("Can't add unsupported device");
icLogger.w("Can't add unsupported device");
}
});
final CBJCompEntity compUpdatedData = cbjCompEntity.copyWith(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:auto_route/auto_route.dart';
import 'package:cbj_integrations_controller/infrastructure/core/utils.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/value_objects_core.dart';
import 'package:cbj_integrations_controller/infrastructure/generic_devices/generic_light_device/generic_light_entity.dart';
import 'package:cbj_integrations_controller/utils.dart';
import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_entity.dart';
import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_failures.dart';
import 'package:cybear_jinni/domain/cbj_comp/cbj_comp_value_objects.dart';
Expand Down Expand Up @@ -115,7 +115,7 @@ class _ConfigureNewCbjCompWidgetsState
deviceE..cbjEntityName = CbjEntityName(deviceName),
);
} catch (e) {
logger.w("Can't add unsupported device");
icLogger.w("Can't add unsupported device");
}
});
final CBJCompEntity compUpdatedData = cbjCompEntity.copyWith(
Expand Down

0 comments on commit b591dfd

Please sign in to comment.