From 42321d5c64beb38c810b751dd52bdc47e6f7bf0d Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Tue, 30 Jan 2024 01:40:57 +0200 Subject: [PATCH 1/4] Fix changing color slider does not move --- android/app/src/main/AndroidManifest.xml | 1 + lib/domain/connections_service.dart | 1 + .../network_utilities_flutter.dart | 4 +++- .../molecules/devices/rgb_light_molecule.dart | 20 ++++--------------- .../computer_connection_check_widget.dart | 2 +- .../configure_new_cbj_comp_widget.dart | 2 +- 6 files changed, 11 insertions(+), 19 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 6e88767c..020e5df0 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -19,6 +19,7 @@ + network_flutter.HostScannerFlutter.getAllPingableDevices( subnet, - firstHostId: 127, + firstHostId: firstHostId ?? HostScanner.defaultFirstHostId, + lastHostId: lastHostId ?? HostScanner.defaultLastHostId, ); @override diff --git a/lib/presentation/molecules/devices/rgb_light_molecule.dart b/lib/presentation/molecules/devices/rgb_light_molecule.dart index c8539aa4..ae78e220 100644 --- a/lib/presentation/molecules/devices/rgb_light_molecule.dart +++ b/lib/presentation/molecules/devices/rgb_light_molecule.dart @@ -161,7 +161,6 @@ class _LightColorMods extends State { late HSVColor hsvColor; late double brightness; late ColorMode colorMode; - late Widget colorModeWidget; @override void initState() { @@ -170,7 +169,6 @@ class _LightColorMods extends State { hsvColor = widget.hsvColor ?? HSVColor.fromColor(Colors.white); colorTemperature = widget.colorTemperature; brightness = widget.brightness; - colorModeWidget = getColorModeWidget(colorMode); _initialized(); } @@ -283,22 +281,9 @@ class _LightColorMods extends State { ); } - Widget getColorModeWidget(ColorMode colorMode) { - switch (colorMode) { - case ColorMode.undefined: - return const SizedBox(); - case ColorMode.rgb: - return getHsvColorModeWidget(); - case ColorMode.white: - return getWhiteModeWidget(); - } - } - void setColorModeState(ColorMode colorMode) { - final Widget colorModeWidget = getColorModeWidget(colorMode); setState(() { this.colorMode = colorMode; - this.colorModeWidget = colorModeWidget; }); } @@ -309,7 +294,10 @@ class _LightColorMods extends State { return Column( children: [ - colorModeWidget, + if (colorMode == ColorMode.white) + getHsvColorModeWidget() + else if (colorMode == ColorMode.rgb) + getWhiteModeWidget(), const SeparatorAtom(variant: SeparatorVariant.reletedElements), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, diff --git a/lib/presentation/pages/add_new_devices_process/computer_connection_check/widgets/computer_connection_check_widget.dart b/lib/presentation/pages/add_new_devices_process/computer_connection_check/widgets/computer_connection_check_widget.dart index 6131c0e5..1b4237ce 100644 --- a/lib/presentation/pages/add_new_devices_process/computer_connection_check/widgets/computer_connection_check_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/computer_connection_check/widgets/computer_connection_check_widget.dart @@ -122,7 +122,7 @@ class _ComputerConnectionCheckWidgetState '$deviceNameFieldKey/${deviceE.uniqueId.getOrCrash()}']! .text; deviceEntityList.add( - deviceE..cbjEntityName = CbjEntityName(deviceName), + deviceE..cbjEntityName = CbjEntityName(value: deviceName), ); } catch (e) { logger.w("Can't add unsupported device"); diff --git a/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart b/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart index d22b8324..59efb79f 100644 --- a/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/configure_new_cbj_comp/widgets/configure_new_cbj_comp_widget.dart @@ -110,7 +110,7 @@ class _ConfigureNewCbjCompWidgetsState '$deviceNameFieldKey/${deviceE.uniqueId.getOrCrash()}']! .text; deviceEntityList.add( - deviceE..cbjEntityName = CbjEntityName(deviceName), + deviceE..cbjEntityName = CbjEntityName(value: deviceName), ); } catch (e) { logger.w("Can't add unsupported device"); From 9c1429419c5e97010131d228eee90c05e092ce97 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Wed, 31 Jan 2024 15:50:41 +0200 Subject: [PATCH 2/4] Starting working on db --- lib/domain/connections_service.dart | 1 - lib/domain/i_local_db_repository.dart | 34 ----- .../i_manage_network_repository.dart | 4 + lib/infrastructure/app_commands.dart | 16 +- .../isar_objects/home_entity_isar_model.dart | 10 -- .../isar_objects/hub_entity_isar_model.dart | 12 -- .../isar_objects/remote_pipes_isar_model.dart | 10 -- .../isar_local_db/isar_repository.dart | 137 ------------------ .../manage_wifi_repository.dart | 60 ++++++++ lib/infrastructure/mqtt.dart | 4 - lib/presentation/pages/splash_page.dart | 25 +--- 11 files changed, 78 insertions(+), 235 deletions(-) delete mode 100644 lib/domain/i_local_db_repository.dart delete mode 100644 lib/infrastructure/isar_local_db/isar_objects/home_entity_isar_model.dart delete mode 100644 lib/infrastructure/isar_local_db/isar_objects/hub_entity_isar_model.dart delete mode 100644 lib/infrastructure/isar_local_db/isar_objects/remote_pipes_isar_model.dart delete mode 100644 lib/infrastructure/isar_local_db/isar_repository.dart diff --git a/lib/domain/connections_service.dart b/lib/domain/connections_service.dart index f077a512..05e55b68 100644 --- a/lib/domain/connections_service.dart +++ b/lib/domain/connections_service.dart @@ -10,7 +10,6 @@ import 'package:cybearjinni/infrastructure/core/logger.dart'; import 'package:cybearjinni/infrastructure/network_utilities_flutter.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/foundation.dart'; -import 'package:flutter/services.dart'; import 'package:grpc/grpc.dart'; import 'package:location/location.dart'; import 'package:network_info_plus/network_info_plus.dart'; diff --git a/lib/domain/i_local_db_repository.dart b/lib/domain/i_local_db_repository.dart deleted file mode 100644 index af328350..00000000 --- a/lib/domain/i_local_db_repository.dart +++ /dev/null @@ -1,34 +0,0 @@ -import 'package:cbj_integrations_controller/integrations_controller.dart'; -import 'package:cybearjinni/infrastructure/core/logger.dart'; -import 'package:cybearjinni/infrastructure/isar_local_db/isar_objects/home_entity_isar_model.dart'; -import 'package:cybearjinni/infrastructure/isar_local_db/isar_objects/hub_entity_isar_model.dart'; -import 'package:cybearjinni/infrastructure/isar_local_db/isar_objects/remote_pipes_isar_model.dart'; -import 'package:dartz/dartz.dart'; -import 'package:isar/isar.dart'; -import 'package:path_provider/path_provider.dart'; - -part 'package:cybearjinni/infrastructure/isar_local_db/isar_repository.dart'; - -abstract interface class ILocalDbRepository { - static ILocalDbRepository? _instance; - - static ILocalDbRepository get instance { - return _instance ??= _IsarRepository(); - } - - Future asyncConstructor(); - - Future> saveHubEntity({ - required String hubNetworkBssid, - required String networkName, - required String lastKnownIp, - }); - - Future> getRemotePipesDnsName(); - - Future> getHubEntityNetworkBssid(); - - Future> getHubEntityNetworkName(); - - Future> getHubEntityLastKnownIp(); -} diff --git a/lib/domain/manage_network/i_manage_network_repository.dart b/lib/domain/manage_network/i_manage_network_repository.dart index a5207c97..29fb092f 100644 --- a/lib/domain/manage_network/i_manage_network_repository.dart +++ b/lib/domain/manage_network/i_manage_network_repository.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:cbj_integrations_controller/integrations_controller.dart'; import 'package:cybearjinni/domain/home_user/home_user_failures.dart'; import 'package:cybearjinni/domain/manage_network/manage_network_entity.dart'; import 'package:cybearjinni/domain/manage_network/manage_network_value_objects.dart'; @@ -7,6 +8,7 @@ import 'package:cybearjinni/infrastructure/core/logger.dart'; import 'package:dartz/dartz.dart'; import 'package:flutter/services.dart'; import 'package:kt_dart/collection.dart'; +import 'package:location/location.dart' as location; import 'package:network_info_plus/network_info_plus.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:wifi_iot/wifi_iot.dart'; @@ -22,6 +24,8 @@ abstract interface class IManageNetworkRepository { static ManageNetworkEntity? manageWiFiEntity; + Future loadWifi(); + Future> doesWiFiEnabled(); Stream>> diff --git a/lib/infrastructure/app_commands.dart b/lib/infrastructure/app_commands.dart index b92ee6cc..d89682c2 100644 --- a/lib/infrastructure/app_commands.dart +++ b/lib/infrastructure/app_commands.dart @@ -4,11 +4,7 @@ import 'package:cbj_integrations_controller/integrations_controller.dart'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:path_provider/path_provider.dart'; -class AppCommands implements IPhoneCommandsD { - AppCommands() { - IPhoneCommandsD.instance = this; - } - +class AppCommands extends SystemCommandsBaseClassD { @override Future getAllEtcReleaseFilesText() { // TODO: implement getAllEtcReleaseFilesText @@ -62,7 +58,7 @@ class AppCommands implements IPhoneCommandsD { } @override - Future getLocalDbPath(Future currentUserName) async { + Future getLocalDbPath() async { final Directory appDocDirectory = await getApplicationDocumentsDirectory(); return appDocDirectory.path; } @@ -86,8 +82,8 @@ class AppCommands implements IPhoneCommandsD { } @override - Future suspendComputer() { - // TODO: implement suspendComputer - throw UnimplementedError(); - } + Future suspendComputer() async => null; + + @override + Future getRaspberryPiDeviceVersion() async => null; } diff --git a/lib/infrastructure/isar_local_db/isar_objects/home_entity_isar_model.dart b/lib/infrastructure/isar_local_db/isar_objects/home_entity_isar_model.dart deleted file mode 100644 index d56475dd..00000000 --- a/lib/infrastructure/isar_local_db/isar_objects/home_entity_isar_model.dart +++ /dev/null @@ -1,10 +0,0 @@ -import 'package:isar/isar.dart'; - -part 'home_entity_isar_model.g.dart'; - -@collection -class HomeEntityIsarModel { - Id id = Isar.autoIncrement; - - late String homeId; -} diff --git a/lib/infrastructure/isar_local_db/isar_objects/hub_entity_isar_model.dart b/lib/infrastructure/isar_local_db/isar_objects/hub_entity_isar_model.dart deleted file mode 100644 index f3fbd788..00000000 --- a/lib/infrastructure/isar_local_db/isar_objects/hub_entity_isar_model.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:isar/isar.dart'; - -part 'hub_entity_isar_model.g.dart'; - -@collection -class HubEntityIsarModel { - Id id = Isar.autoIncrement; - - late String hubNetworkBssid; - late String networkName; - late String lastKnownIp; -} diff --git a/lib/infrastructure/isar_local_db/isar_objects/remote_pipes_isar_model.dart b/lib/infrastructure/isar_local_db/isar_objects/remote_pipes_isar_model.dart deleted file mode 100644 index 8b094470..00000000 --- a/lib/infrastructure/isar_local_db/isar_objects/remote_pipes_isar_model.dart +++ /dev/null @@ -1,10 +0,0 @@ -import 'package:isar/isar.dart'; - -part 'remote_pipes_isar_model.g.dart'; - -@collection -class RemotePipesIsarModel { - Id id = Isar.autoIncrement; - - late String domainName; -} diff --git a/lib/infrastructure/isar_local_db/isar_repository.dart b/lib/infrastructure/isar_local_db/isar_repository.dart deleted file mode 100644 index 127a9175..00000000 --- a/lib/infrastructure/isar_local_db/isar_repository.dart +++ /dev/null @@ -1,137 +0,0 @@ -part of 'package:cybearjinni/domain/i_local_db_repository.dart'; - -class _IsarRepository implements ILocalDbRepository { - late Isar isar; - @override - Future asyncConstructor() async { - final dir = await getApplicationDocumentsDirectory(); - isar = await Isar.open( - [ - RemotePipesIsarModelSchema, - HubEntityIsarModelSchema, - HomeEntityIsarModelSchema, - ], - directory: dir.path, - ); - } - - @override - Future> saveHubEntity({ - required String hubNetworkBssid, - required String networkName, - required String lastKnownIp, - }) async { - try { - final HubEntityIsarModel hubEntityIsarModel = HubEntityIsarModel() - ..hubNetworkBssid = hubNetworkBssid - ..networkName = networkName - ..lastKnownIp = lastKnownIp; - - await isar.writeTxn(() async { - await isar.hubEntityIsarModels.clear(); - await isar.hubEntityIsarModels.put(hubEntityIsarModel); - }); - - logger.i('Hub entity got saved to local storage'); - } catch (e) { - logger.e('Error saving Hub entity to local storage: $e'); - - return left(const LocalDbFailures.unexpected()); - } - return right(unit); - } - - @override - Future> getRemotePipesDnsName() async { - try { - final List remotePipesIsarModelFromDb = - await isar.remotePipesIsarModels.where().findAll(); - - if (remotePipesIsarModelFromDb.isNotEmpty) { - final String remotePipesDnsName = - remotePipesIsarModelFromDb[0].domainName; - logger.i( - 'Remote pipes domain name is: ' - '${remotePipesIsarModelFromDb[0].domainName}', - ); - - return right(remotePipesDnsName); - } - - logger.i("Didn't find any remote pipes in the local DB"); - } catch (e) { - logger.e('Local DB isar getRemotePipesDnsName error: $e'); - } - return left(const LocalDbFailures.unexpected()); - } - - @override - Future> getHubEntityLastKnownIp() async { - try { - final List hubEntityIsarModelFromDb = - await isar.hubEntityIsarModels.where().findAll(); - - if (hubEntityIsarModelFromDb.isNotEmpty) { - final String hubLastKnownIp = hubEntityIsarModelFromDb[0].lastKnownIp; - logger.i( - 'Hub entity lastKnownIp is: ' - '${hubEntityIsarModelFromDb[0].lastKnownIp}', - ); - - return right(hubLastKnownIp); - } - - logger.i("Didn't find any Hub entity in the local DB"); - } catch (e) { - logger.e('Local DB isar getHubEntityLastKnownIp error: $e'); - } - return left(const LocalDbFailures.unexpected()); - } - - @override - Future> getHubEntityNetworkBssid() async { - try { - final List hubEntityIsarModelFromDb = - await isar.hubEntityIsarModels.where().findAll(); - - if (hubEntityIsarModelFromDb.isNotEmpty) { - final String hubNetworkBssid = - hubEntityIsarModelFromDb[0].hubNetworkBssid; - logger.i( - 'Hub entity network bssid is: ' - '${hubEntityIsarModelFromDb[0].hubNetworkBssid}', - ); - - return right(hubNetworkBssid); - } - - logger.i("Didn't find any Hub entity in the local DB"); - } catch (e) { - logger.e('Local DB isar getHubEntityNetworkBssid error: $e'); - } - return left(const LocalDbFailures.unexpected()); - } - - @override - Future> getHubEntityNetworkName() async { - try { - final List hubEntityIsarModelFromDb = - await isar.hubEntityIsarModels.where().findAll(); - - if (hubEntityIsarModelFromDb.isNotEmpty) { - final String hubNetworkName = hubEntityIsarModelFromDb[0].networkName; - logger.i( - 'Hub entity network name is: ' - '${hubEntityIsarModelFromDb[0].networkName}', - ); - - return right(hubNetworkName); - } - - logger.i("Didn't find any Hub entity in the local DB"); - } catch (e) { - logger.e('Local DB isar getHubEntityNetworkName error: $e'); - } - return left(const LocalDbFailures.unexpected()); - } -} diff --git a/lib/infrastructure/manage_wifi_repository.dart b/lib/infrastructure/manage_wifi_repository.dart index 6dd1e6ae..ec716c99 100644 --- a/lib/infrastructure/manage_wifi_repository.dart +++ b/lib/infrastructure/manage_wifi_repository.dart @@ -2,6 +2,7 @@ part of 'package:cybearjinni/domain/manage_network/i_manage_network_repository.d class _ManageWiFiRepository implements IManageNetworkRepository { final NetworkSecurity networkSecurity = NetworkSecurity.WPA; + NetworkObject? network; @override Future> doesWiFiEnabled() async { @@ -125,4 +126,63 @@ class _ManageWiFiRepository implements IManageNetworkRepository { } return wifiName; } + + @override + Future loadWifi() async { + // TODO: Get bssid + final NetworkInfo info = NetworkInfo(); + final PermissionStatus locationStatus = await Permission.location.status; + if (locationStatus.isDenied) { + await Permission.locationWhenInUse.request(); + } + if (await Permission.location.isRestricted) { + await openAppSettings(); + } + + final bool isWifiEnabled = await WiFiForIoTPlugin.isEnabled(); + final bool isWifiConnected = await WiFiForIoTPlugin.isConnected(); + + if (!isWifiEnabled || !isWifiConnected) { + logger.w('Not connected to WiFi'); + exit(0); + } + String bssid; + if (await Permission.location.isGranted) { + final String? bssidTemp = await info.getWifiBSSID(); + if (bssidTemp == null || bssidTemp == "02:00:00:00:00:00") { + logger.w( + 'Location is not on or user-allowed approximate location instead of precise location', + ); + exit(0); + } + bssid = bssidTemp; + } else { + logger.w('Missing location permission'); + exit(0); + } + final String? ssid = await WiFiForIoTPlugin.getSSID(); + final List? ipSplit = (await WiFiForIoTPlugin.getIP())?.split('.'); + String? subNet; + if (ipSplit != null) { + subNet = ipSplit.sublist(0, ipSplit.length - 1).join(); + } + final location.LocationData locationData = + await location.Location().getLocation(); + if (ssid == null || subNet == null) { + logger.w('Ssid or subnet is null'); + exit(0); + } + + final NetworkObject network = NetworkObject( + bssid: bssid, + ssid: ssid, + subNet: subNet, + longitude: locationData.longitude, + latitude: locationData.latitude, + remotePipe: null, + type: null, + ); + NetworksManager().addNetwork(network); + NetworksManager().setCurrentNetwork(network.uniqueId); + } } diff --git a/lib/infrastructure/mqtt.dart b/lib/infrastructure/mqtt.dart index 27a67a14..e0541a15 100644 --- a/lib/infrastructure/mqtt.dart +++ b/lib/infrastructure/mqtt.dart @@ -69,10 +69,6 @@ class MqttServerRepository extends IMqttServerRepository { final DeviceEntityBase deviceEntityBase = entityFromTheApp.toDomain(); deviceEntityBase.entityStateGRPC = EntityState.state(EntityStateGRPC.waitingInComp); - - /// Sends directly to device connector conjecture - // ISavedDevicesRepo.instance.addOrUpdateFromMqtt(deviceEntityBase); - return; } else if (entityFromTheApp is DeviceEntityBase) { entityFromTheApp.entityStateGRPC = diff --git a/lib/presentation/pages/splash_page.dart b/lib/presentation/pages/splash_page.dart index 6c528ec6..7ec2d5c5 100644 --- a/lib/presentation/pages/splash_page.dart +++ b/lib/presentation/pages/splash_page.dart @@ -2,9 +2,8 @@ import 'dart:io'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/integrations_controller.dart'; -import 'package:cbj_smart_device_flutter/commands/flutter_commands.dart'; import 'package:cybearjinni/domain/connections_service.dart'; -import 'package:cybearjinni/domain/i_local_db_repository.dart'; +import 'package:cybearjinni/domain/manage_network/i_manage_network_repository.dart'; import 'package:cybearjinni/infrastructure/app_commands.dart'; import 'package:cybearjinni/infrastructure/mqtt.dart'; import 'package:cybearjinni/presentation/atoms/atoms.dart'; @@ -28,24 +27,16 @@ class _SplashPageState extends State { } Future initilizeApp() async { - // TODO: can we remove + SystemCommandsBaseClassD.instance = AppCommands(); await Hive.initFlutter(); - AppCommands(); - // TODO: can we remove - await Future.value([ - IDbRepository.instance.initializeDb(isFlutter: true), - ILocalDbRepository.instance.asyncConstructor(), - // ISavedDevicesRepo.instance.setUpAllFromDb(), - ]); - // TODO: can we remove + IcSynchronizer.initializeIntegrationsController(); + await IManageNetworkRepository.instance.loadWifi(); + ConnectionsService.setCurrentConnectionType(ConnectionType.appAsHub); + _navigate(); + + // TODO: Only here so that app will not crash MqttServerRepository(); - // TODO: Same as App Command? - PhoneCommandsD(); - SystemCommandsManager(); - // TODO: can we remove NodeRedRepository(); - ConnectionsService.instance; - _navigate(); } void _navigate() { From df38738bc6b26c52f8beb79e3386ae3fbf9ca8e8 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Fri, 2 Feb 2024 13:38:45 +0200 Subject: [PATCH 3/4] Added db support --- devtools_options.yaml | 1 + lib/domain/connections_service.dart | 17 ++++--- .../app_connection_service.dart | 18 ++++---- .../demo_connection_service.dart | 4 ++ .../hub_connection_service.dart | 6 +-- .../remote_pipes_connection_service.dart | 5 ++- .../manage_wifi_repository.dart | 45 +++++++++++++++---- .../molecules/devices/ac_molecule.dart | 2 +- .../molecules/devices/blind_molecule.dart | 2 +- .../molecules/devices/boiler_molecule.dart | 2 +- .../devices/dimmable_light_molecule.dart | 2 +- .../devices/light_card_molecule.dart | 4 +- .../molecules/devices/light_molecule.dart | 2 +- .../molecules/devices/rgb_light_molecule.dart | 4 +- .../devices/smart_computer_molecule.dart | 4 +- .../devices/smart_plug_molecule.dart | 2 +- .../molecules/devices/smart_tv_molecule.dart | 2 +- .../molecules/devices/switch_molecule.dart | 2 +- lib/presentation/pages/add_action_page.dart | 2 +- .../{add_bindings => }/add_binding_page.dart | 22 ++++++--- .../widgets/binding_action_widget.dart | 45 ------------------- .../widgets/routine_action_widget.dart | 45 ------------------- .../{add_routine => }/add_routine_page.dart | 25 ++++++++--- .../widgets/scene_action_widget.dart | 45 ------------------- .../pages/{add_scene => }/add_scene_page.dart | 24 +++++++--- .../pages/change_area_for_devices_page.dart | 2 +- .../pages/comunication_method_page.dart | 15 +++++-- .../widgets/cbj_hub_in_network_widget.dart | 11 ++++- .../pages/connect_to_hub_more_page.dart | 13 +++++- .../pages/entities_in_area_page.dart | 2 +- .../pages/home_page/home_page.dart | 32 ++++++++----- lib/presentation/pages/pages.dart | 8 ++-- lib/presentation/pages/plus_button.dart | 12 ++++- lib/presentation/pages/remote_pipes_page.dart | 12 ++++- .../pages/{scenes => }/scenes_page.dart | 6 +-- lib/presentation/pages/splash_page.dart | 32 +++++++++++-- 36 files changed, 248 insertions(+), 229 deletions(-) create mode 100644 devtools_options.yaml rename lib/presentation/pages/{add_bindings => }/add_binding_page.dart (89%) delete mode 100644 lib/presentation/pages/add_bindings/widgets/binding_action_widget.dart delete mode 100644 lib/presentation/pages/add_routine/widgets/routine_action_widget.dart rename lib/presentation/pages/{add_routine => }/add_routine_page.dart (89%) delete mode 100644 lib/presentation/pages/add_scene/widgets/scene_action_widget.dart rename lib/presentation/pages/{add_scene => }/add_scene_page.dart (90%) rename lib/presentation/pages/{scenes => }/scenes_page.dart (96%) diff --git a/devtools_options.yaml b/devtools_options.yaml new file mode 100644 index 00000000..7e7e7f67 --- /dev/null +++ b/devtools_options.yaml @@ -0,0 +1 @@ +extensions: diff --git a/lib/domain/connections_service.dart b/lib/domain/connections_service.dart index 05e55b68..69cc0023 100644 --- a/lib/domain/connections_service.dart +++ b/lib/domain/connections_service.dart @@ -37,12 +37,15 @@ abstract interface class ConnectionsService { static ConnectionsService? _instance; static ConnectionsService get instance { - return _instance ??= _AppConnectionService(); + return _instance ??= _NoneConnectionService(); } - static ConnectionType _currentConnectionType = ConnectionType.appAsHub; + static ConnectionType _currentConnectionType = ConnectionType.none; - static void setCurrentConnectionType(ConnectionType connectionType) { + static void setCurrentConnectionType({ + required String networkBssid, + required ConnectionType connectionType, + }) { if (connectionType == _currentConnectionType) { return; } @@ -52,13 +55,13 @@ abstract interface class ConnectionsService { switch (connectionType) { case ConnectionType.appAsHub: - _instance = _AppConnectionService(); + _instance = _AppConnectionService(networkBssid); case ConnectionType.hub: - _instance = _HubConnectionService(); + _instance = _HubConnectionService(networkBssid); case ConnectionType.remotePipes: - _instance = _RemotePipesConnectionService(); + _instance = _RemotePipesConnectionService(networkBssid); case ConnectionType.demo: - _instance = _DemoConnectionService(); + _instance = _DemoConnectionService(networkBssid); case ConnectionType.none: _instance = _NoneConnectionService(); } diff --git a/lib/infrastructure/connection_service/app_connection_service.dart b/lib/infrastructure/connection_service/app_connection_service.dart index dc042a96..39683f07 100644 --- a/lib/infrastructure/connection_service/app_connection_service.dart +++ b/lib/infrastructure/connection_service/app_connection_service.dart @@ -1,12 +1,10 @@ part of 'package:cybearjinni/domain/connections_service.dart'; class _AppConnectionService implements ConnectionsService { - _AppConnectionService() { - searchDevicesInstance = SearchDevices(); - searchDevices(); - } + _AppConnectionService(this.networkBssid); - late SearchDevices searchDevicesInstance; + String networkBssid; + SearchDevices? searchDevicesInstance; @override Future> get getEntities async => @@ -17,8 +15,12 @@ class _AppConnectionService implements ConnectionsService { IcSynchronizer().getAreas(); @override - Future searchDevices() => - searchDevicesInstance.startSearchIsolate(NetworkUtilitiesFlutter()); + Future searchDevices() async => + searchDevicesInstance = (searchDevicesInstance ?? SearchDevices()) + ..startSearchIsolate( + networkUtilitiesType: NetworkUtilitiesFlutter(), + systemCommands: SystemCommandsBaseClassD.instance, + ); @override Stream> watchEntities() => @@ -33,7 +35,7 @@ class _AppConnectionService implements ConnectionsService { IcSynchronizer().setEntitiesState(action); @override - Future dispose() async => searchDevicesInstance.dispose(); + Future dispose() async => searchDevicesInstance?.dispose(); @override Future setNewArea(AreaEntity area) async { diff --git a/lib/infrastructure/connection_service/demo_connection_service.dart b/lib/infrastructure/connection_service/demo_connection_service.dart index b0f17dda..e3a87c1a 100644 --- a/lib/infrastructure/connection_service/demo_connection_service.dart +++ b/lib/infrastructure/connection_service/demo_connection_service.dart @@ -1,6 +1,10 @@ part of 'package:cybearjinni/domain/connections_service.dart'; class _DemoConnectionService implements ConnectionsService { + _DemoConnectionService(this.networkBssid); + + String networkBssid; + StreamController>? entitiesStream; StreamController>? areasStream; diff --git a/lib/infrastructure/connection_service/hub_connection_service.dart b/lib/infrastructure/connection_service/hub_connection_service.dart index 70bb08be..6b115813 100644 --- a/lib/infrastructure/connection_service/hub_connection_service.dart +++ b/lib/infrastructure/connection_service/hub_connection_service.dart @@ -1,7 +1,7 @@ part of 'package:cybearjinni/domain/connections_service.dart'; class _HubConnectionService implements ConnectionsService { - _HubConnectionService() { + _HubConnectionService(this.networkBssid) { if (currentEnvApp == EnvApp.prod) { hubPort = 50055; } else { @@ -9,12 +9,13 @@ class _HubConnectionService implements ConnectionsService { } } + String networkBssid; + /// Port to connect to the cbj hub, will change according to the current /// running environment late int hubPort; String? hubIp; - String? networkBssid; String? networkName; ClientChannel? channel; @@ -166,7 +167,6 @@ class _HubConnectionService implements ConnectionsService { final NetworkInfo networkInfo = NetworkInfo(); networkName = await networkInfo.getWifiName(); appDeviceIp = await networkInfo.getWifiIP(); - networkBssid = await networkInfo.getWifiBSSID(); } else { return false; // if (deviceIpOnTheNetwork == null) { diff --git a/lib/infrastructure/connection_service/remote_pipes_connection_service.dart b/lib/infrastructure/connection_service/remote_pipes_connection_service.dart index 3b092073..f39203aa 100644 --- a/lib/infrastructure/connection_service/remote_pipes_connection_service.dart +++ b/lib/infrastructure/connection_service/remote_pipes_connection_service.dart @@ -1,13 +1,14 @@ part of 'package:cybearjinni/domain/connections_service.dart'; class _RemotePipesConnectionService implements ConnectionsService { + _RemotePipesConnectionService(this.networkBssid); + /// Port to connect to the cbj hub, will change according to the current /// running environment int hubPort = 50051; String? address; - String? networkBssid; - String? networkName; + String networkBssid; ClientChannel? channel; CbjHubClient? stub; diff --git a/lib/infrastructure/manage_wifi_repository.dart b/lib/infrastructure/manage_wifi_repository.dart index ec716c99..b512ded0 100644 --- a/lib/infrastructure/manage_wifi_repository.dart +++ b/lib/infrastructure/manage_wifi_repository.dart @@ -120,7 +120,6 @@ class _ManageWiFiRepository implements IManageNetworkRepository { } } on PlatformException catch (e) { logger.e('Failed to get Wifi Name\n$e'); -// wifiName = "Failed to get Wifi Name"; } catch (exception) { logger.e(exception.toString()); } @@ -129,8 +128,31 @@ class _ManageWiFiRepository implements IManageNetworkRepository { @override Future loadWifi() async { - // TODO: Get bssid final NetworkInfo info = NetworkInfo(); + + if (Platform.isLinux) { + final String? bssid = await info.getWifiBSSID(); + final String? wifiName = await info.getWifiName(); + final String? ip = await info.getWifiIP(); + if (bssid == null || wifiName == null || ip == null) { + return; + } + final String subnet = ipToSubnet(ip); + + final NetworkObject network = NetworkObject( + bssid: bssid, + ssid: wifiName, + subNet: subnet, + longitude: null, + latitude: null, + remotePipe: null, + type: null, + ); + NetworksManager().addNetwork(network); + NetworksManager().setCurrentNetwork(network.uniqueId); + return; + } + final PermissionStatus locationStatus = await Permission.location.status; if (locationStatus.isDenied) { await Permission.locationWhenInUse.request(); @@ -146,6 +168,7 @@ class _ManageWiFiRepository implements IManageNetworkRepository { logger.w('Not connected to WiFi'); exit(0); } + String bssid; if (await Permission.location.isGranted) { final String? bssidTemp = await info.getWifiBSSID(); @@ -161,18 +184,17 @@ class _ManageWiFiRepository implements IManageNetworkRepository { exit(0); } final String? ssid = await WiFiForIoTPlugin.getSSID(); - final List? ipSplit = (await WiFiForIoTPlugin.getIP())?.split('.'); - String? subNet; - if (ipSplit != null) { - subNet = ipSplit.sublist(0, ipSplit.length - 1).join(); - } + final String? ip = await WiFiForIoTPlugin.getIP(); final location.LocationData locationData = await location.Location().getLocation(); - if (ssid == null || subNet == null) { - logger.w('Ssid or subnet is null'); + + if (ssid == null || ip == null) { + logger.w('Ssid is null'); exit(0); } + final String subNet = ipToSubnet(ip); + final NetworkObject network = NetworkObject( bssid: bssid, ssid: ssid, @@ -185,4 +207,9 @@ class _ManageWiFiRepository implements IManageNetworkRepository { NetworksManager().addNetwork(network); NetworksManager().setCurrentNetwork(network.uniqueId); } + + String ipToSubnet(String ip) { + final List ipSplit = ip.split('.'); + return ipSplit.sublist(0, ipSplit.length - 1).join(); + } } diff --git a/lib/presentation/molecules/devices/ac_molecule.dart b/lib/presentation/molecules/devices/ac_molecule.dart index bfd215bc..9a2c9268 100644 --- a/lib/presentation/molecules/devices/ac_molecule.dart +++ b/lib/presentation/molecules/devices/ac_molecule.dart @@ -30,7 +30,7 @@ class _AcMoleculeState extends State { void setEntityState(EntityActions action) { final HashSet entitiesId = - HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]); + HashSet.from([widget.entity.entitiyCbjUniqueId.getOrCrash()]); ConnectionsService.instance.setEntityState( RequestActionObject( diff --git a/lib/presentation/molecules/devices/blind_molecule.dart b/lib/presentation/molecules/devices/blind_molecule.dart index a8af44ec..f0387e65 100644 --- a/lib/presentation/molecules/devices/blind_molecule.dart +++ b/lib/presentation/molecules/devices/blind_molecule.dart @@ -32,7 +32,7 @@ class _BlindMoleculeState extends State { void setEntityState(EntityActions action) { final HashSet uniqueIdByVendor = - HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]); + HashSet.from([widget.entity.entitiyCbjUniqueId.getOrCrash()]); ConnectionsService.instance.setEntityState( RequestActionObject( diff --git a/lib/presentation/molecules/devices/boiler_molecule.dart b/lib/presentation/molecules/devices/boiler_molecule.dart index 8a6fec90..ecb3d8dc 100644 --- a/lib/presentation/molecules/devices/boiler_molecule.dart +++ b/lib/presentation/molecules/devices/boiler_molecule.dart @@ -30,7 +30,7 @@ class _BoilerMoleculeState extends State { void setEntityState(EntityActions action) { final HashSet uniqueIdByVendor = - HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]); + HashSet.from([widget.entity.entitiyCbjUniqueId.getOrCrash()]); ConnectionsService.instance.setEntityState( RequestActionObject( diff --git a/lib/presentation/molecules/devices/dimmable_light_molecule.dart b/lib/presentation/molecules/devices/dimmable_light_molecule.dart index e1f034f0..14ff1ad9 100644 --- a/lib/presentation/molecules/devices/dimmable_light_molecule.dart +++ b/lib/presentation/molecules/devices/dimmable_light_molecule.dart @@ -73,7 +73,7 @@ class _DimmableLightMoleculeState extends State { HashMap? value, }) { final HashSet uniqueIdByVendor = - HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]); + HashSet.from([widget.entity.entitiyCbjUniqueId.getOrCrash()]); ConnectionsService.instance.setEntityState( RequestActionObject( diff --git a/lib/presentation/molecules/devices/light_card_molecule.dart b/lib/presentation/molecules/devices/light_card_molecule.dart index bf5cb74f..379ecf1e 100644 --- a/lib/presentation/molecules/devices/light_card_molecule.dart +++ b/lib/presentation/molecules/devices/light_card_molecule.dart @@ -14,11 +14,11 @@ class LightCardMolecule extends StatelessWidget { if (value) { // await IDeviceRepository.instance.turnOnDevices( - // devicesId: [tempDeviceEntity.deviceCbjUniqueId.getOrCrash()], + // devicesId: [tempDeviceEntity.entitiyCbjUniqueId.getOrCrash()], // ); } else { // await IDeviceRepository.instance.turnOffDevices( - // devicesId: [tempDeviceEntity.deviceCbjUniqueId.getOrCrash()], + // devicesId: [tempDeviceEntity.entitiyCbjUniqueId.getOrCrash()], // ); } } diff --git a/lib/presentation/molecules/devices/light_molecule.dart b/lib/presentation/molecules/devices/light_molecule.dart index 9772c14a..d5d75c03 100644 --- a/lib/presentation/molecules/devices/light_molecule.dart +++ b/lib/presentation/molecules/devices/light_molecule.dart @@ -19,7 +19,7 @@ class LightMolecule extends StatelessWidget { void setEntityState(EntityActions action) { final HashSet uniqueIdByVendor = - HashSet.from([entity.deviceCbjUniqueId.getOrCrash()]); + HashSet.from([entity.entitiyCbjUniqueId.getOrCrash()]); ConnectionsService.instance.setEntityState( RequestActionObject( diff --git a/lib/presentation/molecules/devices/rgb_light_molecule.dart b/lib/presentation/molecules/devices/rgb_light_molecule.dart index ae78e220..819163f9 100644 --- a/lib/presentation/molecules/devices/rgb_light_molecule.dart +++ b/lib/presentation/molecules/devices/rgb_light_molecule.dart @@ -66,7 +66,7 @@ class _RgbwLightMoleculeState extends State { HashMap? value, }) { final HashSet uniqueIdByVendor = - HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]); + HashSet.from([widget.entity.entitiyCbjUniqueId.getOrCrash()]); ConnectionsService.instance.setEntityState( RequestActionObject( @@ -202,7 +202,7 @@ class _LightColorMods extends State { HashMap? value, }) { final HashSet uniqueIdByVendor = - HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]); + HashSet.from([widget.entity.entitiyCbjUniqueId.getOrCrash()]); ConnectionsService.instance.setEntityState( RequestActionObject( diff --git a/lib/presentation/molecules/devices/smart_computer_molecule.dart b/lib/presentation/molecules/devices/smart_computer_molecule.dart index 7328aeca..373de172 100644 --- a/lib/presentation/molecules/devices/smart_computer_molecule.dart +++ b/lib/presentation/molecules/devices/smart_computer_molecule.dart @@ -36,12 +36,12 @@ class _SmartComputerMoleculeState extends State { } void suspendComputer(BuildContext context) { - final String deviceId = widget.entity.getCbjDeviceId; + final String deviceId = widget.entity.getCbjEntityId; _suspendAllSmartComputers([deviceId]); } void shutdownComputer(BuildContext context) { - final String deviceId = widget.entity.getCbjDeviceId; + final String deviceId = widget.entity.getCbjEntityId; _shutdownAllSmartComputers([deviceId]); } diff --git a/lib/presentation/molecules/devices/smart_plug_molecule.dart b/lib/presentation/molecules/devices/smart_plug_molecule.dart index 834879de..edc4b976 100644 --- a/lib/presentation/molecules/devices/smart_plug_molecule.dart +++ b/lib/presentation/molecules/devices/smart_plug_molecule.dart @@ -29,7 +29,7 @@ class _SmartPlugsMoleculeState extends State { void setEntityState(EntityActions action) { final HashSet uniqueIdByVendor = - HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]); + HashSet.from([widget.entity.entitiyCbjUniqueId.getOrCrash()]); ConnectionsService.instance.setEntityState( RequestActionObject( diff --git a/lib/presentation/molecules/devices/smart_tv_molecule.dart b/lib/presentation/molecules/devices/smart_tv_molecule.dart index 6d47ee66..d86063cc 100644 --- a/lib/presentation/molecules/devices/smart_tv_molecule.dart +++ b/lib/presentation/molecules/devices/smart_tv_molecule.dart @@ -78,7 +78,7 @@ class _SmartTvMoleculeState extends State { HashMap? value, }) { final HashSet uniqueIdByVendor = - HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]); + HashSet.from([widget.entity.entitiyCbjUniqueId.getOrCrash()]); ConnectionsService.instance.setEntityState( RequestActionObject( diff --git a/lib/presentation/molecules/devices/switch_molecule.dart b/lib/presentation/molecules/devices/switch_molecule.dart index 68a546d7..5eeea1f3 100644 --- a/lib/presentation/molecules/devices/switch_molecule.dart +++ b/lib/presentation/molecules/devices/switch_molecule.dart @@ -29,7 +29,7 @@ class _SwitchMoleculeState extends State { void setEntityState(EntityActions action) { final HashSet uniqueIdByVendor = - HashSet.from([widget.entity.deviceCbjUniqueId.getOrCrash()]); + HashSet.from([widget.entity.entitiyCbjUniqueId.getOrCrash()]); ConnectionsService.instance.setEntityState( RequestActionObject( diff --git a/lib/presentation/pages/add_action_page.dart b/lib/presentation/pages/add_action_page.dart index c405ad66..fbeb3d55 100644 --- a/lib/presentation/pages/add_action_page.dart +++ b/lib/presentation/pages/add_action_page.dart @@ -79,7 +79,7 @@ class _AddActionPageState extends State { items: widget.entities.values.map>((e) { return DropdownMenuItem( - value: e.getCbjDeviceId, + value: e.getCbjEntityId, child: TextAtom(e.cbjEntityName.getOrCrash()!), ); }).toList(), diff --git a/lib/presentation/pages/add_bindings/add_binding_page.dart b/lib/presentation/pages/add_binding_page.dart similarity index 89% rename from lib/presentation/pages/add_bindings/add_binding_page.dart rename to lib/presentation/pages/add_binding_page.dart index ef654864..9b9d4c38 100644 --- a/lib/presentation/pages/add_bindings/add_binding_page.dart +++ b/lib/presentation/pages/add_binding_page.dart @@ -2,6 +2,7 @@ import 'dart:collection'; import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:auto_route/auto_route.dart'; +import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/integrations_controller.dart'; import 'package:cybearjinni/domain/connections_service.dart'; import 'package:cybearjinni/presentation/atoms/atoms.dart'; @@ -9,7 +10,6 @@ import 'package:cybearjinni/presentation/core/routes/app_router.gr.dart'; import 'package:cybearjinni/presentation/core/snack_bar_service.dart'; import 'package:cybearjinni/presentation/molecules/molecules.dart'; import 'package:cybearjinni/presentation/pages/add_action_page.dart'; -import 'package:cybearjinni/presentation/pages/add_bindings/widgets/binding_action_widget.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hexcolor/hexcolor.dart'; @@ -111,10 +111,22 @@ class _AddBindingPageState extends State { return Container( margin: const EdgeInsets.symmetric(vertical: 1), - child: BindingActionWidget( - entity: currentDevice.entity, - propertyToChange: currentDevice.property, - actionToChange: currentDevice.action, + child: ColoredBox( + color: Colors.blue.withOpacity(0.3), + child: ListTile( + leading: const FaIcon( + FontAwesomeIcons.lightbulb, + color: Colors.yellow, + ), + title: AutoSizeText( + '${currentDevice.entity.cbjEntityName.getOrCrash()!} - ${currentDevice.property.name}', + maxLines: 2, + ), + trailing: AutoSizeText( + currentDevice.action.name, + style: const TextStyle(color: Colors.black), + ), + ), ), ); }, diff --git a/lib/presentation/pages/add_bindings/widgets/binding_action_widget.dart b/lib/presentation/pages/add_bindings/widgets/binding_action_widget.dart deleted file mode 100644 index eb073a41..00000000 --- a/lib/presentation/pages/add_bindings/widgets/binding_action_widget.dart +++ /dev/null @@ -1,45 +0,0 @@ -import 'package:auto_size_text/auto_size_text.dart'; -import 'package:cbj_integrations_controller/integrations_controller.dart'; -import 'package:flutter/material.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -/// Action row. -/// Contains device name and action name and sores more data like device id -class BindingActionWidget extends StatelessWidget { - /// Get all and store all info about the action - const BindingActionWidget({ - required this.entity, - required this.propertyToChange, - required this.actionToChange, - }); - - /// Cbj unique id of a device - final DeviceEntityBase entity; - - /// The action for the device - final EntityProperties propertyToChange; - - /// The action for the device - final EntityActions actionToChange; - - @override - Widget build(BuildContext context) { - return ColoredBox( - color: Colors.blue.withOpacity(0.3), - child: ListTile( - leading: const FaIcon( - FontAwesomeIcons.lightbulb, - color: Colors.yellow, - ), - title: AutoSizeText( - '${entity.cbjEntityName.getOrCrash()!} - ${propertyToChange.name}', - maxLines: 2, - ), - trailing: AutoSizeText( - actionToChange.name, - style: const TextStyle(color: Colors.black), - ), - ), - ); - } -} diff --git a/lib/presentation/pages/add_routine/widgets/routine_action_widget.dart b/lib/presentation/pages/add_routine/widgets/routine_action_widget.dart deleted file mode 100644 index 22aabd3f..00000000 --- a/lib/presentation/pages/add_routine/widgets/routine_action_widget.dart +++ /dev/null @@ -1,45 +0,0 @@ -import 'package:auto_size_text/auto_size_text.dart'; -import 'package:cbj_integrations_controller/integrations_controller.dart'; -import 'package:flutter/material.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -/// Action row. -/// Contains device name and action name and sores more data like device id -class RoutineActionWidget extends StatelessWidget { - /// Get all and store all info about the action - const RoutineActionWidget({ - required this.entity, - required this.propertyToChange, - required this.actionToChange, - }); - - /// Cbj unique id of a device - final DeviceEntityBase entity; - - /// The action for the device - final EntityProperties propertyToChange; - - /// The action for the device - final EntityActions actionToChange; - - @override - Widget build(BuildContext context) { - return ColoredBox( - color: Colors.blue.withOpacity(0.3), - child: ListTile( - leading: const FaIcon( - FontAwesomeIcons.lightbulb, - color: Colors.yellow, - ), - title: AutoSizeText( - '${entity.cbjEntityName.getOrCrash()!} - ${propertyToChange.name}', - maxLines: 2, - ), - trailing: AutoSizeText( - actionToChange.name, - style: const TextStyle(color: Colors.black), - ), - ), - ); - } -} diff --git a/lib/presentation/pages/add_routine/add_routine_page.dart b/lib/presentation/pages/add_routine_page.dart similarity index 89% rename from lib/presentation/pages/add_routine/add_routine_page.dart rename to lib/presentation/pages/add_routine_page.dart index ab701e9f..00ae2044 100644 --- a/lib/presentation/pages/add_routine/add_routine_page.dart +++ b/lib/presentation/pages/add_routine_page.dart @@ -2,6 +2,7 @@ import 'dart:collection'; import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:auto_route/auto_route.dart'; +import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/integrations_controller.dart'; import 'package:cybearjinni/domain/connections_service.dart'; import 'package:cybearjinni/presentation/atoms/atoms.dart'; @@ -9,7 +10,6 @@ import 'package:cybearjinni/presentation/core/routes/app_router.gr.dart'; import 'package:cybearjinni/presentation/core/snack_bar_service.dart'; import 'package:cybearjinni/presentation/molecules/molecules.dart'; import 'package:cybearjinni/presentation/pages/add_action_page.dart'; -import 'package:cybearjinni/presentation/pages/add_routine/widgets/routine_action_widget.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hexcolor/hexcolor.dart'; @@ -61,8 +61,7 @@ class _AddRoutinePageState extends State { }); } - Future - _sendRoutineToHub() async { + Future _sendRoutineToHub() async { if (daysToRepeat == null || hourToRepeat == null || minutesToRepeat == null || @@ -136,10 +135,22 @@ class _AddRoutinePageState extends State { return Container( margin: const EdgeInsets.symmetric(vertical: 1), - child: RoutineActionWidget( - entity: currentDevice.entity, - propertyToChange: currentDevice.property, - actionToChange: currentDevice.action, + child: ColoredBox( + color: Colors.blue.withOpacity(0.3), + child: ListTile( + leading: const FaIcon( + FontAwesomeIcons.lightbulb, + color: Colors.yellow, + ), + title: AutoSizeText( + '${currentDevice.entity.cbjEntityName.getOrCrash()!} - ${currentDevice.property.name}', + maxLines: 2, + ), + trailing: AutoSizeText( + currentDevice.action.name, + style: const TextStyle(color: Colors.black), + ), + ), ), ); }, diff --git a/lib/presentation/pages/add_scene/widgets/scene_action_widget.dart b/lib/presentation/pages/add_scene/widgets/scene_action_widget.dart deleted file mode 100644 index 191e000e..00000000 --- a/lib/presentation/pages/add_scene/widgets/scene_action_widget.dart +++ /dev/null @@ -1,45 +0,0 @@ -import 'package:auto_size_text/auto_size_text.dart'; -import 'package:cbj_integrations_controller/integrations_controller.dart'; -import 'package:flutter/material.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; - -/// Action row. -/// Contains device name and action name and sores more data like device id -class SceneActionWidget extends StatelessWidget { - /// Get all and store all info about the action - const SceneActionWidget({ - required this.entity, - required this.propertyToChange, - required this.actionToChange, - }); - - /// Cbj unique id of a device - final DeviceEntityBase entity; - - /// The action for the device - final EntityProperties propertyToChange; - - /// The action for the device - final EntityActions actionToChange; - - @override - Widget build(BuildContext context) { - return ColoredBox( - color: Colors.blue.withOpacity(0.3), - child: ListTile( - leading: const FaIcon( - FontAwesomeIcons.lightbulb, - color: Colors.yellow, - ), - title: AutoSizeText( - '${entity.cbjEntityName.getOrCrash()!} - ${propertyToChange.name}', - maxLines: 2, - ), - trailing: AutoSizeText( - actionToChange.name, - style: const TextStyle(color: Colors.black), - ), - ), - ); - } -} diff --git a/lib/presentation/pages/add_scene/add_scene_page.dart b/lib/presentation/pages/add_scene_page.dart similarity index 90% rename from lib/presentation/pages/add_scene/add_scene_page.dart rename to lib/presentation/pages/add_scene_page.dart index 58301d95..fc6c2059 100644 --- a/lib/presentation/pages/add_scene/add_scene_page.dart +++ b/lib/presentation/pages/add_scene_page.dart @@ -2,6 +2,7 @@ import 'dart:collection'; import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:auto_route/auto_route.dart'; +import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/integrations_controller.dart'; import 'package:cybearjinni/domain/connections_service.dart'; import 'package:cybearjinni/presentation/atoms/atoms.dart'; @@ -9,7 +10,6 @@ import 'package:cybearjinni/presentation/core/routes/app_router.gr.dart'; import 'package:cybearjinni/presentation/core/snack_bar_service.dart'; import 'package:cybearjinni/presentation/organisms/organisms.dart'; import 'package:cybearjinni/presentation/pages/add_action_page.dart'; -import 'package:cybearjinni/presentation/pages/add_scene/widgets/scene_action_widget.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -46,7 +46,7 @@ class _AddScenePageState extends State { entitiesWithActions .map( (e) => RequestActionObject( - entityIds: HashSet.from([e.entity.getCbjDeviceId]), + entityIds: HashSet.from([e.entity.getCbjEntityId]), property: e.property, actionType: e.action, ), @@ -132,10 +132,22 @@ class _AddScenePageState extends State { return Container( margin: const EdgeInsets.symmetric(vertical: 1), - child: SceneActionWidget( - entity: currentDevice.entity, - propertyToChange: currentDevice.property, - actionToChange: currentDevice.action, + child: ColoredBox( + color: Colors.blue.withOpacity(0.3), + child: ListTile( + leading: const FaIcon( + FontAwesomeIcons.lightbulb, + color: Colors.yellow, + ), + title: AutoSizeText( + '${currentDevice.entity.cbjEntityName.getOrCrash()!} - ${currentDevice.property.name}', + maxLines: 2, + ), + trailing: AutoSizeText( + currentDevice.action.name, + style: const TextStyle(color: Colors.black), + ), + ), ), ); }, diff --git a/lib/presentation/pages/change_area_for_devices_page.dart b/lib/presentation/pages/change_area_for_devices_page.dart index 9956c163..592ecb58 100644 --- a/lib/presentation/pages/change_area_for_devices_page.dart +++ b/lib/presentation/pages/change_area_for_devices_page.dart @@ -165,7 +165,7 @@ class _ChangeAreaForDevicesWidgetState items: List>.of( entities!.values.map( (e) => MultiSelectItem( - e.getCbjDeviceId, + e.getCbjEntityId, e.cbjEntityName.getOrCrash()!, ), ), diff --git a/lib/presentation/pages/comunication_method_page.dart b/lib/presentation/pages/comunication_method_page.dart index 63c8ba6c..dde966f8 100644 --- a/lib/presentation/pages/comunication_method_page.dart +++ b/lib/presentation/pages/comunication_method_page.dart @@ -1,4 +1,5 @@ import 'package:auto_route/auto_route.dart'; +import 'package:cbj_integrations_controller/integrations_controller.dart'; import 'package:cybearjinni/domain/connections_service.dart'; import 'package:cybearjinni/presentation/atoms/atoms.dart'; import 'package:cybearjinni/presentation/core/routes/app_router.gr.dart'; @@ -9,6 +10,11 @@ import 'package:flutter/material.dart'; class ComunicationMethodPage extends StatelessWidget { @override Widget build(BuildContext context) { + final String? bssid = NetworksManager().currentNetwork?.bssid; + if (bssid == null) { + return const TextAtom('Please set up network'); + } + return PageOrganism( pageName: 'Comunication type', child: Column( @@ -24,7 +30,8 @@ class ComunicationMethodPage extends StatelessWidget { variant: ButtonVariant.primary, text: 'App as a Hub', onPressed: () => ConnectionsService.setCurrentConnectionType( - ConnectionType.appAsHub, + networkBssid: bssid, + connectionType: ConnectionType.appAsHub, ), ), ButtonWidgetAtom( @@ -32,7 +39,8 @@ class ComunicationMethodPage extends StatelessWidget { text: 'Hub', onPressed: () { ConnectionsService.setCurrentConnectionType( - ConnectionType.hub, + networkBssid: bssid, + connectionType: ConnectionType.hub, ); ConnectionsService.instance.connect(); }, @@ -41,7 +49,8 @@ class ComunicationMethodPage extends StatelessWidget { variant: ButtonVariant.primary, text: 'Demo', onPressed: () => ConnectionsService.setCurrentConnectionType( - ConnectionType.demo, + networkBssid: bssid, + connectionType: ConnectionType.demo, ), ), ], diff --git a/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart b/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart index 26a4054f..11192633 100644 --- a/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart +++ b/lib/presentation/pages/connect_to_hub/widgets/cbj_hub_in_network_widget.dart @@ -3,6 +3,7 @@ import 'dart:collection'; import 'package:auto_route/auto_route.dart'; import 'package:cbj_integrations_controller/integrations_controller.dart'; import 'package:cybearjinni/domain/connections_service.dart'; +import 'package:cybearjinni/infrastructure/core/logger.dart'; import 'package:cybearjinni/presentation/atoms/atoms.dart'; import 'package:cybearjinni/presentation/core/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; @@ -29,8 +30,16 @@ class _CbjHubInNetworkWidgetState extends State { setState(() { loading = true; }); + final String? bssid = NetworksManager().currentNetwork?.bssid; + if (bssid == null) { + logger.e('Please set up network'); + return; + } - ConnectionsService.setCurrentConnectionType(ConnectionType.appAsHub); + ConnectionsService.setCurrentConnectionType( + networkBssid: bssid, + connectionType: ConnectionType.appAsHub, + ); bool foundEntity = false; ConnectionsService.instance.watchEntities().listen((event) { if (!mounted || foundEntity) { diff --git a/lib/presentation/pages/connect_to_hub_more_page.dart b/lib/presentation/pages/connect_to_hub_more_page.dart index 42e1e0fe..d5de6543 100644 --- a/lib/presentation/pages/connect_to_hub_more_page.dart +++ b/lib/presentation/pages/connect_to_hub_more_page.dart @@ -1,7 +1,9 @@ import 'dart:async'; import 'package:auto_route/auto_route.dart'; +import 'package:cbj_integrations_controller/integrations_controller.dart'; import 'package:cybearjinni/domain/connections_service.dart'; +import 'package:cybearjinni/infrastructure/core/logger.dart'; import 'package:cybearjinni/presentation/atoms/atoms.dart'; import 'package:cybearjinni/presentation/core/routes/app_router.gr.dart'; import 'package:flutter/material.dart'; @@ -87,7 +89,16 @@ class _ConnectToHubMoreWidgetState extends State { bool isLoading = false; Future _connectInDemoMode() async { - ConnectionsService.setCurrentConnectionType(ConnectionType.demo); + final String? bssid = NetworksManager().currentNetwork?.bssid; + if (bssid == null) { + logger.e('Please set up network'); + return; + } + + ConnectionsService.setCurrentConnectionType( + networkBssid: bssid, + connectionType: ConnectionType.demo, + ); context.router.replace(const HomeRoute()); } diff --git a/lib/presentation/pages/entities_in_area_page.dart b/lib/presentation/pages/entities_in_area_page.dart index 731936b9..a101c8c3 100644 --- a/lib/presentation/pages/entities_in_area_page.dart +++ b/lib/presentation/pages/entities_in_area_page.dart @@ -42,7 +42,7 @@ class _EntitiesInAreaPageState extends State { tempEntities = entitiesMap.values .where( (element) => - entityIdsInArea.contains(element.getCbjDeviceId) && + entityIdsInArea.contains(element.getCbjEntityId) && (showAllTypes || entityTypes.contains(element.entityTypes.type)) && supportedEntityType(element.entityTypes.type), diff --git a/lib/presentation/pages/home_page/home_page.dart b/lib/presentation/pages/home_page/home_page.dart index 72d130e4..47c75d59 100644 --- a/lib/presentation/pages/home_page/home_page.dart +++ b/lib/presentation/pages/home_page/home_page.dart @@ -24,6 +24,7 @@ class _HomePageState extends State { @override void initState() { super.initState(); + _watchEntities(); _watchAreas(); initializedScenes(); @@ -33,7 +34,7 @@ class _HomePageState extends State { void dispose() { entitiesStream?.cancel(); areasStream?.cancel(); - _pageController.dispose(); + _pageController?.dispose(); super.dispose(); } @@ -45,11 +46,23 @@ class _HomePageState extends State { HashMap? areas; HashMap? entities; + /// Tab num, value will be the default tab to show + int? _currentTabNum; + + PageController? _pageController; + Future initializedScenes() async { final HashMap scenecsTemp = await ConnectionsService.instance.getScenes; setState(() { + if (scenecsTemp.isNotEmpty) { + _currentTabNum = 0; + } else { + _currentTabNum = 1; + } + _pageController = PageController(initialPage: _currentTabNum!); + scenes = scenecsTemp; }); } @@ -126,11 +139,6 @@ class _HomePageState extends State { return type == EntityTypes.undefined || type == EntityTypes.emptyEntity; } - /// Tab num, value will be the default tab to show - int _currentTabNum = 1; - - final _pageController = PageController(initialPage: 1); - static List getBottomNavigationBarItems() { return [ BottomNavigationBarItemAtom( @@ -157,8 +165,8 @@ class _HomePageState extends State { void changeByTabNumber(int index) { setState(() { _currentTabNum = index; - _pageController.animateToPage( - _currentTabNum, + _pageController!.animateToPage( + _currentTabNum!, duration: const Duration(milliseconds: 200), curve: Curves.linear, ); @@ -167,7 +175,11 @@ class _HomePageState extends State { @override Widget build(BuildContext context) { - if (entities == null || areas == null || scenes == null) { + if (_currentTabNum == null || + _pageController == null || + entities == null || + areas == null || + scenes == null) { return const Scaffold( body: CircularProgressIndicatorAtom(), ); @@ -193,7 +205,7 @@ class _HomePageState extends State { bottomNavigationBar: BottomNavigationBarMolecule( bottomNaviList: getBottomNavigationBarItems(), onTap: changeByTabNumber, - pageIndex: _currentTabNum, + pageIndex: _currentTabNum!, ), ), Column( diff --git a/lib/presentation/pages/pages.dart b/lib/presentation/pages/pages.dart index 5c3cb02a..9937cd5e 100644 --- a/lib/presentation/pages/pages.dart +++ b/lib/presentation/pages/pages.dart @@ -1,5 +1,5 @@ export 'package:cybearjinni/presentation/pages/add_action_page.dart'; -export 'package:cybearjinni/presentation/pages/add_bindings/add_binding_page.dart'; +export 'package:cybearjinni/presentation/pages/add_binding_page.dart'; export 'package:cybearjinni/presentation/pages/add_new_area_page.dart'; export 'package:cybearjinni/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/choose_device_vendor_to_add_page.dart'; export 'package:cybearjinni/presentation/pages/add_new_devices_process/computer_connection_check/computer_connection_check_page.dart'; @@ -7,8 +7,8 @@ export 'package:cybearjinni/presentation/pages/add_new_devices_process/configure export 'package:cybearjinni/presentation/pages/add_new_devices_process/connect_to_home_wifi/connect_to_home_wifi_page.dart'; export 'package:cybearjinni/presentation/pages/add_new_devices_process/open_access_point/open_access_pointi_page.dart'; export 'package:cybearjinni/presentation/pages/add_new_devices_process/scan_for_new_cbj_comps/scan_for_new_cbj_comps_page.dart'; -export 'package:cybearjinni/presentation/pages/add_routine/add_routine_page.dart'; -export 'package:cybearjinni/presentation/pages/add_scene/add_scene_page.dart'; +export 'package:cybearjinni/presentation/pages/add_routine_page.dart'; +export 'package:cybearjinni/presentation/pages/add_scene_page.dart'; export 'package:cybearjinni/presentation/pages/change_area_for_devices_page.dart'; export 'package:cybearjinni/presentation/pages/choose_automation_type_to_add_page.dart'; export 'package:cybearjinni/presentation/pages/connect_to_hub/connect_to_hub_page.dart'; @@ -20,7 +20,7 @@ export 'package:cybearjinni/presentation/pages/introduction_screen/introduction_ export 'package:cybearjinni/presentation/pages/pick_repeat_time_page.dart'; export 'package:cybearjinni/presentation/pages/plus_button.dart'; export 'package:cybearjinni/presentation/pages/remote_pipes_page.dart'; -export 'package:cybearjinni/presentation/pages/scenes/scenes_page.dart'; +export 'package:cybearjinni/presentation/pages/scenes_page.dart'; export 'package:cybearjinni/presentation/pages/smart_camera_container_page.dart'; export 'package:cybearjinni/presentation/pages/software_info_page.dart'; export 'package:cybearjinni/presentation/pages/splash_page.dart'; diff --git a/lib/presentation/pages/plus_button.dart b/lib/presentation/pages/plus_button.dart index e325fcfc..49fd8643 100644 --- a/lib/presentation/pages/plus_button.dart +++ b/lib/presentation/pages/plus_button.dart @@ -1,5 +1,7 @@ import 'package:auto_route/auto_route.dart'; +import 'package:cbj_integrations_controller/integrations_controller.dart'; import 'package:cybearjinni/domain/connections_service.dart'; +import 'package:cybearjinni/infrastructure/core/logger.dart'; import 'package:cybearjinni/presentation/atoms/atoms.dart'; import 'package:cybearjinni/presentation/core/routes/app_router.gr.dart'; import 'package:cybearjinni/presentation/molecules/molecules.dart'; @@ -12,7 +14,15 @@ import 'package:iconify_flutter/icons/simple_icons.dart'; class PlusButtonPage extends StatelessWidget { Future _logout(BuildContext context) async { context.router.replace(const ConnectToHubRoute()); - ConnectionsService.setCurrentConnectionType(ConnectionType.none); + final String? bssid = NetworksManager().currentNetwork?.bssid; + if (bssid == null) { + logger.e('Please set up network'); + return; + } + ConnectionsService.setCurrentConnectionType( + networkBssid: bssid, + connectionType: ConnectionType.none, + ); } @override diff --git a/lib/presentation/pages/remote_pipes_page.dart b/lib/presentation/pages/remote_pipes_page.dart index 00c78113..1781643e 100644 --- a/lib/presentation/pages/remote_pipes_page.dart +++ b/lib/presentation/pages/remote_pipes_page.dart @@ -1,6 +1,8 @@ import 'package:adaptive_action_sheet/adaptive_action_sheet.dart'; import 'package:auto_route/auto_route.dart'; +import 'package:cbj_integrations_controller/integrations_controller.dart'; import 'package:cybearjinni/domain/connections_service.dart'; +import 'package:cybearjinni/infrastructure/core/logger.dart'; import 'package:cybearjinni/presentation/atoms/atoms.dart'; import 'package:cybearjinni/presentation/core/snack_bar_service.dart'; import 'package:cybearjinni/presentation/molecules/molecules.dart'; @@ -71,7 +73,15 @@ class _RemotePipesWidgetState extends State { if (remotePipesDomainName == null || remotePipesDomainName!.isEmpty) { return; } - ConnectionsService.setCurrentConnectionType(ConnectionType.remotePipes); + final String? bssid = NetworksManager().currentNetwork?.bssid; + if (bssid == null) { + logger.e('Please set up network'); + return; + } + ConnectionsService.setCurrentConnectionType( + networkBssid: bssid, + connectionType: ConnectionType.remotePipes, + ); ConnectionsService.instance.connect(address: remotePipesDomainName); context.router.pop(); } diff --git a/lib/presentation/pages/scenes/scenes_page.dart b/lib/presentation/pages/scenes_page.dart similarity index 96% rename from lib/presentation/pages/scenes/scenes_page.dart rename to lib/presentation/pages/scenes_page.dart index 686f6c73..d657a34c 100644 --- a/lib/presentation/pages/scenes/scenes_page.dart +++ b/lib/presentation/pages/scenes_page.dart @@ -71,10 +71,6 @@ class _ScenesPageState extends State { ); } - void leftIconFunction(BuildContext context) { - context.router.pop(); - } - @override Widget build(BuildContext context) { if (scenes == null) { @@ -103,7 +99,7 @@ class _ScenesPageState extends State { pageName: 'Scenes_In_Folder', rightIconFunction: userCogFunction, leftIcon: FontAwesomeIcons.arrowLeft, - leftIconFunction: leftIconFunction, + leftIconFunction: context.router.pop, // rightSecondIcon: FontAwesomeIcons.magnifyingGlass, ), Expanded( diff --git a/lib/presentation/pages/splash_page.dart b/lib/presentation/pages/splash_page.dart index 7ec2d5c5..79487910 100644 --- a/lib/presentation/pages/splash_page.dart +++ b/lib/presentation/pages/splash_page.dart @@ -1,3 +1,4 @@ +import 'dart:collection'; import 'dart:io'; import 'package:auto_route/auto_route.dart'; @@ -5,6 +6,7 @@ import 'package:cbj_integrations_controller/integrations_controller.dart'; import 'package:cybearjinni/domain/connections_service.dart'; import 'package:cybearjinni/domain/manage_network/i_manage_network_repository.dart'; import 'package:cybearjinni/infrastructure/app_commands.dart'; +import 'package:cybearjinni/infrastructure/core/logger.dart'; import 'package:cybearjinni/infrastructure/mqtt.dart'; import 'package:cybearjinni/presentation/atoms/atoms.dart'; import 'package:cybearjinni/presentation/core/routes/app_router.gr.dart'; @@ -29,17 +31,39 @@ class _SplashPageState extends State { Future initilizeApp() async { SystemCommandsBaseClassD.instance = AppCommands(); await Hive.initFlutter(); - IcSynchronizer.initializeIntegrationsController(); + await IDbRepository.instance.asyncConstactor(); + NetworksManager().loadFromDb(); await IManageNetworkRepository.instance.loadWifi(); - ConnectionsService.setCurrentConnectionType(ConnectionType.appAsHub); - _navigate(); + final String? bssid = NetworksManager().currentNetwork?.bssid; + if (bssid == null) { + logger.e('Please set up network'); + return; + } + await IcSynchronizer().loadAllFromDb(); + ConnectionsService.setCurrentConnectionType( + networkBssid: bssid, + connectionType: ConnectionType.appAsHub, + ); + + ConnectionsService.instance.searchDevices(); // TODO: Only here so that app will not crash MqttServerRepository(); NodeRedRepository(); + + _navigate(); } - void _navigate() { + Future _navigate() async { + final HashMap entities = + await IcSynchronizer().getEntities(); + if (!mounted) { + return; + } + if (entities.isNotEmpty) { + context.router.replace(const HomeRoute()); + return; + } if (kIsWeb || Platform.isLinux || Platform.isWindows) { context.router.replace(const ConnectToHubRoute()); return; From 66d219f0ca827526813b9bde440451a0dfc1fbb9 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Mon, 5 Feb 2024 04:08:33 +0200 Subject: [PATCH 4/4] version to 1.4.10+74 --- lib/presentation/pages/add_scene_page.dart | 2 +- pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/presentation/pages/add_scene_page.dart b/lib/presentation/pages/add_scene_page.dart index fc6c2059..f793d94e 100644 --- a/lib/presentation/pages/add_scene_page.dart +++ b/lib/presentation/pages/add_scene_page.dart @@ -61,7 +61,6 @@ class _AddScenePageState extends State { uniqueId: UniqueId(), name: SceneCbjName(sceneName), backgroundColor: SceneCbjBackgroundColor(Colors.red.toString()), - automationString: SceneCbjAutomationString(''), nodeRedFlowId: SceneCbjNodeRedFlowId(''), firstNodeId: SceneCbjFirstNodeId(''), iconCodePoint: @@ -76,6 +75,7 @@ class _AddScenePageState extends State { entityStateGRPC: SceneCbjDeviceStateGRPC(EntityStateGRPC.ack.name), actions: actions, areaPurposeType: AreaPurposesTypes.undefined, + entitiesWithAutomaticPurpose: EntitiesWithAutomaticPurpose(HashSet()), ); ConnectionsService.instance.addScene(scene); diff --git a/pubspec.yaml b/pubspec.yaml index 03f59d0b..402a70c2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: cybearjinni description: CyBear Jinni app to interact with your CyBear Jinni Smart Devices -version: 1.4.9+73 +version: 1.4.10+74 homepage: https://cybearjinni.com publish_to: 'none'