Use brand icons in actions (#19227)

This commit is contained in:
Bram Kragten 2024-01-02 18:11:34 +01:00
parent c125ec087a
commit f2226cdec2
2 changed files with 38 additions and 5 deletions

View File

@ -29,6 +29,7 @@ import {
mdiFlash, mdiFlash,
mdiFlower, mdiFlower,
mdiFormatListBulleted, mdiFormatListBulleted,
mdiFormatListCheckbox,
mdiFormTextbox, mdiFormTextbox,
mdiGauge, mdiGauge,
mdiGoogleAssistant, mdiGoogleAssistant,
@ -64,6 +65,7 @@ import {
mdiTransmissionTower, mdiTransmissionTower,
mdiWater, mdiWater,
mdiWaterPercent, mdiWaterPercent,
mdiWeatherPartlyCloudy,
mdiWeatherPouring, mdiWeatherPouring,
mdiWeatherRainy, mdiWeatherRainy,
mdiWeatherWindy, mdiWeatherWindy,
@ -128,6 +130,7 @@ export const FIXED_DOMAIN_ICONS = {
updater: mdiCloudUpload, updater: mdiCloudUpload,
vacuum: mdiRobotVacuum, vacuum: mdiRobotVacuum,
wake_word: mdiChatSleep, wake_word: mdiChatSleep,
weather: mdiWeatherPartlyCloudy,
zone: mdiMapMarkerRadius, zone: mdiMapMarkerRadius,
}; };
@ -166,6 +169,7 @@ export const FIXED_DEVICE_CLASS_ICONS = {
precipitation_intensity: mdiWeatherPouring, precipitation_intensity: mdiWeatherPouring,
pressure: mdiGauge, pressure: mdiGauge,
reactive_power: mdiFlash, reactive_power: mdiFlash,
shopping_List: mdiFormatListCheckbox,
signal_strength: mdiWifi, signal_strength: mdiWifi,
sound_pressure: mdiEarHearing, sound_pressure: mdiEarHearing,
speed: mdiSpeedometer, speed: mdiSpeedometer,

View File

@ -15,7 +15,7 @@ import { repeat } from "lit/directives/repeat";
import { styleMap } from "lit/directives/style-map"; import { styleMap } from "lit/directives/style-map";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { fireEvent } from "../../../common/dom/fire_event"; import { fireEvent } from "../../../common/dom/fire_event";
import { domainIcon } from "../../../common/entity/domain_icon"; import { domainIconWithoutDefault } from "../../../common/entity/domain_icon";
import { shouldHandleRequestSelectedEvent } from "../../../common/mwc/handle-request-selected-event"; import { shouldHandleRequestSelectedEvent } from "../../../common/mwc/handle-request-selected-event";
import { stringCompare } from "../../../common/string/compare"; import { stringCompare } from "../../../common/string/compare";
import { LocalizeFunc } from "../../../common/translations/localize"; import { LocalizeFunc } from "../../../common/translations/localize";
@ -45,6 +45,7 @@ import { TRIGGER_GROUPS, TRIGGER_ICONS } from "../../../data/trigger";
import { HassDialog } from "../../../dialogs/make-dialog-manager"; import { HassDialog } from "../../../dialogs/make-dialog-manager";
import { haStyle, haStyleDialog } from "../../../resources/styles"; import { haStyle, haStyleDialog } from "../../../resources/styles";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
import { brandsUrl } from "../../../util/brands-url";
import { import {
AddAutomationElementDialogParams, AddAutomationElementDialogParams,
PASTE_VALUE, PASTE_VALUE,
@ -68,7 +69,8 @@ interface ListItem {
key: string; key: string;
name: string; name: string;
description: string; description: string;
icon: string; icon?: string;
image?: string;
group: boolean; group: boolean;
} }
@ -309,9 +311,17 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
(!domainUsed && manifest?.integration_type === "entity") || (!domainUsed && manifest?.integration_type === "entity") ||
!["helper", "entity"].includes(manifest?.integration_type || ""))) !["helper", "entity"].includes(manifest?.integration_type || "")))
) { ) {
const icon = domainIconWithoutDefault(domain);
result.push({ result.push({
group: true, group: true,
icon: domainIcon(domain), icon,
image: !icon
? brandsUrl({
domain,
type: "icon",
darkOptimized: this.hass.themes?.darkMode,
})
: undefined,
key: `${SERVICE_PREFIX}${domain}`, key: `${SERVICE_PREFIX}${domain}`,
name: domainToName(localize, domain, manifest), name: domainToName(localize, domain, manifest),
description: "", description: "",
@ -345,9 +355,17 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
const services_keys = Object.keys(services[dmn]); const services_keys = Object.keys(services[dmn]);
for (const service of services_keys) { for (const service of services_keys) {
const icon = domainIconWithoutDefault(dmn);
result.push({ result.push({
group: false, group: false,
icon: domainIcon(dmn), icon,
image: !icon
? brandsUrl({
domain: dmn,
type: "icon",
darkOptimized: this.hass.themes?.darkMode,
})
: undefined,
key: `${SERVICE_PREFIX}${dmn}.${service}`, key: `${SERVICE_PREFIX}${dmn}.${service}`,
name: `${domain ? "" : `${domainToName(localize, dmn)}: `}${ name: `${domain ? "" : `${domainToName(localize, dmn)}: `}${
this.hass.localize(`component.${dmn}.services.${service}.name`) || this.hass.localize(`component.${dmn}.services.${service}.name`) ||
@ -556,7 +574,18 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
> >
${item.name} ${item.name}
<span slot="secondary">${item.description}</span> <span slot="secondary">${item.description}</span>
<ha-svg-icon slot="graphic" .path=${item.icon}></ha-svg-icon> ${item.icon
? html`<ha-svg-icon
slot="graphic"
.path=${item.icon}
></ha-svg-icon>`
: html`<img
alt=""
slot="graphic"
src=${item.image}
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>`}
${item.group ${item.group
? html`<ha-icon-next slot="meta"></ha-icon-next>` ? html`<ha-icon-next slot="meta"></ha-icon-next>`
: html`<ha-svg-icon : html`<ha-svg-icon