Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/extension/otaUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

export default class OTAUpdate extends Extension {
#topicRegex = new RegExp(
`^${settings.get().mqtt.base_topic}/bridge/request/device/ota_update/(update|check|schedule|unschedule)/?(downgrade)?`,
`^${settings.get().mqtt.base_topic}/bridge/request/device/ota_update/(update|check|schedule|unschedule)/?(downgrade|abort)?`,
"i",
);
#inProgress = new Set<string>();
Expand Down Expand Up @@ -248,6 +248,7 @@
| Zigbee2MQTTAPI["bridge/request/device/ota_update/check/downgrade"]
| Zigbee2MQTTAPI["bridge/request/device/ota_update/update"]
| Zigbee2MQTTAPI["bridge/request/device/ota_update/update/downgrade"]
| Zigbee2MQTTAPI["bridge/request/device/ota_update/update/abort"]
| Zigbee2MQTTAPI["bridge/request/device/ota_update/schedule"]
| Zigbee2MQTTAPI["bridge/request/device/ota_update/schedule/downgrade"]
| Zigbee2MQTTAPI["bridge/request/device/ota_update/unschedule"];
Expand All @@ -262,14 +263,20 @@
const device = this.zigbee.resolveEntity(ID);
const type = topicMatch[1] as "check" | "update" | "schedule" | "unschedule";
const downgrade = topicMatch[2] === "downgrade";
const abort = topicMatch[2] === "abort";
let error: string | undefined;
let errorStack: string | undefined;

if (!(device instanceof Device)) {
error = `Device '${ID}' does not exist`;
} else if (this.#inProgress.has(device.ieeeAddr)) {
// also guards against scheduling while check/update op in progress that could result in undesired OTA state
error = `OTA update or check for update already in progress for '${device.name}'`;
if (abort) {
device.zh.abortOta();

Check failure on line 274 in lib/extension/otaUpdate.ts

View workflow job for this annotation

GitHub Actions / ci

Property 'abortOta' does not exist on type 'Device'.

Check failure on line 274 in lib/extension/otaUpdate.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 22)

Property 'abortOta' does not exist on type 'Device'.

Check failure on line 274 in lib/extension/otaUpdate.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Property 'abortOta' does not exist on type 'Device'.

Check failure on line 274 in lib/extension/otaUpdate.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Property 'abortOta' does not exist on type 'Device'.

Check failure on line 274 in lib/extension/otaUpdate.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 22)

Property 'abortOta' does not exist on type 'Device'.

Check failure on line 274 in lib/extension/otaUpdate.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 24)

Property 'abortOta' does not exist on type 'Device'.

Check failure on line 274 in lib/extension/otaUpdate.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 24)

Property 'abortOta' does not exist on type 'Device'.

Check failure on line 274 in lib/extension/otaUpdate.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 24)

Property 'abortOta' does not exist on type 'Device'.

Check failure on line 274 in lib/extension/otaUpdate.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Property 'abortOta' does not exist on type 'Device'.

Check failure on line 274 in lib/extension/otaUpdate.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 22)

Property 'abortOta' does not exist on type 'Device'.
this.#inProgress.delete(device.ieeeAddr);
} else {
// also guards against scheduling while check/update op in progress that could result in undesired OTA state
error = `OTA update or check for update already in progress for '${device.name}'`;
}
} else {
switch (type) {
case "check": {
Expand Down Expand Up @@ -321,6 +328,11 @@
}

case "update": {
if (abort) {
error = `No OTA in progress for device '${device.name}'`;
break;
}

this.#inProgress.add(device.ieeeAddr);

const otaSettings = settings.get().ota;
Expand Down
4 changes: 4 additions & 0 deletions lib/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,10 @@ export interface Zigbee2MQTTAPI {
default_maximum_data_size?: number | null;
};

"bridge/request/device/ota_update/update/abort": {
id: string;
};

"bridge/response/device/ota_update/update": {
id: string;
from:
Expand Down
Loading