From e76f568f0fe0a36e5324b20b8ca3173f618cd8e6 Mon Sep 17 00:00:00 2001 From: slugzero <2014249+slugzero@users.noreply.github.com> Date: Thu, 18 Jan 2024 18:28:52 +0100 Subject: [PATCH] fix: Remove deprecated sendWhen (#20861) --- lib/extension/otaUpdate.ts | 6 +++--- test/otaUpdate.test.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/extension/otaUpdate.ts b/lib/extension/otaUpdate.ts index 5ceb6e0a1..a92ac9c5e 100644 --- a/lib/extension/otaUpdate.ts +++ b/lib/extension/otaUpdate.ts @@ -125,11 +125,11 @@ export default class OTAUpdate extends Extension { logger.debug(`Responded to OTA request of '${data.device.name}' with 'NO_IMAGE_AVAILABLE'`); } - private async readSoftwareBuildIDAndDateCode(device: Device, sendWhen: 'active' | 'immediate'): + private async readSoftwareBuildIDAndDateCode(device: Device, sendPolicy?: 'immediate'): Promise<{softwareBuildID: string, dateCode: string}> { try { const endpoint = device.zh.endpoints.find((e) => e.supportsInputCluster('genBasic')); - const result = await endpoint.read('genBasic', ['dateCode', 'swBuildId'], {sendWhen}); + const result = await endpoint.read('genBasic', ['dateCode', 'swBuildId'], {sendPolicy}); return {softwareBuildID: result.swBuildId, dateCode: result.dateCode}; } catch (e) { return null; @@ -273,7 +273,7 @@ export default class OTAUpdate extends Extension { const payload = this.getEntityPublishPayload(device, {available: false, currentFileVersion: fileVersion, otaFileVersion: fileVersion}); this.publishEntityState(device, payload); - const to = await this.readSoftwareBuildIDAndDateCode(device, 'active'); + const to = await this.readSoftwareBuildIDAndDateCode(device); const [fromS, toS] = [stringify(from_), stringify(to)]; logger.info(`Device '${device.name}' was updated from '${fromS}' to '${toS}'`); responseData.from = from_ ? utils.toSnakeCase(from_) : null; diff --git a/test/otaUpdate.test.js b/test/otaUpdate.test.js index 648e77448..0942c4b90 100644 --- a/test/otaUpdate.test.js +++ b/test/otaUpdate.test.js @@ -89,8 +89,8 @@ describe('OTA update', () => { expect(logger.info).toHaveBeenCalledWith(`Finished update of 'bulb'`); expect(logger.info).toHaveBeenCalledWith(`Device 'bulb' was updated from '{"dateCode":"20190101","softwareBuildID":1}' to '{"dateCode":"20190103","softwareBuildID":3}'`); expect(device.save).toHaveBeenCalledTimes(2); - expect(endpoint.read).toHaveBeenCalledWith('genBasic', ['dateCode', 'swBuildId'], {'sendWhen': 'immediate'}); - expect(endpoint.read).toHaveBeenCalledWith('genBasic', ['dateCode', 'swBuildId'], {'sendWhen': 'active'}); + expect(endpoint.read).toHaveBeenCalledWith('genBasic', ['dateCode', 'swBuildId'], {'sendPolicy': 'immediate'}); + expect(endpoint.read).toHaveBeenCalledWith('genBasic', ['dateCode', 'swBuildId'], {}); expect(MQTT.publish).toHaveBeenCalledWith( 'zigbee2mqtt/bulb', stringify({"update_available":false,"update":{"state":"updating","progress":0}}), @@ -392,7 +392,7 @@ describe('OTA update', () => { expect(logger.info).toHaveBeenCalledWith(`Device 'bulb' was updated from '{"dateCode":"20190101","softwareBuildID":1}' to '{"dateCode":"20190103","softwareBuildID":3}'`); expect(logger.error).toHaveBeenCalledTimes(0); expect(device.save).toHaveBeenCalledTimes(2); - expect(endpoint.read).toHaveBeenCalledWith('genBasic', ['dateCode', 'swBuildId'], {'sendWhen': 'immediate'}); + expect(endpoint.read).toHaveBeenCalledWith('genBasic', ['dateCode', 'swBuildId'], {'sendPolicy': 'immediate'}); }); it('Legacy api: Should handle when OTA update fails', async () => {