mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 17:45:22 +00:00
ble-device-info-service: add actions
This adds actions that are triggered when the device info service characteristics are read.
This commit is contained in:
@@ -10,10 +10,10 @@ import {
|
||||
import { AsyncSaga } from '../../test';
|
||||
import { Action } from '../actions';
|
||||
import { didCheckForUpdate } from '../app/actions';
|
||||
import { bleDIServiceDidReceiveFirmwareRevision } from '../ble-device-info-service/actions';
|
||||
import {
|
||||
BleDeviceFailToConnectReasonType,
|
||||
didFailToConnect as bleDidFailToConnect,
|
||||
didConnect,
|
||||
} from '../ble/actions';
|
||||
import { didFailToSaveAs, storageChanged } from '../editor/actions';
|
||||
import {
|
||||
@@ -81,7 +81,7 @@ test.each([
|
||||
didFailToFinish(FailToFinishReasonType.FirmwareSize),
|
||||
didFailToFinish(FailToFinishReasonType.Unknown, new Error('test error')),
|
||||
didCheckForUpdate(false),
|
||||
didConnect('3.0.0'),
|
||||
bleDIServiceDidReceiveFirmwareRevision('3.0.0'),
|
||||
didFailToSaveAs(new DOMException('test message', 'NotAllowedError')),
|
||||
])('actions that should show notification: %o', async (action: Action) => {
|
||||
const getToasts = jest.fn().mockReturnValue([]);
|
||||
@@ -113,7 +113,7 @@ test.each([
|
||||
didFailToFinish(FailToFinishReasonType.FailedToConnect),
|
||||
didSucceed({} as ServiceWorkerRegistration),
|
||||
didCheckForUpdate(true),
|
||||
didConnect(firmwareVersion),
|
||||
bleDIServiceDidReceiveFirmwareRevision(firmwareVersion),
|
||||
didFailToSaveAs(new DOMException('test message', 'AbortError')),
|
||||
])('actions that should not show a notification: %o', async (action: Action) => {
|
||||
const getToasts = jest.fn().mockReturnValue([]);
|
||||
|
||||
@@ -12,9 +12,12 @@ import * as semver from 'semver';
|
||||
import { delay, getContext, put, take, takeEvery } from 'typed-redux-saga/macro';
|
||||
import { AppActionType, AppDidCheckForUpdateAction, reload } from '../app/actions';
|
||||
import { appName } from '../app/constants';
|
||||
import {
|
||||
BleDIServiceActionType,
|
||||
BleDIServiceDidReceiveFirmwareRevisionAction,
|
||||
} from '../ble-device-info-service/actions';
|
||||
import {
|
||||
BleDeviceActionType,
|
||||
BleDeviceDidConnectAction,
|
||||
BleDeviceDidFailToConnectAction,
|
||||
BleDeviceFailToConnectReasonType,
|
||||
} from '../ble/actions';
|
||||
@@ -393,12 +396,14 @@ function* showNoUpdateInfo(action: AppDidCheckForUpdateAction): Generator {
|
||||
});
|
||||
}
|
||||
|
||||
function* checkVersion(action: BleDeviceDidConnectAction): Generator {
|
||||
function* checkVersion(
|
||||
action: BleDIServiceDidReceiveFirmwareRevisionAction,
|
||||
): Generator {
|
||||
// ensure the actual hub firmware version is the same as the shipped
|
||||
// firmware version or newer
|
||||
if (
|
||||
!semver.satisfies(
|
||||
pythonVersionToSemver(action.firmwareVersion),
|
||||
pythonVersionToSemver(action.version),
|
||||
`>=${pythonVersionToSemver(firmwareVersion)}`,
|
||||
)
|
||||
) {
|
||||
@@ -423,5 +428,5 @@ export default function* (): Generator {
|
||||
yield* takeEvery(NotificationActionType.Add, addNotification);
|
||||
yield* takeEvery(ServiceWorkerActionType.DidUpdate, showServiceWorkerUpdate);
|
||||
yield* takeEvery(AppActionType.DidCheckForUpdate, showNoUpdateInfo);
|
||||
yield* takeEvery(BleDeviceActionType.DidConnect, checkVersion);
|
||||
yield* takeEvery(BleDIServiceActionType.DidReceiveFirmwareRevision, checkVersion);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user