From 8db47b5687ca2dc8b3d66a11141d1f0cefd89e60 Mon Sep 17 00:00:00 2001 From: SebClem Date: Thu, 18 Apr 2024 13:41:52 +0200 Subject: [PATCH] [Back] Add hass status --- .../backend/src/services/homeAssistantService.ts | 9 +++++++++ nextcloud_backup/backend/src/tools/status.ts | 6 +++++- nextcloud_backup/backend/src/types/status.ts | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/nextcloud_backup/backend/src/services/homeAssistantService.ts b/nextcloud_backup/backend/src/services/homeAssistantService.ts index 6967001..1158253 100644 --- a/nextcloud_backup/backend/src/services/homeAssistantService.ts +++ b/nextcloud_backup/backend/src/services/homeAssistantService.ts @@ -24,6 +24,7 @@ import type { SupervisorResponse, } from "../types/services/ha_os_response.js"; import { States, type Status } from "../types/status.js"; +import { DateTime } from "luxon"; const pipeline = promisify(stream.pipeline); @@ -113,9 +114,17 @@ function getBackups(): Promise>> { option ).then( (result) => { + const status = statusTools.getStatus(); + status.hass.ok = true; + status.hass.last_check = DateTime.now(); + statusTools.setStatus(status); return result; }, (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); return Promise.reject(error); } diff --git a/nextcloud_backup/backend/src/tools/status.ts b/nextcloud_backup/backend/src/tools/status.ts index 4bb0887..d14cdf1 100644 --- a/nextcloud_backup/backend/src/tools/status.ts +++ b/nextcloud_backup/backend/src/tools/status.ts @@ -12,6 +12,10 @@ let status: Status = { folder_created: false, last_check: DateTime.now(), }, + hass: { + ok: false, + last_check: DateTime.now(), + }, }; export function init() { @@ -31,4 +35,4 @@ export function setStatus(new_state: Status) { status = new_state; publish_state(status); } -} \ No newline at end of file +} diff --git a/nextcloud_backup/backend/src/types/status.ts b/nextcloud_backup/backend/src/types/status.ts index f3e7af8..bc07af3 100644 --- a/nextcloud_backup/backend/src/types/status.ts +++ b/nextcloud_backup/backend/src/types/status.ts @@ -25,4 +25,8 @@ export interface Status { folder_created: boolean; last_check: DateTime; }; + hass: { + ok: boolean; + last_check: DateTime; + }; }