From a40ad0c52f9d695d4a7aa05e4cea26b2c53e4c38 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Fri, 28 Feb 2020 23:42:59 +0100 Subject: [PATCH] Respond with ABORT when device checks for OTA. https://github.com/Koenkk/zigbee2mqtt/issues/3019 --- lib/extension/otaUpdate.js | 13 ++++++++----- test/otaUpdate.test.js | 4 +++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/extension/otaUpdate.js b/lib/extension/otaUpdate.js index 8080bef36..3c1913c08 100644 --- a/lib/extension/otaUpdate.js +++ b/lib/extension/otaUpdate.js @@ -20,7 +20,8 @@ class OTAUpdate extends BaseExtension { async onZigbeeEvent(type, data, mappedDevice, settingsDevice) { if (data.type !== 'commandQueryNextImageRequest') return; - if (mappedDevice.hasOwnProperty('ota')) { + const supportsOTA = mappedDevice.hasOwnProperty('ota'); + if (supportsOTA) { // When a device does a next image request, it will usually do it a few times after each other // with only 10 - 60 seconds inbetween. It doesn' make sense to check for a new update // each time. @@ -37,11 +38,13 @@ class OTAUpdate extends BaseExtension { logger.info(message); this.mqtt.log('ota_update', message, {status: 'available', device: settingsDevice.friendly_name}); } - } else { - // In case we don't support OTA for this device, response with status 0x98 (= NO_IMAGE_AVAILABLE) - const endpoint = data.device.endpoints.find((e) => e.supportsOutputCluster('genOta')); - await endpoint.commandResponse('genOta', 'queryNextImageResponse', {status: 0x98}); } + + // Respond to the OTA request: + // - In case we don't support OTA: respond with NO_IMAGE_AVAILABLE (0x98) (so the client stops requesting OTAs) + // - In case we do support OTA: respond with ABORT (0x95) as we don't want to update now. + const endpoint = data.device.endpoints.find((e) => e.supportsOutputCluster('genOta')); + await endpoint.commandResponse('genOta', 'queryNextImageResponse', {status: supportsOTA ? 0x95 : 0x98}); } async readSoftwareBuildIDAndDateCode(device, update) { diff --git a/test/otaUpdate.test.js b/test/otaUpdate.test.js index 11ee02b07..c75a0934a 100644 --- a/test/otaUpdate.test.js +++ b/test/otaUpdate.test.js @@ -174,7 +174,9 @@ describe('OTA update', () => { await flushPromises(); expect(mapped.ota.isUpdateAvailable).toHaveBeenCalledTimes(1); expect(mapped.ota.isUpdateAvailable).toHaveBeenCalledWith(device, logger, {"imageType": 12382}); - expect(logger.info).toHaveBeenCalledWith(`Update available for 'bulb'`) + expect(logger.info).toHaveBeenCalledWith(`Update available for 'bulb'`); + expect(device.endpoints[0].commandResponse).toHaveBeenCalledTimes(1); + expect(device.endpoints[0].commandResponse).toHaveBeenCalledWith("genOta", "queryNextImageResponse", {"status": 0x95}); // Should not request again when device asks again after a short time await zigbeeHerdsman.events.message(payload);