Skip to content

Commit

Permalink
Improve pub.dev score with better docs
Browse files Browse the repository at this point in the history
  • Loading branch information
alanmosely committed Feb 25, 2023
1 parent 6288eff commit ced5d3b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 7 deletions.
20 changes: 20 additions & 0 deletions lib/esp_provisioning_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<EspProvisioningEvent, EspProvisioningState> {
EspProvisioningBloc() : super(const EspProvisioningState()) {
Expand All @@ -16,9 +18,15 @@ class EspProvisioningBloc
on<EspProvisioningEventWifiSelected>(_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<EspProvisioningState>): This is the function that you use to emit a new state
Future<void> _onStart(
EspProvisioningEventStart event,
Emitter<EspProvisioningState> emit,
Expand All @@ -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<EspProvisioningState>): This is the function that you use to emit a new state
Future<void> _onBleSelected(
EspProvisioningEventBleSelected event,
Emitter<EspProvisioningState> emit,
Expand Down Expand Up @@ -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<EspProvisioningState>): This is the function that you use to emit a new state
Future<void> _onWifiSelected(
EspProvisioningEventWifiSelected event,
Emitter<EspProvisioningState> emit,
Expand Down
3 changes: 1 addition & 2 deletions lib/esp_provisioning_constants.dart
Original file line number Diff line number Diff line change
@@ -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';
4 changes: 4 additions & 0 deletions lib/esp_provisioning_event.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import 'package:equatable/equatable.dart';

/// An abstract class that represents events across the provisioning process
abstract class EspProvisioningEvent extends Equatable {
const EspProvisioningEvent();

@override
List<Object> get props => [];
}

/// A class that represents the start of the provisioning process
class EspProvisioningEventStart extends EspProvisioningEvent {
final String bluetoothDevicePrefix;

Expand All @@ -16,6 +18,7 @@ class EspProvisioningEventStart extends EspProvisioningEvent {
List<Object> 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;
Expand All @@ -27,6 +30,7 @@ class EspProvisioningEventBleSelected extends EspProvisioningEvent {
List<Object> 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;
Expand Down
8 changes: 8 additions & 0 deletions lib/esp_provisioning_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 3 additions & 0 deletions lib/esp_provisioning_state.dart
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down
8 changes: 3 additions & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit ced5d3b

Please sign in to comment.