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.
This commit is contained in:
David Lechner
2021-03-10 11:19:06 -06:00
parent 684df491e0
commit 56829a502c
+10 -4
View File
@@ -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<BlePybricksServiceCommandAction>((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;
}