diff --git a/src/components/dialogs/hacs-download-dialog.ts b/src/components/dialogs/hacs-download-dialog.ts index 14027ca8..c2b6b3ad 100644 --- a/src/components/dialogs/hacs-download-dialog.ts +++ b/src/components/dialogs/hacs-download-dialog.ts @@ -18,8 +18,8 @@ import { } from "../../data/repository"; import { getRepositories, repositoryBeta, websocketSubscription } from "../../data/websocket"; import { HacsStyles } from "../../styles/hacs-common-style"; -import { generateLovelaceURL } from "../../tools/added-to-lovelace"; -import { updateLovelaceResources } from "../../tools/update-lovelace-resources"; +import { generateFrontendResourceURL } from "../../tools/frontend-resource"; +import { updateFrontendResource } from "../../tools/frontend-resource"; import "./hacs-dialog"; import { HacsDialogBase } from "./hacs-dialog-base"; @@ -147,7 +147,7 @@ export class HacsDonwloadDialog extends HacsDialogBase { ? html`

${this.hacs.localize(`dialog_download.lovelace_instruction`)}

-                url: ${generateLovelaceURL({ repository: this._repository, skipTag: true })}
+                url: ${generateFrontendResourceURL({ repository: this._repository, skipTag: true })}
                 type: module
                 
@@ -227,7 +227,7 @@ export class HacsDonwloadDialog extends HacsDialogBase { this.hacs.log.debug(this._repository.category, "_installRepository"); this.hacs.log.debug(this.hacs.info.lovelace_mode, "_installRepository"); if (this._repository.category === "plugin" && this.hacs.info.lovelace_mode === "storage") { - await updateLovelaceResources(this.hass, this._repository, selectedVersion); + await updateFrontendResource(this.hass, this._repository, selectedVersion); } this._installing = false; diff --git a/src/tools/added-to-lovelace.ts b/src/tools/added-to-lovelace.ts deleted file mode 100644 index 3581871f..00000000 --- a/src/tools/added-to-lovelace.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { RepositoryInfo } from "../data/repository"; - -const generateUniqueTag = (repository: RepositoryInfo, version?: string): string => - String( - `${repository.id}${( - version || - repository.installed_version || - repository.selected_tag || - repository.available_version - ).replace(/\D+/g, "")}` - ); - -export const generateLovelaceURL = (options: { - repository: RepositoryInfo; - version?: string; - skipTag?: boolean; -}): string => - `/hacsfiles/${options.repository.full_name.split("/")[1]}/${options.repository.file_name}${ - !options.skipTag ? `?hacstag=${generateUniqueTag(options.repository, options.version)}` : "" - }`; diff --git a/src/tools/update-lovelace-resources.ts b/src/tools/frontend-resource.ts similarity index 53% rename from src/tools/update-lovelace-resources.ts rename to src/tools/frontend-resource.ts index 95abd0d3..5cf08157 100644 --- a/src/tools/update-lovelace-resources.ts +++ b/src/tools/frontend-resource.ts @@ -3,13 +3,21 @@ import { fetchResources, updateResource, } from "../../homeassistant-frontend/src/data/lovelace"; -import { HomeAssistant } from "../../homeassistant-frontend/src/types"; -import { RepositoryInfo } from "../data/repository"; -import { generateLovelaceURL } from "./added-to-lovelace"; - +import type { HomeAssistant } from "../../homeassistant-frontend/src/types"; +import type { RepositoryInfo } from "../data/repository"; import { HacsLogger } from "./hacs-logger"; -export async function updateLovelaceResources( +const generateUniqueTag = (repository: RepositoryInfo, version?: string): string => + String( + `${repository.id}${( + version || + repository.installed_version || + repository.selected_tag || + repository.available_version + ).replace(/\D+/g, "")}` + ); + +export async function updateFrontendResource( hass: HomeAssistant, repository: RepositoryInfo, version?: string @@ -17,7 +25,7 @@ export async function updateLovelaceResources( const logger = new HacsLogger("updateLovelaceResources"); const resources = await fetchResources(hass.connection); const namespace = `/hacsfiles/${repository.full_name.split("/")[1]}`; - const url = generateLovelaceURL({ repository, version }); + const url = generateFrontendResourceURL({ repository, version }); const exsisting = resources.find((resource) => resource.url.includes(namespace)); logger.debug({ namespace, url, exsisting }); @@ -36,3 +44,12 @@ export async function updateLovelaceResources( }); } } + +export const generateFrontendResourceURL = (options: { + repository: RepositoryInfo; + version?: string; + skipTag?: boolean; +}): string => + `/hacsfiles/${options.repository.full_name.split("/")[1]}/${options.repository.file_name}${ + !options.skipTag ? `?hacstag=${generateUniqueTag(options.repository, options.version)}` : "" + }`;