ble: avoid aliases for UUID constants

This commit is contained in:
David Lechner
2022-07-15 18:05:48 -05:00
parent 15ecdf998d
commit bbe7eb4df3
9 changed files with 65 additions and 54 deletions
+18 -16
View File
@@ -11,20 +11,20 @@ import {
bleDIServiceDidReceiveSoftwareRevision,
} from '../ble-device-info-service/actions';
import {
serviceUUID as deviceInfoServiceUUID,
deviceInformationServiceUUID,
firmwareRevisionStringUUID,
pnpIdUUID,
softwareRevisionStringUUID,
} from '../ble-device-info-service/protocol';
import { encodeInfo } from '../ble-device-info-service/protocol.test';
import {
RxCharUUID as uartRxCharUUID,
ServiceUUID as uartServiceUUID,
TxCharUUID as uartTxCharUUID,
nordicUartRxCharUUID,
nordicUartServiceUUID,
nordicUartTxCharUUID,
} from '../ble-nordic-uart-service/protocol';
import {
ControlCharacteristicUUID as pybricksCommandCharacteristicUUID,
ServiceUUID as pybricksServiceUUID,
pybricksControlCharacteristicUUID,
pybricksServiceUUID,
} from '../ble-pybricks-service/protocol';
import {
BleDeviceFailToConnectReasonType,
@@ -106,7 +106,7 @@ function createMocks(): Mocks {
const pybricksService = mock<BluetoothRemoteGATTService>();
pybricksService.getCharacteristic
.calledWith(pybricksCommandCharacteristicUUID)
.calledWith(pybricksControlCharacteristicUUID)
.mockResolvedValue(pybricksChar);
const uartRxChar = mock<BluetoothRemoteGATTCharacteristic>();
@@ -122,10 +122,10 @@ function createMocks(): Mocks {
const uartService = mock<BluetoothRemoteGATTService>();
uartService.getCharacteristic
.calledWith(uartRxCharUUID)
.calledWith(nordicUartRxCharUUID)
.mockResolvedValue(uartRxChar);
uartService.getCharacteristic
.calledWith(uartTxCharUUID)
.calledWith(nordicUartTxCharUUID)
.mockResolvedValue(uartTxChar);
const gatt = mock<BluetoothRemoteGATTServer>();
@@ -136,12 +136,14 @@ function createMocks(): Mocks {
}, 10);
});
gatt.getPrimaryService
.calledWith(deviceInfoServiceUUID)
.calledWith(deviceInformationServiceUUID)
.mockResolvedValue(deviceInfoService);
gatt.getPrimaryService
.calledWith(pybricksServiceUUID)
.mockResolvedValue(pybricksService);
gatt.getPrimaryService.calledWith(uartServiceUUID).mockResolvedValue(uartService);
gatt.getPrimaryService
.calledWith(nordicUartServiceUUID)
.mockResolvedValue(uartService);
const deviceEvents = new EventTarget();
const device = mock<BluetoothDevice>({
@@ -339,7 +341,7 @@ describe('connect action is dispatched', () => {
it('should fail if device does not have device info service', async () => {
const testError = new DOMException('test error', 'NotFoundError');
mocks.gatt.getPrimaryService
.calledWith(deviceInfoServiceUUID)
.calledWith(deviceInformationServiceUUID)
.mockRejectedValueOnce(testError);
await runConnectUntil(saga, ConnectRunPoint.Connect);
@@ -485,7 +487,7 @@ describe('connect action is dispatched', () => {
it('should fail if getting pybricks characteristic fails', async () => {
const testError = new Error('test error');
mocks.pybricksService.getCharacteristic
.calledWith(pybricksCommandCharacteristicUUID)
.calledWith(pybricksControlCharacteristicUUID)
.mockRejectedValue(testError);
await runConnectUntil(saga, ConnectRunPoint.DidReceivePnpId);
@@ -544,7 +546,7 @@ describe('connect action is dispatched', () => {
it('should fail if device does not have nordic uart service', async () => {
const testError = new DOMException('test error', 'NotFoundError');
mocks.gatt.getPrimaryService
.calledWith(uartServiceUUID)
.calledWith(nordicUartServiceUUID)
.mockRejectedValueOnce(testError);
await runConnectUntil(saga, ConnectRunPoint.DidReceivePnpId);
@@ -562,7 +564,7 @@ describe('connect action is dispatched', () => {
it('should fail if getting nordic uart rx characteristic fails', async () => {
const testError = new Error('test error');
mocks.uartService.getCharacteristic
.calledWith(uartRxCharUUID)
.calledWith(nordicUartRxCharUUID)
.mockRejectedValue(testError);
await runConnectUntil(saga, ConnectRunPoint.DidReceivePnpId);
@@ -583,7 +585,7 @@ describe('connect action is dispatched', () => {
it('should fail if getting nordic uart tx characteristic fails', async () => {
const testError = new Error('test error');
mocks.uartService.getCharacteristic
.calledWith(uartTxCharUUID)
.calledWith(nordicUartTxCharUUID)
.mockRejectedValue(testError);
await runConnectUntil(saga, ConnectRunPoint.DidReceivePnpId);
+19 -13
View File
@@ -23,7 +23,7 @@ import {
} from '../ble-device-info-service/actions';
import {
decodePnpId,
serviceUUID as deviceInfoServiceUUID,
deviceInformationServiceUUID,
firmwareRevisionStringUUID,
pnpIdUUID,
softwareRevisionStringUUID,
@@ -35,9 +35,9 @@ import {
write as writeUart,
} from '../ble-nordic-uart-service/actions';
import {
RxCharUUID as uartRxCharUUID,
ServiceUUID as uartServiceUUID,
TxCharUUID as uartTxCharUUID,
nordicUartRxCharUUID,
nordicUartServiceUUID,
nordicUartTxCharUUID,
} from '../ble-nordic-uart-service/protocol';
import {
didFailToWriteCommand,
@@ -46,8 +46,8 @@ import {
writeCommand,
} from '../ble-pybricks-service/actions';
import {
ControlCharacteristicUUID as pybricksCommandCharacteristicUUID,
ServiceUUID as pybricksServiceUUID,
pybricksControlCharacteristicUUID,
pybricksServiceUUID,
} from '../ble-pybricks-service/protocol';
import { RootState } from '../reducers';
import { ensureError } from '../utils';
@@ -121,8 +121,8 @@ function* handleBleConnectPybricks(): Generator {
filters: [{ services: [pybricksServiceUUID] }],
optionalServices: [
pybricksServiceUUID,
deviceInfoServiceUUID,
uartServiceUUID,
deviceInformationServiceUUID,
nordicUartServiceUUID,
],
}),
);
@@ -183,7 +183,7 @@ function* handleBleConnectPybricks(): Generator {
try {
deviceInfoService = yield* call(
[server, 'getPrimaryService'],
deviceInfoServiceUUID,
deviceInformationServiceUUID,
);
} catch (err) {
server.disconnect();
@@ -360,7 +360,7 @@ function* handleBleConnectPybricks(): Generator {
try {
pybricksControlChar = yield* call(
[pybricksService, 'getCharacteristic'],
pybricksCommandCharacteristicUUID,
pybricksControlCharacteristicUUID,
);
} catch (err) {
server.disconnect();
@@ -432,7 +432,7 @@ function* handleBleConnectPybricks(): Generator {
let uartService: BluetoothRemoteGATTService;
try {
uartService = yield* call([server, 'getPrimaryService'], uartServiceUUID);
uartService = yield* call([server, 'getPrimaryService'], nordicUartServiceUUID);
} catch (err) {
yield* cancel(tasks);
pybricksControlChannel.close();
@@ -460,7 +460,10 @@ function* handleBleConnectPybricks(): Generator {
let uartRxChar: BluetoothRemoteGATTCharacteristic;
try {
uartRxChar = yield* call([uartService, 'getCharacteristic'], uartRxCharUUID);
uartRxChar = yield* call(
[uartService, 'getCharacteristic'],
nordicUartRxCharUUID,
);
} catch (err) {
yield* cancel(tasks);
pybricksControlChannel.close();
@@ -482,7 +485,10 @@ function* handleBleConnectPybricks(): Generator {
let uartTxChar: BluetoothRemoteGATTCharacteristic;
try {
uartTxChar = yield* call([uartService, 'getCharacteristic'], uartTxCharUUID);
uartTxChar = yield* call(
[uartService, 'getCharacteristic'],
nordicUartTxCharUUID,
);
} catch (err) {
yield* cancel(tasks);
pybricksControlChannel.close();