hub: fix buttons not enabled after connection

A previous commit broke buttons after connecting since state all state
transitions were changed to be ignored if the current state was
"disconnected". This made it impossible to get into any other state.

This brings back use of the "unknown" state upon initial connection
to provide a path out of the "disconnected" state.

Fixes: 7a5aa75894
This commit is contained in:
David Lechner
2021-07-06 10:53:56 -05:00
committed by David Lechner
parent d95c550248
commit 4e2902730a
2 changed files with 10 additions and 1 deletions
+8 -1
View File
@@ -4,7 +4,7 @@
import { Action } from '../actions';
import { statusReportEvent } from '../ble-pybricks-service/actions';
import { Status, statusToFlag } from '../ble-pybricks-service/protocol';
import { didDisconnect } from '../ble/actions';
import { didConnect, didDisconnect } from '../ble/actions';
import {
didFailToFinishDownload,
didFinishDownload,
@@ -25,6 +25,13 @@ test('initial state', () => {
});
describe('runtime', () => {
test('', () => {
expect(
reducers({ runtime: HubRuntimeState.Disconnected } as State, didConnect())
.runtime,
).toBe(HubRuntimeState.Unknown);
});
test.each(Object.values(HubRuntimeState))('didDisconnect', (startingState) => {
// all states are overridden by disconnect
expect(
+2
View File
@@ -43,6 +43,8 @@ const runtime: Reducer<HubRuntimeState, Action> = (
action,
) => {
switch (action.type) {
case BleDeviceActionType.DidConnect:
return HubRuntimeState.Unknown;
case BleDeviceActionType.DidDisconnect:
return HubRuntimeState.Disconnected;
case HubActionType.DidStartDownload: