mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +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 { PersonEntity } from "../../../data/person";
|
||||
|
||||
export const STUB_IMAGE =
|
||||
"https://demo.home-assistant.io/stub_config/bedroom.png";
|
||||
|
||||
@customElement("hui-picture-entity-card")
|
||||
class HuiPictureEntityCard extends LitElement implements LovelaceCard {
|
||||
public static async getConfigElement(): Promise<LovelaceCardEditor> {
|
||||
@ -46,7 +49,7 @@ class HuiPictureEntityCard extends LitElement implements LovelaceCard {
|
||||
return {
|
||||
type: "picture-entity",
|
||||
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);
|
||||
let image: string | undefined = this._config.image;
|
||||
switch (domain) {
|
||||
case "image":
|
||||
image = computeImageUrl(stateObj as ImageEntity);
|
||||
break;
|
||||
case "person":
|
||||
if ((stateObj as PersonEntity).attributes.entity_picture) {
|
||||
image = (stateObj as PersonEntity).attributes.entity_picture;
|
||||
}
|
||||
break;
|
||||
if (!image) {
|
||||
switch (domain) {
|
||||
case "image":
|
||||
image = computeImageUrl(stateObj as ImageEntity);
|
||||
break;
|
||||
case "person":
|
||||
if ((stateObj as PersonEntity).attributes.entity_picture) {
|
||||
image = (stateObj as PersonEntity).attributes.entity_picture;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return html`
|
||||
|
@ -11,6 +11,8 @@ import type { LovelaceCardEditor } from "../../types";
|
||||
import { actionConfigStruct } from "../structs/action-struct";
|
||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
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(
|
||||
baseLovelaceCardConfig,
|
||||
@ -110,7 +112,19 @@ export class HuiPictureEntityCardEditor
|
||||
}
|
||||
|
||||
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>) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user