mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 03:06:41 +00:00
Prioritize local image over entity_picture in picture-entity card (#24032)
* Prioritize local image over entity_picture in picture-entity * Remove the default stub image if we switch to an entity with a picture * minor cleanup
This commit is contained in:
parent
863ff622be
commit
aea98f702b
@ -22,6 +22,9 @@ import type { PictureEntityCardConfig } from "./types";
|
|||||||
import type { CameraEntity } from "../../../data/camera";
|
import type { CameraEntity } from "../../../data/camera";
|
||||||
import type { PersonEntity } from "../../../data/person";
|
import type { PersonEntity } from "../../../data/person";
|
||||||
|
|
||||||
|
export const STUB_IMAGE =
|
||||||
|
"https://demo.home-assistant.io/stub_config/bedroom.png";
|
||||||
|
|
||||||
@customElement("hui-picture-entity-card")
|
@customElement("hui-picture-entity-card")
|
||||||
class HuiPictureEntityCard extends LitElement implements LovelaceCard {
|
class HuiPictureEntityCard extends LitElement implements LovelaceCard {
|
||||||
public static async getConfigElement(): Promise<LovelaceCardEditor> {
|
public static async getConfigElement(): Promise<LovelaceCardEditor> {
|
||||||
@ -46,7 +49,7 @@ class HuiPictureEntityCard extends LitElement implements LovelaceCard {
|
|||||||
return {
|
return {
|
||||||
type: "picture-entity",
|
type: "picture-entity",
|
||||||
entity: foundEntities[0] || "",
|
entity: foundEntities[0] || "",
|
||||||
image: "https://demo.home-assistant.io/stub_config/bedroom.png",
|
image: STUB_IMAGE,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,15 +137,17 @@ class HuiPictureEntityCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
const domain: string = computeDomain(this._config.entity);
|
const domain: string = computeDomain(this._config.entity);
|
||||||
let image: string | undefined = this._config.image;
|
let image: string | undefined = this._config.image;
|
||||||
switch (domain) {
|
if (!image) {
|
||||||
case "image":
|
switch (domain) {
|
||||||
image = computeImageUrl(stateObj as ImageEntity);
|
case "image":
|
||||||
break;
|
image = computeImageUrl(stateObj as ImageEntity);
|
||||||
case "person":
|
break;
|
||||||
if ((stateObj as PersonEntity).attributes.entity_picture) {
|
case "person":
|
||||||
image = (stateObj as PersonEntity).attributes.entity_picture;
|
if ((stateObj as PersonEntity).attributes.entity_picture) {
|
||||||
}
|
image = (stateObj as PersonEntity).attributes.entity_picture;
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
|
@ -11,6 +11,8 @@ import type { LovelaceCardEditor } from "../../types";
|
|||||||
import { actionConfigStruct } from "../structs/action-struct";
|
import { actionConfigStruct } from "../structs/action-struct";
|
||||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||||
import { configElementStyle } from "./config-elements-style";
|
import { configElementStyle } from "./config-elements-style";
|
||||||
|
import { computeDomain } from "../../../../common/entity/compute_domain";
|
||||||
|
import { STUB_IMAGE } from "../../cards/hui-picture-entity-card";
|
||||||
|
|
||||||
const cardConfigStruct = assign(
|
const cardConfigStruct = assign(
|
||||||
baseLovelaceCardConfig,
|
baseLovelaceCardConfig,
|
||||||
@ -110,7 +112,19 @@ export class HuiPictureEntityCardEditor
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _valueChanged(ev: CustomEvent): void {
|
private _valueChanged(ev: CustomEvent): void {
|
||||||
fireEvent(this, "config-changed", { config: ev.detail.value });
|
const config = ev.detail.value;
|
||||||
|
if (
|
||||||
|
config.entity &&
|
||||||
|
config.entity !== this._config?.entity &&
|
||||||
|
(computeDomain(config.entity) === "image" ||
|
||||||
|
(computeDomain(config.entity) === "person" &&
|
||||||
|
this.hass?.states[config.entity]?.attributes.entity_picture)) &&
|
||||||
|
config.image === STUB_IMAGE
|
||||||
|
) {
|
||||||
|
delete config.image;
|
||||||
|
}
|
||||||
|
|
||||||
|
fireEvent(this, "config-changed", { config });
|
||||||
}
|
}
|
||||||
|
|
||||||
private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) => {
|
private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user