fix: Fix incorrect update state when Z2M is restarted during OTA update https://github.com/Koenkk/zigbee2mqtt/issues/12794

This commit is contained in:
koenkk 2024-03-05 22:33:33 +01:00
parent 1d73d9d476
commit 1110d3f8ef
2 changed files with 11 additions and 0 deletions

View File

@ -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';
}
}
}

View File

@ -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'}});
});
});