Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use hacstag for yaml #485

Merged
merged 1 commit into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/dialogs/hacs-install-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class HacsInstallDialog extends HacsDialogBase {
? html`
<p>${this.hacs.localize(`repository.lovelace_instruction`)}</p>
<pre>
url: ${generateLovelaceURL(this._repository, this._version)}
url: ${generateLovelaceURL({ repository: this._repository, skipTag: true })}
type: module
</pre
>
Expand Down
4 changes: 2 additions & 2 deletions src/components/hacs-repository-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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?"
}
},
Expand Down
16 changes: 10 additions & 6 deletions src/tools/added-to-lovelace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
};
2 changes: 1 addition & 1 deletion src/tools/update-lovelace-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down