mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
ble: add id and name to didConnect action
This commit is contained in:
@@ -409,7 +409,7 @@ function* connect(_action: BleDeviceConnectAction): Generator {
|
||||
|
||||
tasks.push(yield* takeEvery(BleUartActionType.Write, writeUart, uartRxChar));
|
||||
|
||||
yield* put(didConnect());
|
||||
yield* put(didConnect(device.id, device.name || ''));
|
||||
|
||||
// wait for disconnection
|
||||
yield* takeMaybe(disconnectChannel);
|
||||
|
||||
+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(
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2021 The Pybricks Authors
|
||||
|
||||
import { firmwareVersion } from '@pybricks/firmware';
|
||||
import { Action } from '../actions';
|
||||
import { didReceiveStatusReport } from '../ble-pybricks-service/actions';
|
||||
import { Status, statusToFlag } from '../ble-pybricks-service/protocol';
|
||||
@@ -28,8 +27,10 @@ test('initial state', () => {
|
||||
describe('runtime', () => {
|
||||
test('', () => {
|
||||
expect(
|
||||
reducers({ runtime: HubRuntimeState.Disconnected } as State, didConnect())
|
||||
.runtime,
|
||||
reducers(
|
||||
{ runtime: HubRuntimeState.Disconnected } as State,
|
||||
didConnect('test-id', 'Test Name'),
|
||||
).runtime,
|
||||
).toBe(HubRuntimeState.Unknown);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user