mirror of
https://github.com/home-assistant/frontend.git
synced 2026-07-10 22:28:01 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8f679d12ff | |||
| 20793ecdba | |||
| afe044d152 | |||
| dc2038916b | |||
| cf8e2a6d02 | |||
| 3269b2878b |
@@ -1,3 +1,5 @@
|
||||
---
|
||||
title: Selectors
|
||||
---
|
||||
|
||||
See the website for [list of available selectors](https://www.home-assistant.io/docs/blueprint/selectors/).
|
||||
|
||||
@@ -49,7 +49,8 @@ import "../ha-svg-icon";
|
||||
import "../ha-fab";
|
||||
import { browseLocalMediaPlayer } from "../../data/media_source";
|
||||
import { isTTSMediaSource } from "../../data/tts";
|
||||
import { TtsMediaPickedEvent } from "./ha-browse-media-tts";
|
||||
import type { TtsMediaPickedEvent } from "./ha-browse-media-tts";
|
||||
import "./ha-browse-media-tts";
|
||||
|
||||
declare global {
|
||||
interface HASSDomEvents {
|
||||
|
||||
@@ -3,6 +3,7 @@ import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { load } from "js-yaml";
|
||||
import { debounce } from "../../../common/util/debounce";
|
||||
import "../../../components/ha-circular-progress";
|
||||
import "../../../components/ha-code-editor";
|
||||
@@ -51,6 +52,10 @@ class HaPanelDevTemplate extends LitElement {
|
||||
|
||||
private _template = "";
|
||||
|
||||
private _context_data = "";
|
||||
|
||||
private _context_variables?;
|
||||
|
||||
private _inited = false;
|
||||
|
||||
public connectedCallback() {
|
||||
@@ -65,8 +70,14 @@ class HaPanelDevTemplate extends LitElement {
|
||||
}
|
||||
|
||||
protected firstUpdated() {
|
||||
if (localStorage && localStorage["panel-dev-template-template"]) {
|
||||
this._template = localStorage["panel-dev-template-template"];
|
||||
if (localStorage) {
|
||||
if (localStorage["panel-dev-template-template"]) {
|
||||
this._template = localStorage["panel-dev-template-template"];
|
||||
}
|
||||
if (localStorage["panel-dev-template-context-data"]) {
|
||||
this._context_data = localStorage["panel-dev-template-context-data"];
|
||||
this._context_variables = undefined;
|
||||
}
|
||||
} else {
|
||||
this._template = DEMO_TEMPLATE;
|
||||
}
|
||||
@@ -141,6 +152,17 @@ class HaPanelDevTemplate extends LitElement {
|
||||
"ui.panel.developer-tools.tabs.templates.reset"
|
||||
)}
|
||||
</mwc-button>
|
||||
<p>
|
||||
${this.hass.localize(
|
||||
"ui.panel.developer-tools.tabs.templates.context_data"
|
||||
)}
|
||||
</p>
|
||||
<ha-code-editor
|
||||
mode="yaml"
|
||||
.value=${this._context_data}
|
||||
@value-changed=${this._contextDataChanged}
|
||||
dir="ltr"
|
||||
></ha-code-editor>
|
||||
</div>
|
||||
|
||||
<div class="render-pane">
|
||||
@@ -302,6 +324,15 @@ class HaPanelDevTemplate extends LitElement {
|
||||
false
|
||||
);
|
||||
|
||||
private _contextDataChanged(ev) {
|
||||
this._context_data = ev.detail.value;
|
||||
this._context_variables = undefined;
|
||||
if (this._error) {
|
||||
this._error = undefined;
|
||||
}
|
||||
this._debounceRender();
|
||||
}
|
||||
|
||||
private _templateChanged(ev) {
|
||||
this._template = ev.detail.value;
|
||||
if (this._error) {
|
||||
@@ -314,6 +345,9 @@ class HaPanelDevTemplate extends LitElement {
|
||||
this._rendering = true;
|
||||
await this._unsubscribeTemplate();
|
||||
try {
|
||||
if (this._context_data && !this._context_variables) {
|
||||
this._context_variables = load(this._context_data);
|
||||
}
|
||||
this._unsubRenderTemplate = subscribeRenderTemplate(
|
||||
this.hass.connection,
|
||||
(result) => {
|
||||
@@ -322,6 +356,7 @@ class HaPanelDevTemplate extends LitElement {
|
||||
},
|
||||
{
|
||||
template: this._template,
|
||||
variables: this._context_variables,
|
||||
timeout: 3,
|
||||
}
|
||||
);
|
||||
@@ -360,12 +395,16 @@ class HaPanelDevTemplate extends LitElement {
|
||||
if (!this._inited) {
|
||||
return;
|
||||
}
|
||||
localStorage["panel-dev-template-context-data"] = this._context_data;
|
||||
localStorage["panel-dev-template-template"] = this._template;
|
||||
}
|
||||
|
||||
private _restoreDemo() {
|
||||
this._context_data = "";
|
||||
this._context_variables = undefined;
|
||||
this._template = DEMO_TEMPLATE;
|
||||
this._subscribeTemplate();
|
||||
delete localStorage["panel-dev-template-context-data"];
|
||||
delete localStorage["panel-dev-template-template"];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export class BrowserMediaPlayer {
|
||||
|
||||
constructor(
|
||||
public hass: HomeAssistant,
|
||||
private item: MediaPlayerItem,
|
||||
public item: MediaPlayerItem,
|
||||
private onChange: () => void
|
||||
) {}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
TemplateResult,
|
||||
} from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
import { computeDomain } from "../../common/entity/compute_domain";
|
||||
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
||||
@@ -164,7 +165,11 @@ class BarMediaPlayer extends LitElement {
|
||||
|
||||
return html`
|
||||
<div
|
||||
class="info ${!isBrowser ? "pointer" : ""}"
|
||||
class=${classMap({
|
||||
info: true,
|
||||
pointer: !isBrowser,
|
||||
app: this._browserPlayer?.item.media_class === "app",
|
||||
})}
|
||||
@click=${this._openMoreInfo}
|
||||
>
|
||||
${mediaArt ? html`<img src=${this.hass.hassUrl(mediaArt)} />` : ""}
|
||||
@@ -498,6 +503,11 @@ class BarMediaPlayer extends LitElement {
|
||||
max-height: 100px;
|
||||
}
|
||||
|
||||
.app img {
|
||||
max-height: 68px;
|
||||
margin: 16px 0 16px 16px;
|
||||
}
|
||||
|
||||
ha-button-menu mwc-button {
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
@@ -291,6 +291,7 @@ class PanelMediaBrowser extends LitElement {
|
||||
"change",
|
||||
async () => {
|
||||
const files = input.files!;
|
||||
document.body.removeChild(input);
|
||||
const target = this._currentItem!.media_content_id!;
|
||||
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
@@ -315,6 +316,9 @@ class PanelMediaBrowser extends LitElement {
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
// https://stackoverflow.com/questions/47664777/javascript-file-input-onchange-not-working-ios-safari-only
|
||||
input.style.display = "none";
|
||||
document.body.append(input);
|
||||
input.click();
|
||||
}
|
||||
|
||||
|
||||
@@ -4093,6 +4093,7 @@
|
||||
"no_listeners": "This template does not listen for any events and will not update automatically.",
|
||||
"listeners": "This template listens for the following state changed events:",
|
||||
"entity": "Entity",
|
||||
"context_data": "Context data for template",
|
||||
"domain": "Domain"
|
||||
},
|
||||
"statistics": {
|
||||
|
||||
Reference in New Issue
Block a user