Skip to content

Commit

Permalink
fix: Fix incorrect update state when Z2M is restarted during OTA update
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Mar 5, 2024
1 parent 1d73d9d commit 1110d3f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/extension/otaUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/otaUpdate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'}});
});
});

0 comments on commit 1110d3f

Please sign in to comment.