Skip to content

Commit

Permalink
add available icon status
Browse files Browse the repository at this point in the history
requestStorageInformation is dependent on requestStorageInformationBackup
  • Loading branch information
arteck committed Jan 11, 2024
1 parent 35ec611 commit 12e5744
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions admin/jsonConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"lg": 6
},
"requestStorageInformationBackup": {
"hidden": "!data.requestStorageInformation",
"type": "checkbox",
"label": "Backup on Storage information",
"sm": 12,
Expand Down
20 changes: 20 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,10 +800,24 @@ class Proxmox extends utils.Adapter {

await this.setStateChangedAsync(`${sid}.status`, { val: res.status, ack: true });

await this.extendObjectAsync(`${sid}.available`, {
type: 'state',
common: {
name: 'Available',
type: 'boolean',
role: 'state',
read: true,
write: false,
},
native: {},
});

let available = false;
let resourceStatus;

if (res.status === 'running') {
resourceStatus = await this.proxmox?.getResourceStatus(res.node, type, res.vmid);
available = true;
this.log.debug(`new ${type}: ${resourceStatus.name} - ${JSON.stringify(resourceStatus)}`);
} else {
this.offlineResourceStatus.status = res.status;
Expand All @@ -813,6 +827,8 @@ class Proxmox extends utils.Adapter {
resourceStatus = this.offlineResourceStatus;
}

await this.setStateChangedAsync(`${sid}.available`, { val: available, ack: true });

await this.findState(sid, resourceStatus, async (states) => {
for (const s of states) {
try {
Expand Down Expand Up @@ -1197,10 +1213,12 @@ class Proxmox extends utils.Adapter {
return void this.restart();
}

let available = false;
let resourceStatus;

if (res.status === 'running') {
resourceStatus = await this.proxmox?.getResourceStatus(res.node, res.type, res.vmid, true);
available = true;
} else {
this.offlineResourceStatus.status = res.status;
this.offlineResourceStatus.type = res.type;
Expand All @@ -1209,6 +1227,8 @@ class Proxmox extends utils.Adapter {
resourceStatus = this.offlineResourceStatus;
}

await this.setStateChangedAsync(`${sid}.available`, { val: available, ack: true });

await this.findState(sid, resourceStatus, async (states) => {
for (const element of states) {
await this.setStateChangedAsync(`${element[0]}.${element[1]}`, element[3], true);
Expand Down

0 comments on commit 12e5744

Please sign in to comment.