mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-14 10:35:11 +00:00
ble: add id and name to didConnect action
This commit is contained in:
+8
-3
@@ -44,13 +44,18 @@ export function connect(): BleDeviceConnectAction {
|
||||
return { type: BleDeviceActionType.Connect };
|
||||
}
|
||||
|
||||
export type BleDeviceDidConnectAction = Action<BleDeviceActionType.DidConnect>;
|
||||
export type BleDeviceDidConnectAction = Action<BleDeviceActionType.DidConnect> & {
|
||||
/** A unique identifier for the connected hub. */
|
||||
id: string;
|
||||
/** A user-displayable name for the connected hub. */
|
||||
name: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an action that indicates a device was connected.
|
||||
*/
|
||||
export function didConnect(): BleDeviceDidConnectAction {
|
||||
return { type: BleDeviceActionType.DidConnect };
|
||||
export function didConnect(id: string, name: string): BleDeviceDidConnectAction {
|
||||
return { type: BleDeviceActionType.DidConnect, id, name };
|
||||
}
|
||||
|
||||
export enum BleDeviceFailToConnectReasonType {
|
||||
|
||||
@@ -29,8 +29,10 @@ test('connection', () => {
|
||||
.connection,
|
||||
).toBe(BleConnectionState.Connecting);
|
||||
expect(
|
||||
reducers({ connection: BleConnectionState.Connecting } as State, didConnect())
|
||||
.connection,
|
||||
reducers(
|
||||
{ connection: BleConnectionState.Connecting } as State,
|
||||
didConnect('test-id', 'Test Name'),
|
||||
).connection,
|
||||
).toBe(BleConnectionState.Connected);
|
||||
expect(
|
||||
reducers(
|
||||
|
||||
Reference in New Issue
Block a user