Skip to content

Commit

Permalink
fix(connect): allow firmwareUpdate from binary without known device.f…
Browse files Browse the repository at this point in the history
…irmwareRelease
  • Loading branch information
szymonlesisz committed Jan 20, 2025
1 parent 26127a4 commit 63f955d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
49 changes: 49 additions & 0 deletions packages/connect/src/core/__tests__/onCallFirmwareUpdate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,53 @@ describe('onCallFirmwareUpdate', () => {

await deviceList.dispose();
});

it('T3W1: from binary', async () => {
const { context, deviceList, waitForDeviceList, buildFixture } = setupTest();
const t3 = {
internal_model: 'T3W1',
};

await waitForDeviceList([
// GetFeatures before reboot
buildFixture('0037', { ...t3 }),
// GetFeatures in bootloader mode
buildFixture('0037', { ...t3, bootloader_mode: true }),
// Initialize in bootloader mode
buildFixture('0000', { ...t3 }),
// GetFeatures after reboot
buildFixture('0037', { ...t3 }),
]);

const binary = await httpRequestMock();
const result = await runFirmwareUpdate({
params: { binary },
context,
});

expect(result.check).toEqual('omitted');
expect(result.versionCheck).toEqual(true);

await deviceList.dispose();
});

// NOTE: this test fails because there are no official releases for T3W1, should be removed after release
it('T3W1: failed from config', async () => {
const { context, deviceList, waitForDeviceList, buildFixture } = setupTest();
const t3 = { internal_model: 'T3W1' };

await waitForDeviceList([
// GetFeatures before reboot
buildFixture('0037', { ...t3 }),
]);

await expect(() =>
onCallFirmwareUpdate({
params: {},
context,
}),
).rejects.toThrow('firmwareRelease is not set');

await deviceList.dispose();
});
});
15 changes: 6 additions & 9 deletions packages/connect/src/core/onCallFirmwareUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ const getBinaryHelper = (
postMessage: PostMessage,
btcOnly: boolean,
) => {
if (!device.firmwareRelease) {
throw ERRORS.TypedError('Runtime', 'device.firmwareRelease is not set');
}
if (params.binary) {
return {
binary: params.binary,
Expand All @@ -196,6 +193,10 @@ const getBinaryHelper = (
};
}

if (!device.firmwareRelease) {
throw ERRORS.TypedError('Runtime', 'device.firmwareRelease is not set');
}

const {
intermediaryVersion,
release: { version },
Expand Down Expand Up @@ -318,10 +319,6 @@ export const onCallFirmwareUpdate = async ({
log.debug('onCallFirmwareUpdate with params: ', params);

const device = await initDevice(params?.device?.path);
if (!device.firmwareRelease) {
throw ERRORS.TypedError('Runtime', 'device.firmwareRelease is not set');
}

if (deviceList.getDeviceCount() > 1) {
throw ERRORS.TypedError(
'Device_MultipleNotSupported',
Expand Down Expand Up @@ -378,7 +375,7 @@ export const onCallFirmwareUpdate = async ({

const targetLanguage = params.language || device.features.language || 'en-US';
const languageBlob =
language && targetLanguage !== 'en-US'
device.firmwareRelease && language && targetLanguage !== 'en-US'
? await getLanguage({
language: targetLanguage,
version: device.firmwareRelease.release.version,
Expand Down Expand Up @@ -438,7 +435,7 @@ export const onCallFirmwareUpdate = async ({
);
}

const intermediary = !params.binary && device.firmwareRelease.intermediaryVersion;
const intermediary = !params.binary && device.firmwareRelease?.intermediaryVersion;
const bootloaderVersion = reconnectedDevice.getVersion();

// note: fw major_version 1 requires calling initialize before calling FirmwareErase. Without it device would not respond
Expand Down

0 comments on commit 63f955d

Please sign in to comment.