mirror of
https://github.com/Sebclem/hassio-nextcloud-backup.git
synced 2024-11-24 02:02:59 +01:00
41 lines
1011 B
TypeScript
41 lines
1011 B
TypeScript
import { publish_state } from "../services/homeAssistantService.js";
|
|
import logger from "../config/winston.js"
|
|
import type { Status } from "../types/status.js";
|
|
|
|
let status: Status = {
|
|
status: "idle",
|
|
last_backup: undefined,
|
|
next_backup: undefined,
|
|
progress: -1,
|
|
};
|
|
|
|
export function init() {
|
|
if (status.status !== "idle") {
|
|
status.status = "idle";
|
|
status.message = undefined;
|
|
status.progress = -1;
|
|
}
|
|
}
|
|
|
|
export function getStatus() {
|
|
return status;
|
|
}
|
|
|
|
export function setStatus(new_state: Status) {
|
|
const old_state_str = JSON.stringify(status);
|
|
if(old_state_str !== JSON.stringify(new_state)){
|
|
status = new_state;
|
|
publish_state(status);
|
|
}
|
|
}
|
|
|
|
export function setError(message: string, error_code: number){
|
|
// Check if we don't have another error stored
|
|
if (status.status != "error") {
|
|
status.status = "error"
|
|
status.message = message
|
|
status.error_code = error_code;
|
|
}
|
|
logger.error(message);
|
|
}
|