From 88701c616726354cb5a04b1bc1eda25d35b9dce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Beye?= Date: Tue, 10 Nov 2020 15:25:06 +0100 Subject: [PATCH] Refactor brands url to single location (#7613) --- .../config-flow/step-flow-pick-handler.ts | 3 +- src/onboarding/integration-badge.ts | 3 +- .../config/devices/ha-config-device-page.ts | 5 ++- src/panels/config/info/integrations-card.ts | 3 +- .../integrations/ha-config-integrations.ts | 5 +-- .../integrations/ha-integration-card.ts | 5 +-- src/util/brands-url.ts | 9 +++++ test-mocha/util/generate-brands-url-spec.ts | 33 +++++++++++++++++++ 8 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 src/util/brands-url.ts create mode 100644 test-mocha/util/generate-brands-url-spec.ts diff --git a/src/dialogs/config-flow/step-flow-pick-handler.ts b/src/dialogs/config-flow/step-flow-pick-handler.ts index cbfcf3b8d5..381cca56d3 100644 --- a/src/dialogs/config-flow/step-flow-pick-handler.ts +++ b/src/dialogs/config-flow/step-flow-pick-handler.ts @@ -23,6 +23,7 @@ import { HomeAssistant } from "../../types"; import { documentationUrl } from "../../util/documentation-url"; import { FlowConfig } from "./show-dialog-data-entry-flow"; import { configFlowContentStyles } from "./styles"; +import { brandsUrl } from "../../util/brands-url"; interface HandlerObj { name: string; @@ -102,7 +103,7 @@ class StepFlowPickHandler extends LitElement { diff --git a/src/onboarding/integration-badge.ts b/src/onboarding/integration-badge.ts index 5bf4267b56..bb84d3ce79 100644 --- a/src/onboarding/integration-badge.ts +++ b/src/onboarding/integration-badge.ts @@ -8,6 +8,7 @@ import { TemplateResult, } from "lit-element"; import "../components/ha-icon"; +import { brandsUrl } from "../util/brands-url"; @customElement("integration-badge") class IntegrationBadge extends LitElement { @@ -23,7 +24,7 @@ class IntegrationBadge extends LitElement { return html`
${this.badgeIcon diff --git a/src/panels/config/devices/ha-config-device-page.ts b/src/panels/config/devices/ha-config-device-page.ts index 4c747026ff..dfad8ec20e 100644 --- a/src/panels/config/devices/ha-config-device-page.ts +++ b/src/panels/config/devices/ha-config-device-page.ts @@ -45,6 +45,7 @@ import { configSections } from "../ha-panel-config"; import "./device-detail/ha-device-entities-card"; import "./device-detail/ha-device-info-card"; import { showDeviceAutomationDialog } from "./device-detail/show-dialog-device-automation"; +import { brandsUrl } from "../../../util/brands-url"; export interface EntityRegistryStateEntry extends EntityRegistryEntry { stateName?: string | null; @@ -224,9 +225,7 @@ export class HaConfigDevicePage extends LitElement { : "" } diff --git a/src/panels/config/integrations/ha-config-integrations.ts b/src/panels/config/integrations/ha-config-integrations.ts index 3ce52f210d..1cee69af8e 100644 --- a/src/panels/config/integrations/ha-config-integrations.ts +++ b/src/panels/config/integrations/ha-config-integrations.ts @@ -67,6 +67,7 @@ import type { ConfigEntryUpdatedEvent, HaIntegrationCard, } from "./ha-integration-card"; +import { brandsUrl } from "../../../util/brands-url"; interface DataEntryFlowProgressExtended extends DataEntryFlowProgress { localized_title?: string; @@ -330,7 +331,7 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
{ + return `https://brands.home-assistant.io/${ + useFallback ? "_/" : "" + }${domain}/${type}.png`; +}; diff --git a/test-mocha/util/generate-brands-url-spec.ts b/test-mocha/util/generate-brands-url-spec.ts new file mode 100644 index 0000000000..6d3c48edda --- /dev/null +++ b/test-mocha/util/generate-brands-url-spec.ts @@ -0,0 +1,33 @@ +import * as assert from "assert"; +import { brandsUrl } from "../../src/util/brands-url"; + +describe("Generate brands Url", function () { + it("Generate logo brands url for cloud component without fallback", function () { + assert.strictEqual( + // @ts-ignore + brandsUrl("cloud", "logo"), + "https://brands.home-assistant.io/cloud/logo.png" + ); + }); + it("Generate icon brands url for cloud component without fallback", function () { + assert.strictEqual( + // @ts-ignore + brandsUrl("cloud", "icon"), + "https://brands.home-assistant.io/cloud/icon.png" + ); + }); + it("Generate logo brands url for cloud component with fallback", function () { + assert.strictEqual( + // @ts-ignore + brandsUrl("cloud", "logo", true), + "https://brands.home-assistant.io/_/cloud/logo.png" + ); + }); + it("Generate icon brands url for cloud component with fallback", function () { + assert.strictEqual( + // @ts-ignore + brandsUrl("cloud", "icon", true), + "https://brands.home-assistant.io/_/cloud/icon.png" + ); + }); +});