From 56829a502c3525ae193e45a20521e6ee09a5f6cf Mon Sep 17 00:00:00 2001 From: David Lechner Date: Wed, 10 Mar 2021 11:11:49 -0600 Subject: [PATCH] ble-pybricks-service/sagas: fix filtering of command send completions Since didSend and didFailToSend are part of the same enum as the command send actions types, we have to filter them out when subscribing to the send actions. --- src/ble-pybricks-service/sagas.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ble-pybricks-service/sagas.ts b/src/ble-pybricks-service/sagas.ts index 7f035155..f2f611b3 100644 --- a/src/ble-pybricks-service/sagas.ts +++ b/src/ble-pybricks-service/sagas.ts @@ -41,10 +41,16 @@ import { function* encodeRequest(): Generator { // Using a while loop to serialize sending data to avoid "busy" errors. + const sendCommands: readonly BlePybricksServiceCommandActionType[] = Object.values( + BlePybricksServiceCommandActionType, + ).filter( + (x) => + x !== BlePybricksServiceCommandActionType.DidSend && + x != BlePybricksServiceCommandActionType.DidFailToSend, + ); + const chan = yield* actionChannel((a: Action) => - Object.values(BlePybricksServiceCommandActionType).includes( - a.type as BlePybricksServiceCommandActionType, - ), + sendCommands.includes(a.type as BlePybricksServiceCommandActionType), ); while (true) { @@ -56,7 +62,7 @@ function* encodeRequest(): Generator { break; /* istanbul ignore next: should not be possible to reach */ default: - console.error(`Unknown Pybricks service command ${action}`); + console.error(`Unknown Pybricks service command ${action.type}`); continue; }