diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 6e88767ca..020e5df09 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -19,6 +19,7 @@ + > 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 a5207c970..29fb092ff 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 b92ee6ccf..d89682c28 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/connection_service/app_connection_service.dart b/lib/infrastructure/connection_service/app_connection_service.dart index dc042a966..39683f077 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 b0f17ddac..e3a87c1aa 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 70bb08beb..6b1158131 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 3b0920734..f39203aa7 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/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 d56475dd8..000000000 --- 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 f3fbd7888..000000000 --- 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 8b0944700..000000000 --- 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 127a91753..000000000 --- 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 6dd1e6aea..b512ded04 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 { @@ -119,10 +120,96 @@ 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()); } return wifiName; } + + @override + Future loadWifi() async { + 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(); + } + 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 String? ip = await WiFiForIoTPlugin.getIP(); + final location.LocationData locationData = + await location.Location().getLocation(); + + 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, + subNet: subNet, + longitude: locationData.longitude, + latitude: locationData.latitude, + remotePipe: null, + type: null, + ); + 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/infrastructure/mqtt.dart b/lib/infrastructure/mqtt.dart index 27a67a14a..e0541a15e 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/infrastructure/network_utilities_flutter.dart b/lib/infrastructure/network_utilities_flutter.dart index 22304b148..a83079c09 100644 --- a/lib/infrastructure/network_utilities_flutter.dart +++ b/lib/infrastructure/network_utilities_flutter.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:cbj_integrations_controller/integrations_controller.dart'; import 'package:network_tools_flutter/network_tools_flutter.dart' as network_flutter; +import 'package:network_tools_flutter/network_tools_flutter.dart'; class NetworkUtilitiesFlutter extends NetworkUtilities { @override @@ -13,7 +14,8 @@ class NetworkUtilitiesFlutter extends NetworkUtilities { }) => network_flutter.HostScannerFlutter.getAllPingableDevices( subnet, - firstHostId: 127, + firstHostId: firstHostId ?? HostScanner.defaultFirstHostId, + lastHostId: lastHostId ?? HostScanner.defaultLastHostId, ); @override diff --git a/lib/presentation/molecules/devices/ac_molecule.dart b/lib/presentation/molecules/devices/ac_molecule.dart index bfd215bc8..9a2c9268c 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 a8af44ec7..f0387e654 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 8a6fec90b..ecb3d8dcd 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 e1f034f02..14ff1ad94 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 bf5cb74f5..379ecf1e2 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 9772c14a2..d5d75c03e 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 c8539aa40..819163f94 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( @@ -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(); } @@ -204,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( @@ -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/molecules/devices/smart_computer_molecule.dart b/lib/presentation/molecules/devices/smart_computer_molecule.dart index 7328aecad..373de1722 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 834879de6..edc4b9768 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 6d47ee669..d86063cca 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 68a546d70..5eeea1f38 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 c405ad665..fbeb3d556 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 ef654864e..9b9d4c383 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 eb073a415..000000000 --- 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_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 6131c0e50..1b4237ce3 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 d22b8324d..59efb79fb 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"); 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 22aabd3f6..000000000 --- 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 90% rename from lib/presentation/pages/add_routine/add_routine_page.dart rename to lib/presentation/pages/add_routine_page.dart index 0497f292a..00ae20442 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'; @@ -135,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 191e000e3..000000000 --- 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 89% rename from lib/presentation/pages/add_scene/add_scene_page.dart rename to lib/presentation/pages/add_scene_page.dart index 58301d953..f793d94e9 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, ), @@ -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); @@ -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 9956c1637..592ecb58f 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 63c8ba6c3..dde966f8c 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 26a4054f7..111926335 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 42e1e0fe5..d5de65432 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 731936b92..a101c8c3d 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 72d130e44..47c75d59c 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 5c3cb02a7..9937cd5e3 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 e325fcfc1..49fd86437 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 00c781134..1781643e1 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 686f6c739..d657a34ce 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 6c528ec64..79487910a 100644 --- a/lib/presentation/pages/splash_page.dart +++ b/lib/presentation/pages/splash_page.dart @@ -1,11 +1,12 @@ +import 'dart:collection'; 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/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'; @@ -28,27 +29,41 @@ 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 + await IDbRepository.instance.asyncConstactor(); + NetworksManager().loadFromDb(); + await IManageNetworkRepository.instance.loadWifi(); + 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(); - // TODO: Same as App Command? - PhoneCommandsD(); - SystemCommandsManager(); - // TODO: can we remove NodeRedRepository(); - ConnectionsService.instance; + _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; diff --git a/pubspec.yaml b/pubspec.yaml index 03f59d0bc..402a70c23 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'