mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 09:36:27 +00:00
hub/reducers: change hub runtime state when disconnecting
When disconnect is requested, we should not longer allow interacting with the hub, so we say the runtime state is unknown until it is confirmed to be disconnected. Fixes: https://github.com/pybricks/support/issues/1021
This commit is contained in:
committed by
David Lechner
parent
93cce0352f
commit
19f6862bb5
@@ -4,6 +4,11 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
- Fixed run button active while hub is disconnecting ([support#1021]).
|
||||
|
||||
[support#1021]: https://github.com/pybricks/support/issues/1021
|
||||
|
||||
## [2.2.0-beta.2] - 2023-03-24
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2021-2022 The Pybricks Authors
|
||||
// Copyright (c) 2021-2023 The Pybricks Authors
|
||||
|
||||
import { AnyAction } from 'redux';
|
||||
import { bleDidConnectPybricks, bleDidDisconnectPybricks } from '../ble/actions';
|
||||
import {
|
||||
bleDidConnectPybricks,
|
||||
bleDidDisconnectPybricks,
|
||||
bleDisconnectPybricks,
|
||||
} from '../ble/actions';
|
||||
import { didReceiveStatusReport } from '../ble-pybricks-service/actions';
|
||||
import { Status, statusToFlag } from '../ble-pybricks-service/protocol';
|
||||
import {
|
||||
@@ -39,6 +43,17 @@ describe('runtime', () => {
|
||||
).toBe(HubRuntimeState.Unknown);
|
||||
});
|
||||
|
||||
test.each(Object.values(HubRuntimeState))(
|
||||
'bleDisconnectPybricks',
|
||||
(startingState) => {
|
||||
// all states are overridden by disconnect
|
||||
expect(
|
||||
reducers({ runtime: startingState } as State, bleDisconnectPybricks())
|
||||
.runtime,
|
||||
).toBe(HubRuntimeState.Unknown);
|
||||
},
|
||||
);
|
||||
|
||||
test.each(Object.values(HubRuntimeState))('didDisconnect', (startingState) => {
|
||||
// all states are overridden by disconnect
|
||||
expect(
|
||||
|
||||
+11
-2
@@ -1,9 +1,13 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2020-2022 The Pybricks Authors
|
||||
// Copyright (c) 2020-2023 The Pybricks Authors
|
||||
|
||||
import { Reducer, combineReducers } from 'redux';
|
||||
import * as semver from 'semver';
|
||||
import { bleDidConnectPybricks, bleDidDisconnectPybricks } from '../ble/actions';
|
||||
import {
|
||||
bleDidConnectPybricks,
|
||||
bleDidDisconnectPybricks,
|
||||
bleDisconnectPybricks,
|
||||
} from '../ble/actions';
|
||||
import { HubType } from '../ble-lwp3-service/protocol';
|
||||
import {
|
||||
blePybricksServiceDidNotReceiveHubCapabilities,
|
||||
@@ -62,6 +66,11 @@ const runtime: Reducer<HubRuntimeState> = (
|
||||
return HubRuntimeState.Unknown;
|
||||
}
|
||||
|
||||
if (bleDisconnectPybricks.matches(action)) {
|
||||
// disconnecting
|
||||
return HubRuntimeState.Unknown;
|
||||
}
|
||||
|
||||
if (bleDidDisconnectPybricks.matches(action)) {
|
||||
return HubRuntimeState.Disconnected;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user