From 4e2902730abab5dca8f8a5a962d750fa86614e44 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Mon, 5 Jul 2021 10:22:26 -0500 Subject: [PATCH] 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: 7a5aa7589443bc11d77ff62c91535407918e29ba --- src/hub/reducers.test.ts | 9 ++++++++- src/hub/reducers.ts | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/hub/reducers.test.ts b/src/hub/reducers.test.ts index 8c403ae9..4b1e2dc0 100644 --- a/src/hub/reducers.test.ts +++ b/src/hub/reducers.test.ts @@ -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( diff --git a/src/hub/reducers.ts b/src/hub/reducers.ts index 5f87654b..934e3d03 100644 --- a/src/hub/reducers.ts +++ b/src/hub/reducers.ts @@ -43,6 +43,8 @@ const runtime: Reducer = ( action, ) => { switch (action.type) { + case BleDeviceActionType.DidConnect: + return HubRuntimeState.Unknown; case BleDeviceActionType.DidDisconnect: return HubRuntimeState.Disconnected; case HubActionType.DidStartDownload: