diff --git a/lib/extension/otaUpdate.ts b/lib/extension/otaUpdate.ts index a92ac9c5e..7db198b7f 100644 --- a/lib/extension/otaUpdate.ts +++ b/lib/extension/otaUpdate.ts @@ -65,6 +65,10 @@ export default class OTAUpdate extends Extension { // remove them. for (const device of this.zigbee.devices(false)) { this.removeProgressAndRemainingFromState(device); + // Reset update state, e.g. when Z2M restarted during update. + if (this.state.get(device).update?.state === 'updating') { + this.state.get(device).update.state = 'available'; + } } } diff --git a/test/otaUpdate.test.js b/test/otaUpdate.test.js index 0fdf1a897..6b38a3a95 100644 --- a/test/otaUpdate.test.js +++ b/test/otaUpdate.test.js @@ -485,4 +485,11 @@ describe('OTA update', () => { expect(spyUseIndexOverride).toHaveBeenCalledWith('http://my.site/index.json'); spyUseIndexOverride.mockClear(); }); + + it('Clear update state on startup', async () => { + const device = controller.zigbee.resolveEntity(zigbeeHerdsman.devices.bulb_color.ieeeAddr); + controller.state.set(device, {update: {progress: 100, remaining: 10, state: 'updating'}}) + await resetExtension(); + expect(controller.state.get(device)).toStrictEqual({update: {state: 'available'}}); + }); });