Skip to content

Commit b86d2e5

Browse files
committed
feat: add ability to abort running OTA
1 parent 5458e50 commit b86d2e5

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

lib/extension/otaUpdate.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ export default class OTAUpdate extends Extension {
248248
| Zigbee2MQTTAPI["bridge/request/device/ota_update/check/downgrade"]
249249
| Zigbee2MQTTAPI["bridge/request/device/ota_update/update"]
250250
| Zigbee2MQTTAPI["bridge/request/device/ota_update/update/downgrade"]
251+
| Zigbee2MQTTAPI["bridge/request/device/ota_update/update/abort"]
251252
| Zigbee2MQTTAPI["bridge/request/device/ota_update/schedule"]
252253
| Zigbee2MQTTAPI["bridge/request/device/ota_update/schedule/downgrade"]
253254
| Zigbee2MQTTAPI["bridge/request/device/ota_update/unschedule"];
@@ -262,14 +263,20 @@ export default class OTAUpdate extends Extension {
262263
const device = this.zigbee.resolveEntity(ID);
263264
const type = topicMatch[1] as "check" | "update" | "schedule" | "unschedule";
264265
const downgrade = topicMatch[2] === "downgrade";
266+
const abort = topicMatch[2] === "abort";
265267
let error: string | undefined;
266268
let errorStack: string | undefined;
267269

268270
if (!(device instanceof Device)) {
269271
error = `Device '${ID}' does not exist`;
270272
} else if (this.#inProgress.has(device.ieeeAddr)) {
271-
// also guards against scheduling while check/update op in progress that could result in undesired OTA state
272-
error = `OTA update or check for update already in progress for '${device.name}'`;
273+
if (abort) {
274+
device.zh.abortOta();
275+
this.#inProgress.delete(device.ieeeAddr);
276+
} else {
277+
// also guards against scheduling while check/update op in progress that could result in undesired OTA state
278+
error = `OTA update or check for update already in progress for '${device.name}'`;
279+
}
273280
} else {
274281
switch (type) {
275282
case "check": {
@@ -321,6 +328,11 @@ export default class OTAUpdate extends Extension {
321328
}
322329

323330
case "update": {
331+
if (abort) {
332+
error = `No OTA in progress for device '${device.name}'`;
333+
break;
334+
}
335+
324336
this.#inProgress.add(device.ieeeAddr);
325337

326338
const otaSettings = settings.get().ota;

lib/types/api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,10 @@ export interface Zigbee2MQTTAPI {
677677
default_maximum_data_size?: number | null;
678678
};
679679

680+
"bridge/request/device/ota_update/update/abort": {
681+
id: string;
682+
};
683+
680684
"bridge/response/device/ota_update/update": {
681685
id: string;
682686
from:

0 commit comments

Comments
 (0)