mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-15 02:54:07 +00:00
ble-device-info-service: add actions
This adds actions that are triggered when the device info service characteristics are read.
This commit is contained in:
+3
-6
@@ -44,16 +44,13 @@ export function connect(): BleDeviceConnectAction {
|
||||
return { type: BleDeviceActionType.Connect };
|
||||
}
|
||||
|
||||
export type BleDeviceDidConnectAction = Action<BleDeviceActionType.DidConnect> & {
|
||||
firmwareVersion: string;
|
||||
};
|
||||
export type BleDeviceDidConnectAction = Action<BleDeviceActionType.DidConnect>;
|
||||
|
||||
/**
|
||||
* Creates an action that indicates a device was connected.
|
||||
* @param firmwareVersion The firmware version of the hub (e.g. 3.0.0a1)
|
||||
*/
|
||||
export function didConnect(firmwareVersion: string): BleDeviceDidConnectAction {
|
||||
return { type: BleDeviceActionType.DidConnect, firmwareVersion };
|
||||
export function didConnect(): BleDeviceDidConnectAction {
|
||||
return { type: BleDeviceActionType.DidConnect };
|
||||
}
|
||||
|
||||
export enum BleDeviceFailToConnectReasonType {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2021 The Pybricks Authors
|
||||
|
||||
import { firmwareVersion } from '@pybricks/firmware';
|
||||
import { Action } from '../actions';
|
||||
import {
|
||||
BleDeviceDidFailToConnectReason,
|
||||
@@ -30,10 +29,8 @@ test('connection', () => {
|
||||
.connection,
|
||||
).toBe(BleConnectionState.Connecting);
|
||||
expect(
|
||||
reducers(
|
||||
{ connection: BleConnectionState.Connecting } as State,
|
||||
didConnect(firmwareVersion),
|
||||
).connection,
|
||||
reducers({ connection: BleConnectionState.Connecting } as State, didConnect())
|
||||
.connection,
|
||||
).toBe(BleConnectionState.Connected);
|
||||
expect(
|
||||
reducers(
|
||||
|
||||
Reference in New Issue
Block a user