-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
picture cards: add person image support (#20593)
* picture cards: add person image support * fix: person attributes typing * review: apply comment from @coderabbitai * fix lint:types * review: put person domain in image_entity config * add picture card compatibility & exemple in gallery * fix lint * Allow only image or person domains on image_entity editor config Co-authored-by: Simon Lamon <[email protected]> * fix domain type * gracefully use the default config.image if the person don't have an image * gracefully use the default config.image if the person don't have an image (that works) --------- Co-authored-by: Simon Lamon <[email protected]>
- Loading branch information
Showing
15 changed files
with
214 additions
and
20 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: Picture Card | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { html, LitElement, PropertyValues, TemplateResult } from "lit"; | ||
import { customElement, query } from "lit/decorators"; | ||
import { getEntity } from "../../../../src/fake_data/entity"; | ||
import { provideHass } from "../../../../src/fake_data/provide_hass"; | ||
import "../../components/demo-cards"; | ||
import { mockIcons } from "../../../../demo/src/stubs/icons"; | ||
|
||
const ENTITIES = [ | ||
getEntity("person", "paulus", "home", { | ||
friendly_name: "Paulus", | ||
entity_picture: "/images/paulus.jpg", | ||
}), | ||
]; | ||
|
||
const CONFIGS = [ | ||
{ | ||
heading: "Image URL", | ||
config: ` | ||
- type: picture | ||
image: /images/living_room.png | ||
`, | ||
}, | ||
{ | ||
heading: "Person entity", | ||
config: ` | ||
- type: picture | ||
image_entity: person.paulus | ||
`, | ||
}, | ||
{ | ||
heading: "Error: Image required", | ||
config: ` | ||
- type: picture | ||
entity: person.paulus | ||
`, | ||
}, | ||
]; | ||
|
||
@customElement("demo-lovelace-picture-card") | ||
class DemoPicture extends LitElement { | ||
@query("#demos") private _demoRoot!: HTMLElement; | ||
|
||
protected render(): TemplateResult { | ||
return html`<demo-cards id="demos" .configs=${CONFIGS}></demo-cards>`; | ||
} | ||
|
||
protected firstUpdated(changedProperties: PropertyValues) { | ||
super.firstUpdated(changedProperties); | ||
const hass = provideHass(this._demoRoot); | ||
hass.updateTranslations(null, "en"); | ||
hass.updateTranslations("lovelace", "en"); | ||
hass.addEntities(ENTITIES); | ||
mockIcons(hass); | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"demo-lovelace-picture-card": DemoPicture; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.