Skip to content

Commit

Permalink
Fix preferred agent for backup download (#23659)
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored Jan 9, 2025
1 parent 853059a commit 166633c
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/data/backup.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { setHours, setMinutes } from "date-fns";
import type { HassConfig } from "home-assistant-js-websocket";
import memoizeOne from "memoize-one";
import { formatTime } from "../common/datetime/format_time";
import type { LocalizeFunc } from "../common/translations/localize";
import type { HomeAssistant } from "../types";
import { domainToName } from "./integration";
import type { FrontendLocaleData } from "./translation";
import {
formatDateTime,
formatDateTimeNumeric,
} from "../common/datetime/format_date_time";
import { formatTime } from "../common/datetime/format_time";
import type { LocalizeFunc } from "../common/translations/localize";
import type { HomeAssistant } from "../types";
import { fileDownload } from "../util/file_download";
import { domainToName } from "./integration";
import type { FrontendLocaleData } from "./translation";

export const enum BackupScheduleState {
NEVER = "never",
Expand Down Expand Up @@ -217,10 +217,16 @@ export const uploadBackup = async (
};

export const getPreferredAgentForDownload = (agents: string[]) => {
const localAgents = agents.filter(
(agent) => agent.split(".")[0] === "backup"
);
return localAgents[0] || agents[0];
const localAgent = agents.find(isLocalAgent);
if (localAgent) {
return localAgent;
}
const networkMountAgent = agents.find(isNetworkMountAgent);
if (networkMountAgent) {
return networkMountAgent;
}

return agents[0];
};

export const CORE_LOCAL_AGENT = "backup.local";
Expand Down

0 comments on commit 166633c

Please sign in to comment.