mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
ble-pybricks-service: rename statusReportEvent
New name is didReceiveStatusReport which is more consistent with existing naming patterns.
This commit is contained in:
@@ -187,8 +187,8 @@ export type BlePybricksServiceCommandAction =
|
||||
|
||||
/** Action types for events received from the Pybricks service control characteristic. */
|
||||
export enum BlePybricksServiceEventActionType {
|
||||
/** A status report event. */
|
||||
StatusReport = 'blePybricksServiceEvent.action.statusReport',
|
||||
/** A status report event was received. */
|
||||
DidReceiveStatusReport = 'blePybricksServiceEvent.action.didReceiveStatusReport',
|
||||
/** A pseudo-event indicating there was a protocol error (not directly received from the hub). */
|
||||
ProtocolError = 'blePybricksServiceEvent.action.protocolError',
|
||||
}
|
||||
@@ -197,7 +197,7 @@ export enum BlePybricksServiceEventActionType {
|
||||
* Action that represents a status report event received from the hub.
|
||||
*/
|
||||
export type BlePybricksServiceEventStatusReportAction =
|
||||
Action<BlePybricksServiceEventActionType.StatusReport> & {
|
||||
Action<BlePybricksServiceEventActionType.DidReceiveStatusReport> & {
|
||||
statusFlags: number;
|
||||
};
|
||||
|
||||
@@ -205,10 +205,13 @@ export type BlePybricksServiceEventStatusReportAction =
|
||||
* Action that represents a status report event received from the hub.
|
||||
* @param statusFlags The status flags.
|
||||
*/
|
||||
export function statusReportEvent(
|
||||
export function didReceiveStatusReport(
|
||||
statusFlags: number,
|
||||
): BlePybricksServiceEventStatusReportAction {
|
||||
return { type: BlePybricksServiceEventActionType.StatusReport, statusFlags };
|
||||
return {
|
||||
type: BlePybricksServiceEventActionType.DidReceiveStatusReport,
|
||||
statusFlags,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,11 +6,11 @@ import {
|
||||
didFailToSendCommand,
|
||||
didFailToWriteCommand,
|
||||
didNotifyEvent,
|
||||
didReceiveStatusReport,
|
||||
didSendCommand,
|
||||
didWriteCommand,
|
||||
eventProtocolError,
|
||||
sendStopUserProgramCommand,
|
||||
statusReportEvent,
|
||||
writeCommand,
|
||||
} from './actions';
|
||||
import { CommandType, ProtocolError } from './protocol';
|
||||
@@ -101,7 +101,7 @@ describe('event decoder', () => {
|
||||
0x00, // .
|
||||
0x00, // flags count MSB
|
||||
],
|
||||
statusReportEvent(0x00000001),
|
||||
didReceiveStatusReport(0x00000001),
|
||||
],
|
||||
])('decode %s event', async (_n, message, expected) => {
|
||||
const saga = new AsyncSaga(blePybricksService);
|
||||
|
||||
@@ -21,9 +21,9 @@ import {
|
||||
BlePybricksServiceDidNotifyEventAction,
|
||||
BlePybricksServiceDidWriteCommandAction,
|
||||
didFailToSendCommand,
|
||||
didReceiveStatusReport,
|
||||
didSendCommand,
|
||||
eventProtocolError,
|
||||
statusReportEvent,
|
||||
writeCommand,
|
||||
} from './actions';
|
||||
import {
|
||||
@@ -92,7 +92,7 @@ function* decodeResponse(action: BlePybricksServiceDidNotifyEventAction): Genera
|
||||
const responseType = getEventType(action.value);
|
||||
switch (responseType) {
|
||||
case EventType.StatusReport:
|
||||
yield* put(statusReportEvent(parseStatusReport(action.value)));
|
||||
yield* put(didReceiveStatusReport(parseStatusReport(action.value)));
|
||||
break;
|
||||
default:
|
||||
throw new ProtocolError(
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { firmwareVersion } from '@pybricks/firmware';
|
||||
import { Action } from '../actions';
|
||||
import { statusReportEvent } from '../ble-pybricks-service/actions';
|
||||
import { didReceiveStatusReport } from '../ble-pybricks-service/actions';
|
||||
import { Status, statusToFlag } from '../ble-pybricks-service/protocol';
|
||||
import { didConnect, didDisconnect } from '../ble/actions';
|
||||
import {
|
||||
@@ -108,13 +108,13 @@ describe('runtime', () => {
|
||||
).toBe(HubRuntimeState.Idle);
|
||||
});
|
||||
|
||||
test('statusReportEvent', () => {
|
||||
test('didReceiveStatusReport', () => {
|
||||
// don't ever expect this to happen in practice since we can't receive
|
||||
// updates while disconnected
|
||||
expect(
|
||||
reducers(
|
||||
{ runtime: HubRuntimeState.Disconnected } as State,
|
||||
statusReportEvent(statusToFlag(Status.UserProgramRunning)),
|
||||
didReceiveStatusReport(statusToFlag(Status.UserProgramRunning)),
|
||||
).runtime,
|
||||
).toBe(HubRuntimeState.Disconnected);
|
||||
|
||||
@@ -122,7 +122,7 @@ describe('runtime', () => {
|
||||
expect(
|
||||
reducers(
|
||||
{ runtime: HubRuntimeState.Loading } as State,
|
||||
statusReportEvent(statusToFlag(Status.UserProgramRunning)),
|
||||
didReceiveStatusReport(statusToFlag(Status.UserProgramRunning)),
|
||||
).runtime,
|
||||
).toBe(HubRuntimeState.Loading);
|
||||
|
||||
@@ -130,21 +130,23 @@ describe('runtime', () => {
|
||||
expect(
|
||||
reducers(
|
||||
{ runtime: HubRuntimeState.Loaded } as State,
|
||||
statusReportEvent(statusToFlag(Status.UserProgramRunning)),
|
||||
didReceiveStatusReport(statusToFlag(Status.UserProgramRunning)),
|
||||
).runtime,
|
||||
).toBe(HubRuntimeState.Running);
|
||||
|
||||
// really short program run finished before receiving download finished
|
||||
expect(
|
||||
reducers({ runtime: HubRuntimeState.Loaded } as State, statusReportEvent(0))
|
||||
.runtime,
|
||||
reducers(
|
||||
{ runtime: HubRuntimeState.Loaded } as State,
|
||||
didReceiveStatusReport(0),
|
||||
).runtime,
|
||||
).toBe(HubRuntimeState.Idle);
|
||||
|
||||
// normal operation - user program stopped
|
||||
expect(
|
||||
reducers(
|
||||
{ runtime: HubRuntimeState.Running } as State,
|
||||
statusReportEvent(0),
|
||||
didReceiveStatusReport(0),
|
||||
).runtime,
|
||||
).toBe(HubRuntimeState.Idle);
|
||||
});
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ const runtime: Reducer<HubRuntimeState, Action> = (
|
||||
return state;
|
||||
}
|
||||
return HubRuntimeState.Idle;
|
||||
case BlePybricksServiceEventActionType.StatusReport:
|
||||
case BlePybricksServiceEventActionType.DidReceiveStatusReport:
|
||||
// The loading state is determined solely by the IDE, so we can't
|
||||
// let the hub status interfere with it.
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user