[Back] Add hass status

This commit is contained in:
SebClem 2024-04-18 13:41:52 +02:00
parent 363768f4ba
commit fe02131f74
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
3 changed files with 18 additions and 1 deletions

View File

@ -24,6 +24,7 @@ import type {
SupervisorResponse, SupervisorResponse,
} from "../types/services/ha_os_response.js"; } from "../types/services/ha_os_response.js";
import { States, type Status } from "../types/status.js"; import { States, type Status } from "../types/status.js";
import { DateTime } from "luxon";
const pipeline = promisify(stream.pipeline); const pipeline = promisify(stream.pipeline);
@ -113,9 +114,17 @@ function getBackups(): Promise<Response<SupervisorResponse<BackupData>>> {
option option
).then( ).then(
(result) => { (result) => {
const status = statusTools.getStatus();
status.hass.ok = true;
status.hass.last_check = DateTime.now();
statusTools.setStatus(status);
return result; return result;
}, },
(error) => { (error) => {
const status = statusTools.getStatus();
status.hass.ok = false;
status.hass.last_check = DateTime.now();
statusTools.setStatus(status);
messageManager.error("Fail to fetch Hassio backups", error?.message); messageManager.error("Fail to fetch Hassio backups", error?.message);
return Promise.reject(error); return Promise.reject(error);
} }

View File

@ -12,6 +12,10 @@ let status: Status = {
folder_created: false, folder_created: false,
last_check: DateTime.now(), last_check: DateTime.now(),
}, },
hass: {
ok: false,
last_check: DateTime.now(),
},
}; };
export function init() { export function init() {
@ -31,4 +35,4 @@ export function setStatus(new_state: Status) {
status = new_state; status = new_state;
publish_state(status); publish_state(status);
} }
} }

View File

@ -25,4 +25,8 @@ export interface Status {
folder_created: boolean; folder_created: boolean;
last_check: DateTime; last_check: DateTime;
}; };
hass: {
ok: boolean;
last_check: DateTime;
};
} }