mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 17:45:22 +00:00
add a failed to disconnect action
This commit is contained in:
+15
-1
@@ -29,6 +29,10 @@ export enum BleDeviceActionType {
|
||||
* The device was disconnected.
|
||||
*/
|
||||
DidDisconnect = 'ble.device.action.didDisconnect',
|
||||
/**
|
||||
* The device fail to disconnect.
|
||||
*/
|
||||
DidFailToDisconnect = 'ble.device.action.didFailToDisconnect',
|
||||
}
|
||||
|
||||
export type BleDeviceConnectAction = Action<BleDeviceActionType.Connect>;
|
||||
@@ -114,6 +118,15 @@ export function didDisconnect(): BleDeviceDidDisconnectAction {
|
||||
return { type: BleDeviceActionType.DidDisconnect };
|
||||
}
|
||||
|
||||
export type BleDeviceDidFailToDisconnectAction = Action<BleDeviceActionType.DidFailToDisconnect>;
|
||||
|
||||
/**
|
||||
* Creates an action that indicates a device failed to disconnect.
|
||||
*/
|
||||
export function didFailToDisconnect(): BleDeviceDidFailToDisconnectAction {
|
||||
return { type: BleDeviceActionType.DidFailToDisconnect };
|
||||
}
|
||||
|
||||
/**
|
||||
* Common type for all BLE connection actions.
|
||||
*/
|
||||
@@ -122,7 +135,8 @@ export type BLEConnectAction =
|
||||
| BleDeviceDidConnectAction
|
||||
| BleDeviceDidFailToConnectAction
|
||||
| BleDeviceDisconnectAction
|
||||
| BleDeviceDidDisconnectAction;
|
||||
| BleDeviceDidDisconnectAction
|
||||
| BleDeviceDidFailToDisconnectAction;
|
||||
|
||||
/**
|
||||
* High-level BLE actions.
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
didConnect,
|
||||
didDisconnect,
|
||||
didFailToConnect,
|
||||
didFailToDisconnect,
|
||||
disconnect,
|
||||
} from './actions';
|
||||
import reducers, { BleConnectionState } from './reducers';
|
||||
@@ -47,4 +48,10 @@ test('connection', () => {
|
||||
didDisconnect(),
|
||||
).connection,
|
||||
).toBe(BleConnectionState.Disconnected);
|
||||
expect(
|
||||
reducers(
|
||||
{ connection: BleConnectionState.Disconnecting } as State,
|
||||
didFailToDisconnect(),
|
||||
).connection,
|
||||
).toBe(BleConnectionState.Connected);
|
||||
});
|
||||
|
||||
@@ -38,6 +38,7 @@ const connection: Reducer<BleConnectionState, Action> = (
|
||||
case BleDeviceActionType.Connect:
|
||||
return BleConnectionState.Connecting;
|
||||
case BleDeviceActionType.DidConnect:
|
||||
case BleDeviceActionType.DidFailToDisconnect:
|
||||
return BleConnectionState.Connected;
|
||||
case BleDeviceActionType.Disconnect:
|
||||
return BleConnectionState.Disconnecting;
|
||||
|
||||
Reference in New Issue
Block a user