diff --git a/bin/main.dart b/bin/main.dart index 30dd9c1..98e2fd1 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -2,7 +2,6 @@ import 'dart:io'; import 'package:cbj_integrations_controller/integrations_controller.dart'; import 'package:cbj_smart_device/application/usecases/core_u/smart_device_manager_u.dart'; -import 'package:cbj_smart_device/infrastructure/datasources/core_d/manage_physical_components/device_pin_manager.dart'; import 'package:cbj_smart_device/utils.dart'; void main(List arguments) async { diff --git a/lib/application/usecases/button_object_u/button_object_local_abstract.dart b/lib/application/usecases/button_object_u/button_object_local_abstract.dart index 4ff7c09..5d34c1c 100644 --- a/lib/application/usecases/button_object_u/button_object_local_abstract.dart +++ b/lib/application/usecases/button_object_u/button_object_local_abstract.dart @@ -41,7 +41,7 @@ abstract class ButtonObjectLocalAbstract { ); /// Logic of two buttons - Future changeBlindsPinsOutput( + Future changeBlindsPinsOutput( BlindsObject blindsObject, PinInformation firstLightPin, PinInformation secondLightPin, diff --git a/lib/application/usecases/button_object_u/button_object_local_u.dart b/lib/application/usecases/button_object_u/button_object_local_u.dart index b8fc72f..d167cf6 100644 --- a/lib/application/usecases/button_object_u/button_object_local_u.dart +++ b/lib/application/usecases/button_object_u/button_object_local_u.dart @@ -8,7 +8,7 @@ import 'package:cbj_smart_device/utils.dart'; class ButtonObjectLocalU extends ButtonObjectLocalAbstract { @override - Future buttonPressed( + Future buttonPressed( SmartDeviceBase smartDevice, PinInformation buttonPinNumber, PinInformation lightPin, @@ -50,7 +50,7 @@ class ButtonObjectLocalU extends ButtonObjectLocalAbstract { } @override - Future buttonPressedForBoiler( + Future buttonPressedForBoiler( BoilerObject boilerObject, PinInformation buttonPinNumber, PinInformation boiler, @@ -94,7 +94,7 @@ class ButtonObjectLocalU extends ButtonObjectLocalAbstract { /// Listen to two buttons but work only if one is pressed. @override - Future listenToTwoButtonPressedButtOnlyOneCanBePressedAtATime( + Future listenToTwoButtonPressedButtOnlyOneCanBePressedAtATime( BlindsObject smartDevice, PinInformation firstButtonPinNumber, PinInformation firstBlindsPin, @@ -119,7 +119,7 @@ class ButtonObjectLocalU extends ButtonObjectLocalAbstract { } @override - Future listenToButtonPressAndChangeBlindStateAccordingly( + Future listenToButtonPressAndChangeBlindStateAccordingly( BlindsObject blindsObject, PinInformation buttonPinNumber, PinInformation firstLightPin, @@ -143,7 +143,7 @@ class ButtonObjectLocalU extends ButtonObjectLocalAbstract { /// Logic of two buttons that cannot be pressed together @override - Future changeBlindsPinsOutput( + Future changeBlindsPinsOutput( BlindsObject blindsObject, PinInformation firstBlindsPin, PinInformation secondBlindsPin, diff --git a/lib/application/usecases/button_object_u/button_with_light_object.dart b/lib/application/usecases/button_object_u/button_with_light_object.dart index 3807a27..c18b470 100644 --- a/lib/application/usecases/button_object_u/button_with_light_object.dart +++ b/lib/application/usecases/button_object_u/button_with_light_object.dart @@ -3,7 +3,6 @@ import 'package:cbj_smart_device/application/usecases/button_object_u/simple_but import 'package:cbj_smart_device/application/usecases/devices_pin_configuration_u/pin_information.dart'; import 'package:cbj_smart_device/application/usecases/wish_classes_u/off_wish_u.dart'; import 'package:cbj_smart_device/application/usecases/wish_classes_u/on_wish_u.dart'; -import 'package:cbj_smart_device/infrastructure/datasources/core_d/manage_physical_components/device_pin_manager.dart'; import 'package:cbj_smart_device/infrastructure/repositories/button_object_r/button_object_r.dart'; import 'package:cbj_smart_device/utils.dart'; @@ -12,11 +11,12 @@ class ButtonWithLightObject extends ButtonObject { ButtonWithLightObject( super.id, super.deviceName, - super.buttonPinInt, - int? buttonLightInt, { + // super.buttonPinInt, + // int? buttonLightInt, + { super.buttonStatesAction, }) { - buttonLight = DevicePinListManager().getGpioPin(buttonLightInt); + // buttonLight = DevicePinListManager().getGpioPin(buttonLightInt); buttonObjectRepository = ButtonObjectR(); listenToButtonPress(); @@ -42,7 +42,7 @@ class ButtonWithLightObject extends ButtonObject { /// Listen to the button press and execute actions from buttonStateActions @override - Future listenToButtonPress() async { + Future listenToButtonPress() async { if (buttonPin == null) { return; } diff --git a/lib/application/usecases/button_object_u/simple_button_object.dart b/lib/application/usecases/button_object_u/simple_button_object.dart index ec2d59b..f8ad8e1 100644 --- a/lib/application/usecases/button_object_u/simple_button_object.dart +++ b/lib/application/usecases/button_object_u/simple_button_object.dart @@ -3,7 +3,6 @@ import 'package:cbj_smart_device/application/usecases/devices_pin_configuration_ import 'package:cbj_smart_device/application/usecases/smart_device_objects_u/abstracts_devices/smart_device_base.dart'; import 'package:cbj_smart_device/application/usecases/smart_device_objects_u/abstracts_devices/smart_device_base_abstract.dart'; import 'package:cbj_smart_device/core/my_singleton.dart'; -import 'package:cbj_smart_device/infrastructure/datasources/core_d/manage_physical_components/device_pin_manager.dart'; import 'package:cbj_smart_device/infrastructure/repositories/button_object_r/button_object_r.dart'; import 'package:cbj_smart_device/utils.dart'; @@ -12,10 +11,11 @@ class ButtonObject extends SmartDeviceBaseAbstract { ButtonObject( super.id, super.deviceName, - int? buttonPinInt, { + // int? buttonPinInt, + { this.buttonStatesAction, }) { - buttonPin = DevicePinListManager().getGpioPin(buttonPinInt); + // buttonPin = DevicePinListManager().getGpioPin(buttonPinInt); buttonObjectRepository = ButtonObjectR(); listenToButtonPress(); @@ -52,7 +52,7 @@ class ButtonObject extends SmartDeviceBaseAbstract { static List neededPinTypesList() => ['gpio']; /// Listen to the button press and execute actions from buttonStateActions - Future listenToButtonPress() async { + Future listenToButtonPress() async { if (buttonPin == null) { return; } diff --git a/lib/application/usecases/set_devices_u/set_devices_u.dart b/lib/application/usecases/set_devices_u/set_devices_u.dart index b2c3242..d57ef26 100644 --- a/lib/application/usecases/set_devices_u/set_devices_u.dart +++ b/lib/application/usecases/set_devices_u/set_devices_u.dart @@ -17,7 +17,7 @@ class SetDevicesU { late SetDevicesE _setDevicesE; /// Setting all the devices from saved data - Future setAllDevices({ + Future setAllDevices({ List? deviceList, }) async { if (deviceList != null) { @@ -49,7 +49,7 @@ class SetDevicesU { // manualSetup(); } - Future manualSetup() async { + Future manualSetup() async { final String uuid = await _setDevicesE.getCurrentDeviceUUid(); MySingleton().smartDevicesList = [ diff --git a/lib/application/usecases/smart_client/smart_client.dart b/lib/application/usecases/smart_client/smart_client.dart index c9912a3..fdc2e2e 100644 --- a/lib/application/usecases/smart_client/smart_client.dart +++ b/lib/application/usecases/smart_client/smart_client.dart @@ -13,7 +13,7 @@ class SmartClient { } /// Turn smart device on - static Future createStreamWithClients(String addressToHub) async { + static Future createStreamWithClients(String addressToHub) async { channel = await createCbjSmartDeviceServerClient(addressToHub); stub = CbjSmartDeviceConnectionsClient(channel!); diff --git a/lib/application/usecases/smart_device_objects_u/abstracts_devices/smart_device_base.dart b/lib/application/usecases/smart_device_objects_u/abstracts_devices/smart_device_base.dart index 67b8dd8..8c6ef8b 100644 --- a/lib/application/usecases/smart_device_objects_u/abstracts_devices/smart_device_base.dart +++ b/lib/application/usecases/smart_device_objects_u/abstracts_devices/smart_device_base.dart @@ -7,7 +7,6 @@ import 'package:cbj_smart_device/application/usecases/wish_classes_u/on_wish_u.d import 'package:cbj_smart_device/application/usecases/wish_classes_u/smart_computer_wish_u.dart'; import 'package:cbj_smart_device/core/helper_methods.dart'; import 'package:cbj_smart_device/domain/entities/core_e/enums_e.dart'; -import 'package:cbj_smart_device/infrastructure/datasources/core_d/manage_physical_components/device_pin_manager.dart'; import 'package:cbj_smart_device/infrastructure/repositories/smart_device_objects_r/smart_device_objects_r.dart'; import 'package:cbj_smart_device/utils.dart'; @@ -124,10 +123,11 @@ abstract class SmartDeviceBase extends SmartDeviceBaseAbstract { PinInformation? addPinToGpioPinList(int pinNumber) { // Check if pin is free to be taken, // if not return negative number with error number - final PinInformation gpioPin = - DevicePinListManager().getGpioPin(pinNumber)!; - _gpioPinList.add(gpioPin); - return gpioPin; + // final PinInformation gpioPin = + // DevicePinListManager().getGpioPin(pinNumber)!; + // _gpioPinList.add(gpioPin); + // return gpioPin; + return null; } /// Return PossibleWishes object if @@ -227,7 +227,7 @@ abstract class SmartDeviceBase extends SmartDeviceBaseAbstract { } /// Listen to button press - Future listenToButtonPressed() async { + Future listenToButtonPressed() async { ButtonObjectLocalU().buttonPressed(this, onOffButtonPin!, onOffPin!); } } diff --git a/lib/application/usecases/smart_device_objects_u/simple_devices/boiler_object.dart b/lib/application/usecases/smart_device_objects_u/simple_devices/boiler_object.dart index dcb90a9..45cf4fb 100644 --- a/lib/application/usecases/smart_device_objects_u/simple_devices/boiler_object.dart +++ b/lib/application/usecases/smart_device_objects_u/simple_devices/boiler_object.dart @@ -4,15 +4,15 @@ import 'package:cbj_smart_device/application/usecases/devices_pin_configuration_ import 'package:cbj_smart_device/application/usecases/smart_device_objects_u/abstracts_devices/smart_device_simple_abstract.dart'; import 'package:cbj_smart_device/application/usecases/wish_classes_u/off_wish_u.dart'; import 'package:cbj_smart_device/application/usecases/wish_classes_u/on_wish_u.dart'; -import 'package:cbj_smart_device/infrastructure/datasources/core_d/manage_physical_components/device_pin_manager.dart'; import 'package:cbj_smart_device/utils.dart'; class BoilerObject extends SmartDeviceSimpleAbstract { BoilerObject( String? uuid, String? smartInstanceName, - int? boilerPinNUmber, - int? boilerButtonPinNumber, { + // int? boilerPinNUmber, + // int? boilerButtonPinNumber, + { int? onOffPinNumber, int? onOffButtonPinNumber, }) : super( @@ -22,8 +22,8 @@ class BoilerObject extends SmartDeviceSimpleAbstract { onOffButtonPinNumber: onOffButtonPinNumber, ) { logger.i('New boiler object'); - boilerPin = DevicePinListManager().getGpioPin(boilerPinNUmber); - boilerButtonPin = DevicePinListManager().getGpioPin(boilerButtonPinNumber); + // boilerPin = DevicePinListManager().getGpioPin(boilerPinNUmber); + // boilerButtonPin = DevicePinListManager().getGpioPin(boilerButtonPinNumber); listenButtonsPress(); deviceType = CbjDeviceTypes.boiler; } diff --git a/lib/application/usecases/smart_device_objects_u/static_devices/blinds_object.dart b/lib/application/usecases/smart_device_objects_u/static_devices/blinds_object.dart index f232d31..30d311d 100644 --- a/lib/application/usecases/smart_device_objects_u/static_devices/blinds_object.dart +++ b/lib/application/usecases/smart_device_objects_u/static_devices/blinds_object.dart @@ -3,7 +3,6 @@ import 'package:cbj_smart_device/application/usecases/button_object_u/button_obj import 'package:cbj_smart_device/application/usecases/devices_pin_configuration_u/pin_information.dart'; import 'package:cbj_smart_device/application/usecases/smart_device_objects_u/abstracts_devices/smart_device_static_abstract.dart'; import 'package:cbj_smart_device/application/usecases/wish_classes_u/blinds_wish_u.dart'; -import 'package:cbj_smart_device/infrastructure/datasources/core_d/manage_physical_components/device_pin_manager.dart'; import 'package:cbj_smart_device/utils.dart'; /// Object to control blinds @@ -14,18 +13,18 @@ class BlindsObject extends SmartDeviceStaticAbstract { String? super.smartInstanceName, super.onOffPinNumber, onOffButtonPinNumber, - int? blindsUpPin, - int? upButtonPinNumber, - int? blindsDownPin, - int? downButtonPinNumber, + // int? blindsUpPin, + // int? upButtonPinNumber, + // int? blindsDownPin, + // int? downButtonPinNumber, ) : super( onOffButtonPinNumber: onOffButtonPinNumber, ) { - buttonPinUp = DevicePinListManager().getGpioPin(upButtonPinNumber); - buttonPinDown = DevicePinListManager().getGpioPin(downButtonPinNumber); + // buttonPinUp = DevicePinListManager().getGpioPin(upButtonPinNumber); + // buttonPinDown = DevicePinListManager().getGpioPin(downButtonPinNumber); - this.blindsUpPin = DevicePinListManager().getGpioPin(blindsUpPin); - this.blindsDownPin = DevicePinListManager().getGpioPin(blindsDownPin); + // this.blindsUpPin = DevicePinListManager().getGpioPin(blindsUpPin); + // this.blindsDownPin = DevicePinListManager().getGpioPin(blindsDownPin); listenToTwoButtonsPress(); deviceType = CbjDeviceTypes.blinds; diff --git a/lib/application/usecases/smart_server_u/smart_server_u.dart b/lib/application/usecases/smart_server_u/smart_server_u.dart index 9c592cf..e23e43c 100644 --- a/lib/application/usecases/smart_server_u/smart_server_u.dart +++ b/lib/application/usecases/smart_server_u/smart_server_u.dart @@ -447,7 +447,7 @@ class CbjSmartDeviceServerU extends CbjSmartDeviceConnectionsServiceBase { } } - Future exitTheApp() async { + Future exitTheApp() async { const int secondsToExistTheProgram = 15; logger.i('$secondsToExistTheProgram seconds to exit the program'); await Future.delayed(const Duration(seconds: secondsToExistTheProgram)); diff --git a/lib/application/usecases/wish_classes_u/blinds_wish_u.dart b/lib/application/usecases/wish_classes_u/blinds_wish_u.dart index bb5d064..f68b44b 100644 --- a/lib/application/usecases/wish_classes_u/blinds_wish_u.dart +++ b/lib/application/usecases/wish_classes_u/blinds_wish_u.dart @@ -21,7 +21,7 @@ class BlindsWishU { blindsInformation.blindsDownPin, ); - await Future.delayed(const Duration(seconds: 1)); + await Future.delayed(const Duration(seconds: 1)); blindsInformation.blindsUpPin?.onDuration = -1; @@ -54,7 +54,7 @@ class BlindsWishU { blindsInformation.blindsUpPin, ); - await Future.delayed(const Duration(seconds: 1)); + await Future.delayed(const Duration(seconds: 1)); blindsInformation.blindsDownPin?.onDuration = -1; status += diff --git a/lib/domain/entities/core_e/enums_e.dart b/lib/domain/entities/core_e/enums_e.dart index 31a7c68..d74d442 100644 --- a/lib/domain/entities/core_e/enums_e.dart +++ b/lib/domain/entities/core_e/enums_e.dart @@ -134,13 +134,16 @@ class EnumHelper { case CbjDeviceTypes.light: return LightObject(null, null, null); case CbjDeviceTypes.blinds: - return BlindsObject(null, null, null, null, null, null, null, null); + return BlindsObject(null, null, null, null); case CbjDeviceTypes.boiler: - return BoilerObject(null, null, null, null); + return BoilerObject(null, null); case CbjDeviceTypes.button: - return ButtonObject(null, null, null); + return ButtonObject(null, null); case CbjDeviceTypes.buttonWithLight: - return ButtonWithLightObject(null, null, null, null); + return ButtonWithLightObject( + null, + null, + ); default: logger.i('Type $deviceType is not supported'); } diff --git a/lib/domain/entities/local_db_e/local_db_e.dart b/lib/domain/entities/local_db_e/local_db_e.dart index 4497b52..925a45d 100644 --- a/lib/domain/entities/local_db_e/local_db_e.dart +++ b/lib/domain/entities/local_db_e/local_db_e.dart @@ -21,7 +21,7 @@ class LocalDbE { return firebaseAccountsInformationD; } - Future saveAllDevices( + Future saveAllDevices( List smartDevicesList, ) async { await _localDbR.saveAllDevices(smartDevicesList); diff --git a/lib/domain/entities/set_devices_e/set_devices_e.dart b/lib/domain/entities/set_devices_e/set_devices_e.dart index c0210a9..14243a1 100644 --- a/lib/domain/entities/set_devices_e/set_devices_e.dart +++ b/lib/domain/entities/set_devices_e/set_devices_e.dart @@ -1,17 +1,8 @@ import 'package:cbj_integrations_controller/integrations_controller.dart'; -import 'package:cbj_smart_device/application/usecases/button_object_u/button_with_light_object.dart'; -import 'package:cbj_smart_device/application/usecases/button_object_u/simple_button_object.dart'; -import 'package:cbj_smart_device/application/usecases/devices_pin_configuration_u/pin_information.dart'; -import 'package:cbj_smart_device/application/usecases/smart_device_objects_u/abstracts_devices/smart_device_base.dart'; import 'package:cbj_smart_device/application/usecases/smart_device_objects_u/abstracts_devices/smart_device_base_abstract.dart'; -import 'package:cbj_smart_device/application/usecases/smart_device_objects_u/simple_devices/boiler_object.dart'; -import 'package:cbj_smart_device/application/usecases/smart_device_objects_u/simple_devices/light_object.dart'; -import 'package:cbj_smart_device/application/usecases/smart_device_objects_u/static_devices/blinds_object.dart'; import 'package:cbj_smart_device/domain/entities/core_e/enums_e.dart'; -import 'package:cbj_smart_device/infrastructure/datasources/core_d/manage_physical_components/device_pin_manager.dart'; import 'package:cbj_smart_device/infrastructure/repositories/set_devices_r/set_devices_r.dart'; import 'package:cbj_smart_device/utils.dart'; -import 'package:uuid/uuid.dart'; class SetDevicesE { SetDevicesE() { @@ -52,170 +43,170 @@ class SetDevicesE { return []; } - String? uuid; + // String? uuid; try { - uuid = await getCurrentDeviceUUid(); + // uuid = await getCurrentDeviceUUid(); } catch (e) { logger.i("Can't get uuid: $e"); } - String id; + // String id; for (final CbjDeviceTypes deviceType in deviceTypeList) { - id = const Uuid().v1(); + // id = const Uuid().v1(); /// Setting up for Light if (deviceType == CbjDeviceTypes.light) { - final List? lightPins = DevicePinListManager() - .getFreePinsForSmartDeviceType(CbjDeviceTypes.light); - - final int? lightPinNumber = - lightPins?[0]?.pinAndPhysicalPinConfiguration; - - final int deviceTypeCounter = numberOfThatTypeThatExist( - smartDeviceBaseAbstractList, - CbjDeviceTypes.light, - ); - - smartDeviceBaseAbstractList.add( - LightObject( - uuid, - 'Light$deviceTypeCounter', - lightPinNumber, - )..id = id, - ); + // final List? lightPins = DevicePinListManager() + // .getFreePinsForSmartDeviceType(CbjDeviceTypes.light); + + // final int? lightPinNumber = + // lightPins?[0]?.pinAndPhysicalPinConfiguration; + + // final int deviceTypeCounter = numberOfThatTypeThatExist( + // smartDeviceBaseAbstractList, + // CbjDeviceTypes.light, + // ); + + // smartDeviceBaseAbstractList.add( + // LightObject( + // uuid, + // 'Light$deviceTypeCounter', + // lightPinNumber, + // )..id = id, + // ); } /// Setting up for Boiler else if (deviceType == CbjDeviceTypes.boiler) { - final List? boilerPins = DevicePinListManager() - .getFreePinsForSmartDeviceType(CbjDeviceTypes.boiler); - - final int? boilerPinNumber = - boilerPins?[0]?.pinAndPhysicalPinConfiguration; - - final int? buttonPinNumber = - boilerPins?[1]?.pinAndPhysicalPinConfiguration; - - logger.i('boilerPinNumber: $boilerPinNumber'); - logger.i('buttonPinNumber: $buttonPinNumber'); - - final int deviceTypeCounter = numberOfThatTypeThatExist( - smartDeviceBaseAbstractList, - CbjDeviceTypes.boiler, - ); - - smartDeviceBaseAbstractList.add( - BoilerObject( - uuid, - 'Boiler$deviceTypeCounter', - boilerPinNumber, - buttonPinNumber, - )..id = id, - ); + // final List? boilerPins = DevicePinListManager() + // .getFreePinsForSmartDeviceType(CbjDeviceTypes.boiler); + + // final int? boilerPinNumber = + // boilerPins?[0]?.pinAndPhysicalPinConfiguration; + + // final int? buttonPinNumber = + // boilerPins?[1]?.pinAndPhysicalPinConfiguration; + + // logger.i('boilerPinNumber: $boilerPinNumber'); + // logger.i('buttonPinNumber: $buttonPinNumber'); + + // final int deviceTypeCounter = numberOfThatTypeThatExist( + // smartDeviceBaseAbstractList, + // CbjDeviceTypes.boiler, + // ); + + // smartDeviceBaseAbstractList.add( + // BoilerObject( + // uuid, + // 'Boiler$deviceTypeCounter', + // boilerPinNumber, + // buttonPinNumber, + // )..id = id, + // ); } /// Setting up for Blinds else if (deviceType == CbjDeviceTypes.blinds) { - final List? blindPinsAndButtonPins = - DevicePinListManager() - .getFreePinsForSmartDeviceType(CbjDeviceTypes.blinds); - - final int? blindUpPinNumber = - blindPinsAndButtonPins?[0]?.pinAndPhysicalPinConfiguration; - - final int? buttonUpPinNumber = - blindPinsAndButtonPins?[1]?.pinAndPhysicalPinConfiguration; - - final int? blindDownPinNumber = - blindPinsAndButtonPins?[2]?.pinAndPhysicalPinConfiguration; - - final int? buttonDownPinNumber = - blindPinsAndButtonPins?[3]?.pinAndPhysicalPinConfiguration; - - final int deviceTypeCounter = numberOfThatTypeThatExist( - smartDeviceBaseAbstractList, - CbjDeviceTypes.blinds, - ); - - smartDeviceBaseAbstractList.add( - BlindsObject( - uuid, - 'Blinds$deviceTypeCounter', - null, - // onOffPinNumber - null, - // onOffButtonPinNumber - blindUpPinNumber, - // blindsUpPin - buttonUpPinNumber, - // upButtonPinNumber - blindDownPinNumber, - // blindsDownPin - buttonDownPinNumber, // downButtonPinNumber - )..id = id, - ); + // final List? blindPinsAndButtonPins = + // DevicePinListManager() + // .getFreePinsForSmartDeviceType(CbjDeviceTypes.blinds); + + // final int? blindUpPinNumber = + // blindPinsAndButtonPins?[0]?.pinAndPhysicalPinConfiguration; + + // final int? buttonUpPinNumber = + // blindPinsAndButtonPins?[1]?.pinAndPhysicalPinConfiguration; + + // final int? blindDownPinNumber = + // blindPinsAndButtonPins?[2]?.pinAndPhysicalPinConfiguration; + + // final int? buttonDownPinNumber = + // blindPinsAndButtonPins?[3]?.pinAndPhysicalPinConfiguration; + + // final int deviceTypeCounter = numberOfThatTypeThatExist( + // smartDeviceBaseAbstractList, + // CbjDeviceTypes.blinds, + // ); + + // smartDeviceBaseAbstractList.add( + // BlindsObject( + // uuid, + // 'Blinds$deviceTypeCounter', + // null, + // // onOffPinNumber + // null, + // // onOffButtonPinNumber + // blindUpPinNumber, + // // blindsUpPin + // buttonUpPinNumber, + // // upButtonPinNumber + // blindDownPinNumber, + // // blindsDownPin + // buttonDownPinNumber, // downButtonPinNumber + // )..id = id, + // ); } /// Setting up simple Button else if (deviceType == CbjDeviceTypes.button) { - final List? buttonPinList = DevicePinListManager() - .getFreePinsForSmartDeviceType(CbjDeviceTypes.button); - - final int? buttonPin = - buttonPinList?[0]?.pinAndPhysicalPinConfiguration; - - final int deviceTypeCounter = numberOfThatTypeThatExist( - smartDeviceBaseAbstractList, - CbjDeviceTypes.button, - ); - - final Map>>? - buttonStatesAction = - ButtonObject.buttonDefaultStateAction(smartDeviceBaseAbstractList); - - smartDeviceBaseAbstractList.add( - ButtonObject( - uuid, - 'Button $deviceTypeCounter', - buttonPin, - buttonStatesAction: buttonStatesAction, - ), - ); + // final List? buttonPinList = DevicePinListManager() + // .getFreePinsForSmartDeviceType(CbjDeviceTypes.button); + + // final int? buttonPin = + // buttonPinList?[0]?.pinAndPhysicalPinConfiguration; + + // final int deviceTypeCounter = numberOfThatTypeThatExist( + // smartDeviceBaseAbstractList, + // CbjDeviceTypes.button, + // ); + + // final Map>>? + // buttonStatesAction = + // ButtonObject.buttonDefaultStateAction(smartDeviceBaseAbstractList); + + // smartDeviceBaseAbstractList.add( + // ButtonObject( + // uuid, + // 'Button $deviceTypeCounter', + // buttonPin, + // buttonStatesAction: buttonStatesAction, + // ), + // ); } /// Setting up Button With Light else if (deviceType == CbjDeviceTypes.buttonWithLight) { - final List? lightPinAndButtonPin = - DevicePinListManager() - .getFreePinsForSmartDeviceType(CbjDeviceTypes.buttonWithLight); - - final int? buttonPin = - lightPinAndButtonPin?[0]?.pinAndPhysicalPinConfiguration; - - final int? buttonLightPin = - lightPinAndButtonPin?[1]?.pinAndPhysicalPinConfiguration; - - final int deviceTypeCounter = numberOfThatTypeThatExist( - smartDeviceBaseAbstractList, - CbjDeviceTypes.buttonWithLight, - ); - - final Map>>? - buttonStatesAction = - ButtonObject.buttonDefaultStateAction(smartDeviceBaseAbstractList); - - smartDeviceBaseAbstractList.add( - ButtonWithLightObject( - uuid, - 'Button With Light $deviceTypeCounter', - buttonPin, - buttonLightPin, - buttonStatesAction: buttonStatesAction, - ), - ); + // final List? lightPinAndButtonPin = + // DevicePinListManager() + // .getFreePinsForSmartDeviceType(CbjDeviceTypes.buttonWithLight); + + // final int? buttonPin = + // lightPinAndButtonPin?[0]?.pinAndPhysicalPinConfiguration; + + // final int? buttonLightPin = + // lightPinAndButtonPin?[1]?.pinAndPhysicalPinConfiguration; + + // final int deviceTypeCounter = numberOfThatTypeThatExist( + // smartDeviceBaseAbstractList, + // CbjDeviceTypes.buttonWithLight, + // ); + + // final Map>>? + // buttonStatesAction = + // ButtonObject.buttonDefaultStateAction(smartDeviceBaseAbstractList); + + // smartDeviceBaseAbstractList.add( + // ButtonWithLightObject( + // uuid, + // 'Button With Light $deviceTypeCounter', + // buttonPin, + // buttonLightPin, + // buttonStatesAction: buttonStatesAction, + // ), + // ); } } if (smartDeviceBaseAbstractList.isEmpty) { diff --git a/lib/infrastructure/datasources/core_d/manage_physical_components/device_pin_manager.dart b/lib/infrastructure/datasources/core_d/manage_physical_components/device_pin_manager.dart deleted file mode 100644 index d973f95..0000000 --- a/lib/infrastructure/datasources/core_d/manage_physical_components/device_pin_manager.dart +++ /dev/null @@ -1,299 +0,0 @@ -import 'package:cbj_integrations_controller/integrations_controller.dart'; -import 'package:cbj_smart_device/application/usecases/button_object_u/button_with_light_object.dart'; -import 'package:cbj_smart_device/application/usecases/button_object_u/simple_button_object.dart'; -import 'package:cbj_smart_device/application/usecases/devices_pin_configuration_u/device_configuration_base_class.dart'; -import 'package:cbj_smart_device/application/usecases/devices_pin_configuration_u/nano_pi_duo2_configuration/nano_pi_duo2_configuration.dart'; -import 'package:cbj_smart_device/application/usecases/devices_pin_configuration_u/nano_pi_neo/nano_pi_neo_configuration.dart'; -import 'package:cbj_smart_device/application/usecases/devices_pin_configuration_u/nano_pi_neo2/nano_pi_neo2_configuration.dart'; -import 'package:cbj_smart_device/application/usecases/devices_pin_configuration_u/nano_pi_neo_air/nano_pi_neo_air_configuration.dart'; -import 'package:cbj_smart_device/application/usecases/devices_pin_configuration_u/pin_information.dart'; -import 'package:cbj_smart_device/application/usecases/devices_pin_configuration_u/raspberry_pi3_model_b_rev_1_2/raspberry_pi3_model_b_rev_1_2_configuration.dart'; -import 'package:cbj_smart_device/application/usecases/smart_device_objects_u/abstracts_devices/smart_device_base_abstract.dart'; -import 'package:cbj_smart_device/domain/entities/core_e/enums_e.dart'; -import 'package:cbj_smart_device/utils.dart'; - -/// This class save all the configuration of the pins per device, -/// every device have different pin for each task, -/// and these class will give the correct pin for the task. -/// Also these class will manage unused pins for new connections and -/// will return free pins number for the required task. - -/// Also these class manage the pins, -/// and check if this pin is in the type that the user needs (gpio and more), -/// If pin is not in use and in the correct type that user expect it return the -/// number of the pin, else return -1 - -abstract class DevicePinListManagerAbstract { - /// Will save the type of the current physical device - static PhysicalDeviceType? physicalDeviceType; - - /// Will save the current physical device pin configuration - static DeviceConfigurationBaseClass? physicalDevice; - - /// Set recognize and set the physical device type in the singleton - Future setPhysicalDeviceType(); - - /// Return a list of free pins that are not taken, the list will consist of - /// the different pins types depending on the smart device type needed pins - List? getFreePinsForSmartDeviceType( - CbjDeviceTypes deviceType, - ); - - /// Return a list of free gpio pins that are not taken - PinInformation? getFreeGpioPins({List ignorePinsList}); - - PinInformation? getGpioPin(int pinNumber); - - PhysicalDeviceType? - convertPhysicalCbjDeviceTypestringToPhysicalDeviceTypeObject( - String physicalDeviceType, - ); -} - -class DevicePinListManager extends DevicePinListManagerAbstract { - /// Will save the type of the current physical device - static PhysicalDeviceType? physicalDeviceType; - - /// Will save the current physical device pin configuration - static DeviceConfigurationBaseClass? physicalDevice; - - @override - Future setPhysicalDeviceType() async { - final SystemCommandsManager systemCommandsManager = SystemCommandsManager(); - final String etcReleaseOutput = - await systemCommandsManager.getAllEtcReleaseFilesText(); - - final List etcReleaseFilesAsList = etcReleaseOutput.split('\n'); - try { - String deviceHostName = etcReleaseFilesAsList.firstWhere( - (etcReleaseSingleLine) => etcReleaseSingleLine.contains('BOARD'), - ); - deviceHostName = - deviceHostName.substring(deviceHostName.indexOf('=') + 1); - logger.i('Now'); - logger.i(deviceHostName); - deviceHostName = deviceHostName.replaceAll('-', '').replaceAll(' ', ''); - - physicalDeviceType = - convertPhysicalCbjDeviceTypestringToPhysicalDeviceTypeObject( - deviceHostName, - ); - - final String? raspberryPiVersion = - await systemCommandsManager.getRaspberryPiDeviceVersion(); - - if (physicalDeviceType == null && - raspberryPiVersion != null && - raspberryPiVersion - .toLowerCase() - .contains('Raspberry_Pi'.toLowerCase())) { - physicalDeviceType = PhysicalDeviceType.raspberryPi; - } - - logger.i('phys type is $physicalDeviceType'); - // Save the current physical device configuration to the - // physicalDevice variable - switch (physicalDeviceType) { - case PhysicalDeviceType.nanoPiDuo2: - { - physicalDevice = NanoPiDuo2Configuration(); - break; - } - case PhysicalDeviceType.nanoPiAir: - { - physicalDevice = NanoPiNEOAirConfiguration(); - break; - } - case PhysicalDeviceType.nanoPiNeo: - { - physicalDevice = NanoPiNeoConfiguration(); - break; - } - case PhysicalDeviceType.nanoPiNeo2: - { - physicalDevice = NanoPiNeo2Configuration(); - break; - } - case PhysicalDeviceType.raspberryPi: - { - final RaspberryPiType raspberryPiType = - EnumHelper.stringToRaspberryPiType(raspberryPiVersion!)!; - - switch (raspberryPiType) { - case RaspberryPiType.raspberryPi3ModelBRev1Underscore2: - { - logger.i('Raspberry Pi 3 Model B Rev 1.2 found'); - physicalDevice = - RaspberryPi3ModelBRev1Underscore2Configuration(); - break; - } - case RaspberryPiType.raspberryPi4ModelBRev1Underscore4: - { - logger.i('Raspberry Pi 4 Model B Rev 1.4 found'); - // Have same pin configuration as Pi 3 - physicalDevice = - RaspberryPi3ModelBRev1Underscore2Configuration(); - break; - } - default: - { - logger.i('Raspberry pi $raspberryPiVersion is not supported'); - logger.i('The software will not be able to control the pins'); - break; - } - } - break; - } - default: - { - logger.i('Detected deviceHostName $deviceHostName \n' - 'Entity is not supported, the software will not be able to ' - 'control the pins.'); - break; - } - } - } catch (e) { - logger.i('Board type does not exist'); - } - logger.i('This device is of type:' - ' ${EnumHelper.physicalDeviceTypeToString(physicalDeviceType)}'); - } - - /// Ask for gpio pin, if free return the pin number, - /// else return error number (negative numbers) - @override - PinInformation? getGpioPin(int? pinNumber) { - if (physicalDevice == null) { - logger.i('Error physical device is null'); - return null; - } - try { - final int isGpioFree = physicalDevice!.isGpioPinFree(pinNumber); - if (isGpioFree != 0) { - logger.i( - 'Gpio $pinNumber is not free, exist with error code $isGpioFree', - ); - return null; - } - - final PinInformation? pinInformation = - physicalDevice?.getGpioPin(pinNumber!); - - return pinInformation; - } catch (e) { - logger.i('This is the exception: $e'); - return null; - } - } - - /// Return physicalDeviceType object if - /// string physicalDeviceType exist (in general) else return null - @override - PhysicalDeviceType? - convertPhysicalCbjDeviceTypestringToPhysicalDeviceTypeObject( - String physicalDeviceType, - ) { - // Loop through all the physical devices types - for (final PhysicalDeviceType physicalDeviceTypeTemp - in PhysicalDeviceType.values) { - if (EnumHelper.physicalDeviceTypeToString(physicalDeviceTypeTemp) - .toLowerCase() == - physicalDeviceType.toLowerCase()) { - return physicalDeviceTypeTemp; // If physicalDeviceType string exist - // return the physicalDeviceType enum object - } - } - return null; - } - - @override - List? getFreePinsForSmartDeviceType( - CbjDeviceTypes deviceType, - ) { - List? neededPinTypesList; - - if (deviceType == CbjDeviceTypes.light || - deviceType == CbjDeviceTypes.blinds || - deviceType == CbjDeviceTypes.boiler) { - final dynamic smartDeviceBaseAbstract = - EnumHelper.deviceTypeToSmartDeviceBaseAbstractObject(deviceType); - neededPinTypesList = (smartDeviceBaseAbstract as SmartDeviceBaseAbstract) - .getNeededPinTypesList(); - } else if (deviceType == CbjDeviceTypes.button) { - neededPinTypesList = ButtonObject.neededPinTypesList(); - } else if (deviceType == CbjDeviceTypes.buttonWithLight) { - neededPinTypesList = ButtonWithLightObject.neededPinTypesList(); - } else { - logger.i('Getting device $deviceType pins requirement is not supported'); - return null; - } - - final List pinInformationList = []; - - for (final String pinType in neededPinTypesList) { - if (pinType.toLowerCase() == 'gpio') { - pinInformationList - .add(getFreeGpioPins(ignorePinsList: pinInformationList)); - } else { - throw UnimplementedError(); - } - } - - return pinInformationList; - } - - @override - PinInformation? getFreeGpioPins({List? ignorePinsList}) { - return physicalDevice?.getNextFreeGpioPin(ignorePinsList: ignorePinsList); - } -} - -class DevicePinListManagerPC extends DevicePinListManagerAbstract { - /// Will save the type of the current physical device - static PhysicalDeviceType? physicalDeviceType; - - /// Will save the current physical device pin configuration - static DeviceConfigurationBaseClass? physicalDevice; - - @override - PhysicalDeviceType? - convertPhysicalCbjDeviceTypestringToPhysicalDeviceTypeObject( - String physicalDeviceType, - ) { - // Loop through all the physical devices types - for (final PhysicalDeviceType physicalDeviceTypeTemp - in PhysicalDeviceType.values) { - if (EnumHelper.physicalDeviceTypeToString(physicalDeviceTypeTemp) - .toLowerCase() == - physicalDeviceType.toLowerCase()) { - return physicalDeviceTypeTemp; // If physicalDeviceType string exist - // return the physicalDeviceType enum object - } - } - return null; - } - - @override - PinInformation getGpioPin(int pinNumber) { - return PinInformation(); - } - - @override - List getFreePinsForSmartDeviceType( - CbjDeviceTypes deviceType, - ) { - logger.i('Computer does not give free pins, only smart device'); - throw UnimplementedError(); - } - - @override - PinInformation getFreeGpioPins({List? ignorePinsList}) { - logger.i('Computer does not give free gpio pins, only smart device'); - throw UnimplementedError(); - } - - @override - Future setPhysicalDeviceType() { - return Future.value('PC'); - } -} diff --git a/lib/infrastructure/datasources/core_d/microphone/python_class_local.dart b/lib/infrastructure/datasources/core_d/microphone/python_class_local.dart index 397be30..84bde39 100644 --- a/lib/infrastructure/datasources/core_d/microphone/python_class_local.dart +++ b/lib/infrastructure/datasources/core_d/microphone/python_class_local.dart @@ -3,7 +3,7 @@ import 'dart:io'; import 'package:cbj_smart_device/utils.dart'; class RecognitionClass { - Future listenToLightCommend() async { + Future listenToLightCommend() async { final List pythonCommends = []; pythonCommends.add('-c'); pythonCommends.add(''' diff --git a/lib/infrastructure/datasources/hive_d/hive_d.dart b/lib/infrastructure/datasources/hive_d/hive_d.dart index d649eeb..bddfd37 100644 --- a/lib/infrastructure/datasources/hive_d/hive_d.dart +++ b/lib/infrastructure/datasources/hive_d/hive_d.dart @@ -115,7 +115,7 @@ class IsarD { return null; } - Future saveAllDevices( + Future saveAllDevices( Map> smartDevicesMapList, ) async { try { @@ -147,7 +147,7 @@ class IsarD { return; } - Future saveListOfDatabaseInformation( + Future saveListOfDatabaseInformation( Map firebaseAccountsInformationMap, ) async { try { diff --git a/lib/infrastructure/datasources/local_db_d/local_db_d.dart b/lib/infrastructure/datasources/local_db_d/local_db_d.dart index 814d13a..edfff72 100644 --- a/lib/infrastructure/datasources/local_db_d/local_db_d.dart +++ b/lib/infrastructure/datasources/local_db_d/local_db_d.dart @@ -24,7 +24,7 @@ class LocalDbD { return _isarD!.getListOfDatabaseInformation(); } - Future saveAllDevices( + Future saveAllDevices( List smartDevicesList, ) async { // TODO: We need to find better saving method since devices will save diff --git a/lib/infrastructure/repositories/local_db_r/local_db_r.dart b/lib/infrastructure/repositories/local_db_r/local_db_r.dart index fbb592b..b670559 100644 --- a/lib/infrastructure/repositories/local_db_r/local_db_r.dart +++ b/lib/infrastructure/repositories/local_db_r/local_db_r.dart @@ -45,17 +45,17 @@ class LocalDbR { ), ); case CbjDeviceTypes.boiler: - final int? boilerPinNumber = - values[1] == '' ? null : int.parse(values[1]!); - final int? boilerButtonPinNumber = - values[2] == '' ? null : int.parse(values[2]!); + // final int? boilerPinNumber = + // values[1] == '' ? null : int.parse(values[1]!); + // final int? boilerButtonPinNumber = + // values[2] == '' ? null : int.parse(values[2]!); logger.i('Adding from local db boiler object'); smartDeviceBaseAbstractList.add( BoilerObject( deviceUuid, 'Boiler name missing', - boilerPinNumber, - boilerButtonPinNumber, + // boilerPinNumber, + // boilerButtonPinNumber, ), ); case CbjDeviceTypes.blinds: @@ -68,14 +68,14 @@ class LocalDbR { values[1] == '' ? null : int.parse(values[1]!); final int? onOffButtonPinNumber = values[2] == '' ? null : int.parse(values[2]!); - final int? blindsUpPin = - values[3] == '' ? null : int.parse(values[3]!); - final int? upButtonPinNumber = - values[4] == '' ? null : int.parse(values[4]!); - final int? blindsDownPin = - values[5] == '' ? null : int.parse(values[5]!); - final int? downButtonPinNumber = - values[6] == '' ? null : int.parse(values[6]!); + // final int? blindsUpPin = + // values[3] == '' ? null : int.parse(values[3]!); + // final int? upButtonPinNumber = + // values[4] == '' ? null : int.parse(values[4]!); + // final int? blindsDownPin = + // values[5] == '' ? null : int.parse(values[5]!); + // final int? downButtonPinNumber = + // values[6] == '' ? null : int.parse(values[6]!); smartDeviceBaseAbstractList.add( BlindsObject( @@ -84,18 +84,18 @@ class LocalDbR { onOffPinNumber, onOffButtonPinNumber, // onOffButtonPinNumber - blindsUpPin, + // blindsUpPin, // blindsUpPin - upButtonPinNumber, + // upButtonPinNumber, // upButtonPinNumber - blindsDownPin, + // blindsDownPin, // blindsDownPin - downButtonPinNumber, // downButtonPinNumber + // downButtonPinNumber, // downButtonPinNumber ), ); case CbjDeviceTypes.button: - final int? buttonPinNumber = - values[1] == '' ? null : int.parse(values[1]!); + // final int? buttonPinNumber = + // values[1] == '' ? null : int.parse(values[1]!); logger.i('Adding from local db button object'); final Map saveAllDevices( + Future saveAllDevices( List smartDevicesList, ) async { await _localDbD.saveAllDevices(smartDevicesList); diff --git a/pubspec.yaml b/pubspec.yaml index 580c532..45829ab 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,8 +9,8 @@ environment: dependencies: cbj_integrations_controller: -# path: ../cbj_integrations_controller - git: https://github.com/CyBear-Jinni/cbj_integrations_controller.git + path: ../cbj_integrations_controller + # git: https://github.com/CyBear-Jinni/cbj_integrations_controller.git # Functional programming thingies, let you use multiple return types dartz: ^0.10.1 # Convert enum to string