From 500c09592eaee790022efa0f14c8a39a5f50f51b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Thu, 17 Jun 2021 23:07:59 +0000 Subject: [PATCH] Don't use hacstag for yaml --- src/components/dialogs/hacs-install-dialog.ts | 2 +- src/components/hacs-repository-card.ts | 4 ++-- src/localize/languages/en.json | 2 +- src/tools/added-to-lovelace.ts | 16 ++++++++++------ src/tools/update-lovelace-resources.ts | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/dialogs/hacs-install-dialog.ts b/src/components/dialogs/hacs-install-dialog.ts index b2056b9c..e365dba3 100644 --- a/src/components/dialogs/hacs-install-dialog.ts +++ b/src/components/dialogs/hacs-install-dialog.ts @@ -152,7 +152,7 @@ export class HacsInstallDialog extends HacsDialogBase { ? html`

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

-                url: ${generateLovelaceURL(this._repository, this._version)}
+                url: ${generateLovelaceURL({ repository: this._repository, skipTag: true })}
                 type: module
                 
diff --git a/src/components/hacs-repository-card.ts b/src/components/hacs-repository-card.ts index bf6c5a6f..9a4591ad 100644 --- a/src/components/hacs-repository-card.ts +++ b/src/components/hacs-repository-card.ts @@ -250,10 +250,10 @@ export class HacsRepositoryCard extends LitElement { private async _uninstallRepository() { if (this.repository.category === "plugin" && this.hacs.status?.lovelace_mode !== "yaml") { const resources = await fetchResources(this.hass); - const expectedURL = generateLovelaceURL(this.repository); + const expectedURL = generateLovelaceURL({ repository: this.repository, skipTag: true }); await Promise.all( resources - .filter((resource) => expectedURL.includes(resource.url)) + .filter((resource) => resource.url.includes(expectedURL)) .map((resource) => deleteResource(this.hass, String(resource.id))) ); } diff --git a/src/localize/languages/en.json b/src/localize/languages/en.json index 91917141..b94bd363 100644 --- a/src/localize/languages/en.json +++ b/src/localize/languages/en.json @@ -265,7 +265,7 @@ }, "dialog": { "reload": { - "description": "You need to clear your browser cache when changing Lovelace resources.", + "description": "You need to reload your browser for the updated resources to be used.", "confirm": "Do you want to do that now?" } }, diff --git a/src/tools/added-to-lovelace.ts b/src/tools/added-to-lovelace.ts index 04dddffc..299dc8b3 100644 --- a/src/tools/added-to-lovelace.ts +++ b/src/tools/added-to-lovelace.ts @@ -11,10 +11,14 @@ const generateUniqueTag = (repository: Repository, version?: string): string => ).replace(/\D+/g, "")}` ); -export const generateLovelaceURL = (repository: Repository, version?: string): string => - `/hacsfiles/${repository.full_name.split("/")[1]}/${ - repository.file_name - }?hacstag=${generateUniqueTag(repository, version)}`; +export const generateLovelaceURL = (options: { + repository: Repository; + version?: string; + skipTag?: boolean; +}): string => + `/hacsfiles/${options.repository.full_name.split("/")[1]}/${options.repository.file_name}${ + !options.skipTag ? `?hacstag=${generateUniqueTag(options.repository, options.version)}` : "" + }`; export const addedToLovelace = (hacs: Hacs, repository: Repository): boolean => { if (!repository.installed) { @@ -26,6 +30,6 @@ export const addedToLovelace = (hacs: Hacs, repository: Repository): boolean => if (hacs.status?.lovelace_mode !== "storage") { return true; } - const expectedUrl = generateLovelaceURL(repository); - return hacs.resources?.some((resource) => expectedUrl.includes(resource.url)) || false; + const expectedUrl = generateLovelaceURL({ repository, skipTag: true }); + return hacs.resources?.some((resource) => resource.url.includes(expectedUrl)) || false; }; diff --git a/src/tools/update-lovelace-resources.ts b/src/tools/update-lovelace-resources.ts index 41eb37c2..209ae398 100644 --- a/src/tools/update-lovelace-resources.ts +++ b/src/tools/update-lovelace-resources.ts @@ -13,7 +13,7 @@ export async function updateLovelaceResources( const logger = new HacsLogger(); const resources = await fetchResources(hass); const namespace = `/hacsfiles/${repository.full_name.split("/")[1]}`; - const url = generateLovelaceURL(repository, version); + const url = generateLovelaceURL({ repository, version }); const exsisting = resources.find((resource) => resource.url.includes(namespace)); logger.debug({ namespace, url, exsisting }, "updateLovelaceResources");