diff --git a/lib/esp_provisioning_bloc.dart b/lib/esp_provisioning_bloc.dart index 50818c9..d6158cf 100644 --- a/lib/esp_provisioning_bloc.dart +++ b/lib/esp_provisioning_bloc.dart @@ -8,6 +8,8 @@ import 'esp_provisioning_event.dart'; import 'esp_provisioning_service.dart'; import 'esp_provisioning_state.dart'; +/// The EspProvisioningBloc class is a BLoC that handles EspProvisioningEvents and emits +/// EspProvisioningStates class EspProvisioningBloc extends Bloc { EspProvisioningBloc() : super(const EspProvisioningState()) { @@ -16,9 +18,15 @@ class EspProvisioningBloc on(_onWifiSelected); } +/// A late final variable that is assigned to the instance of the EspProvisioningService class. late final FlutterEspBleProv? espProvisioningService = EspProvisioningService.getInstance(); +/// _onStart() is a function that is called when the EspProvisioningEventStart event is emitted +/// +/// Args: +/// event (EspProvisioningEventStart): This is the event that was emitted by the UI +/// emit (Emitter): This is the function that you use to emit a new state Future _onStart( EspProvisioningEventStart event, Emitter emit, @@ -45,6 +53,12 @@ class EspProvisioningBloc } } + /// _onBleSelected() is a function that is called when the user selects a bluetooth device from the + /// list of available bluetooth devices + /// + /// Args: + /// event (EspProvisioningEventBleSelected): This is the event that was emitted by the UI + /// emit (Emitter): This is the function that you use to emit a new state Future _onBleSelected( EspProvisioningEventBleSelected event, Emitter emit, @@ -81,6 +95,12 @@ class EspProvisioningBloc } } + /// _onWifiSelected() is called when the user selects a wifi network from the list of available + /// networks. It then calls the provisionWifi() function in the EspProvisioningService class + /// + /// Args: + /// event (EspProvisioningEventWifiSelected): This is the event that was emitted by the UI + /// emit (Emitter): This is the function that you use to emit a new state Future _onWifiSelected( EspProvisioningEventWifiSelected event, Emitter emit, diff --git a/lib/esp_provisioning_constants.dart b/lib/esp_provisioning_constants.dart index d272641..ce2e915 100644 --- a/lib/esp_provisioning_constants.dart +++ b/lib/esp_provisioning_constants.dart @@ -1,5 +1,4 @@ // ignore_for_file: constant_identifier_names +/// Time before a request to the FlutterEspBleProv plugin times out, in seconds const TIMEOUT = 10; -const DEVICE_PREFIX = 'PROV'; -const PROOF_OF_POSSESSION = 'abcd1234'; diff --git a/lib/esp_provisioning_event.dart b/lib/esp_provisioning_event.dart index 8ee8f80..2c233c0 100644 --- a/lib/esp_provisioning_event.dart +++ b/lib/esp_provisioning_event.dart @@ -1,5 +1,6 @@ import 'package:equatable/equatable.dart'; +/// An abstract class that represents events across the provisioning process abstract class EspProvisioningEvent extends Equatable { const EspProvisioningEvent(); @@ -7,6 +8,7 @@ abstract class EspProvisioningEvent extends Equatable { List get props => []; } +/// A class that represents the start of the provisioning process class EspProvisioningEventStart extends EspProvisioningEvent { final String bluetoothDevicePrefix; @@ -16,6 +18,7 @@ class EspProvisioningEventStart extends EspProvisioningEvent { List get props => [bluetoothDevicePrefix]; } +/// A class that represents the selection of a ble device within the provisioning process class EspProvisioningEventBleSelected extends EspProvisioningEvent { final String bluetoothDevice; final String proofOfPossession; @@ -27,6 +30,7 @@ class EspProvisioningEventBleSelected extends EspProvisioningEvent { List get props => [bluetoothDevice, proofOfPossession]; } +/// A class that represents the selection of a wifi network within the provisioning process class EspProvisioningEventWifiSelected extends EspProvisioningEvent { final String bluetoothDevice; final String proofOfPossession; diff --git a/lib/esp_provisioning_service.dart b/lib/esp_provisioning_service.dart index bd217e8..9954a87 100644 --- a/lib/esp_provisioning_service.dart +++ b/lib/esp_provisioning_service.dart @@ -2,9 +2,17 @@ import 'dart:developer'; import 'package:esp_provisioning_wifi/src/flutter_esp_ble_prov/flutter_esp_ble_prov.dart'; +/// The EspProvisioningService class is a singleton that returns an instance of the FlutterEspBleProv +/// class class EspProvisioningService { + /// A static variable that is used to store the instance of the class static FlutterEspBleProv? _instance; +/// If the instance is null, create a new instance and return it. Otherwise, return the existing +/// instance +/// +/// Returns: +/// The instance of the class static FlutterEspBleProv? getInstance() { _instance ??= FlutterEspBleProv(); log('EspProvisioningService started'); diff --git a/lib/esp_provisioning_state.dart b/lib/esp_provisioning_state.dart index 69eb6bb..3333439 100644 --- a/lib/esp_provisioning_state.dart +++ b/lib/esp_provisioning_state.dart @@ -1,5 +1,6 @@ import 'package:equatable/equatable.dart'; +/// A list of all the possible states that the ESP provisioning can be in enum EspProvisioningStatus { initial, bleScanned, @@ -10,6 +11,8 @@ enum EspProvisioningStatus { error, } +/// EspProvisioningState is a class that contains a bunch of properties that are used to store the state +/// of the ESP provisioning class EspProvisioningState extends Equatable { const EspProvisioningState({ this.status = EspProvisioningStatus.initial, diff --git a/pubspec.yaml b/pubspec.yaml index 8a86c7a..84f5c64 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,9 +1,7 @@ name: esp_provisioning_wifi -description: | - Bloc wrapper over 'flutter_esp_ble_prov' which provisions WiFi on - Espressif ESP32 devices over Bluetooth. It uses the 'esp-idf-provisioning-android' - and 'esp-idf-provisioning-ios' Espressif-provided provisioning libraries. -version: 0.0.1 +description: Bloc wrapper over 'flutter_esp_ble_prov' which provisions WiFi on + Espressif ESP32 devices over Bluetooth using Espressif-provided provisioning libraries. +version: 0.0.2 repository: https://github.com/alanmosely/esp_provisioning_wifi issue_tracker: https://github.com/alanmosely/esp_provisioning_wifi/issues