2019-06-30 19:37:32 +02:00
|
|
|
import {LitElement, html, css, customElement, property, TemplateResult, CSSResult} from "lit-element";
|
|
|
|
import {classMap} from "lit-html/directives/class-map";
|
2020-04-19 10:52:45 +02:00
|
|
|
import {styleMap} from "lit-html/directives/style-map";
|
2019-06-30 19:37:32 +02:00
|
|
|
import {HomeAssistant} from "./home-assistant-interface";
|
2020-07-14 15:42:58 +02:00
|
|
|
//import '@polymer/paper-icon-button/paper-icon-button.js';
|
|
|
|
//import '@polymer/iron-icons/iron-icons.js';
|
2019-06-30 19:37:32 +02:00
|
|
|
|
|
|
|
@customElement("room-glance-card")
|
|
|
|
export class RoomGlanceCard extends LitElement {
|
|
|
|
|
|
|
|
@property() public hass?: HomeAssistant;
|
|
|
|
@property() private _config?: any;
|
|
|
|
|
|
|
|
|
|
|
|
public setConfig(config: any) {
|
|
|
|
//if (!config || !config.entity) {
|
|
|
|
// throw new Error("Invalid configuration");
|
|
|
|
//}
|
|
|
|
console.log("Setting config", config);
|
|
|
|
this._config = config;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static getCardSize(): number {
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected render(): TemplateResult | void {
|
2020-04-19 11:20:24 +02:00
|
|
|
|
|
|
|
if(this._config.scenes.length >= 5) {
|
|
|
|
return html`
|
|
|
|
<ha-card>
|
|
|
|
<img style="width: 100%; display: block" src="${this._config.image}">
|
2019-06-30 19:37:32 +02:00
|
|
|
|
2020-04-19 11:20:24 +02:00
|
|
|
|
|
|
|
<div class="box box-top">
|
|
|
|
<div>${this._config.name}</div>
|
|
|
|
<div>
|
|
|
|
${this.renderCoverControl()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="box box-upper">
|
|
|
|
<div class="title"></div>
|
|
|
|
<div> ${this.renderLightControl()} </div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="box box-lower">
|
|
|
|
<div class="title"></div>
|
|
|
|
<div>
|
|
|
|
${this._config.scenes.map((sceneButtonCfg) => this.renderSceneButton(sceneButtonCfg))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</ha-card>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return html`
|
|
|
|
<ha-card>
|
|
|
|
<img style="width: 100%; display: block" src="${this._config.image}">
|
|
|
|
|
|
|
|
<div class="box box-upper">
|
|
|
|
<div class="title"></div>
|
|
|
|
<div>${this._config.name}</div>
|
|
|
|
<div>
|
|
|
|
${this.renderCoverControl()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="box box-lower">
|
|
|
|
<div class="title"></div>
|
|
|
|
<div>
|
|
|
|
${this._config.scenes.map((sceneButtonCfg) => this.renderSceneButton(sceneButtonCfg))}
|
|
|
|
${this.renderLightControl()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</ha-card>
|
|
|
|
`;
|
|
|
|
}
|
2019-06-30 19:37:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private renderSceneButton(buttonCfg: any) {
|
|
|
|
return html`
|
2020-07-14 15:42:58 +02:00
|
|
|
<ha-icon-button
|
2019-06-30 19:37:32 +02:00
|
|
|
icon="${buttonCfg.icon || "mdi:checkbox-blank"}"
|
|
|
|
title="${buttonCfg.name}"
|
|
|
|
@click=${this.serviceHandler("scene", "turn_on", {entity_id: buttonCfg.scene})}
|
2022-08-28 22:33:35 +02:00
|
|
|
>
|
|
|
|
<ha-icon style="color: ${buttonCfg.color || ""};"
|
|
|
|
icon="${buttonCfg.icon || "mdi:checkbox-blank"}"></ha-icon>
|
|
|
|
</ha-icon-button>
|
2019-06-30 19:37:32 +02:00
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2020-04-19 11:20:24 +02:00
|
|
|
private renderLightControl() {
|
2019-06-30 19:37:32 +02:00
|
|
|
return html`
|
2020-07-14 15:42:58 +02:00
|
|
|
<ha-icon-button
|
2020-04-19 11:20:24 +02:00
|
|
|
icon="mdi:close-circle"
|
|
|
|
@click=${this.serviceHandler("light", "turn_off")}
|
2022-08-28 22:33:35 +02:00
|
|
|
>
|
|
|
|
<ha-icon icon="mdi:close-circle"></ha-icon>
|
|
|
|
</ha-icon-button>
|
2020-04-19 11:20:24 +02:00
|
|
|
|
2020-07-14 15:42:58 +02:00
|
|
|
<ha-icon-button
|
2020-04-19 11:20:24 +02:00
|
|
|
icon="mdi:chevron-up"
|
|
|
|
title="Heller"
|
|
|
|
@click=${this.serviceHandler("dimmer", "dim", {offset: 30})}
|
2022-08-28 22:33:35 +02:00
|
|
|
>
|
|
|
|
<ha-icon icon="mdi:chevron-up"></ha-icon>
|
|
|
|
</ha-icon-button>
|
2020-07-14 15:42:58 +02:00
|
|
|
<ha-icon-button
|
2020-04-19 11:20:24 +02:00
|
|
|
icon="mdi:chevron-down"
|
|
|
|
title="Dunkler"
|
|
|
|
@click=${this.serviceHandler("dimmer", "dim", {offset: -30})}
|
2022-08-28 22:33:35 +02:00
|
|
|
>
|
|
|
|
<ha-icon icon="mdi:chevron-down"></ha-icon>
|
|
|
|
</ha-icon-button>`;
|
2020-04-19 11:20:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private renderCoverControl() {
|
|
|
|
return html`
|
2020-07-14 15:42:58 +02:00
|
|
|
<ha-icon-button
|
2019-06-30 19:37:32 +02:00
|
|
|
icon="hass:menu"
|
|
|
|
@click=${this.serviceHandler("cover_half", "set_half")}
|
2022-08-28 22:33:35 +02:00
|
|
|
>
|
|
|
|
<ha-icon icon="hass:menu"></ha-icon>
|
|
|
|
</ha-icon-button>
|
2020-07-14 15:42:58 +02:00
|
|
|
<ha-icon-button
|
2019-06-30 19:37:32 +02:00
|
|
|
icon="hass:arrow-up"
|
|
|
|
@click=${this.serviceHandler("cover", "open_cover")}
|
2022-08-28 22:33:35 +02:00
|
|
|
>
|
|
|
|
<ha-icon icon="hass:arrow-up"></ha-icon>
|
|
|
|
</ha-icon-button>
|
2020-07-14 15:42:58 +02:00
|
|
|
<ha-icon-button
|
2019-06-30 19:37:32 +02:00
|
|
|
icon="hass:stop"
|
|
|
|
@click=${this.serviceHandler("cover", "stop_cover")}
|
2022-08-28 22:33:35 +02:00
|
|
|
>
|
|
|
|
<ha-icon icon="hass:stop"></ha-icon>
|
|
|
|
</ha-icon-button>
|
2020-07-14 15:42:58 +02:00
|
|
|
<ha-icon-button
|
2019-06-30 19:37:32 +02:00
|
|
|
icon="hass:arrow-down"
|
|
|
|
@click=${this.serviceHandler("cover", "close_cover")}
|
2022-08-28 22:33:35 +02:00
|
|
|
>
|
|
|
|
<ha-icon icon="hass:arrow-down"></ha-icon>
|
|
|
|
</ha-icon-button>
|
2019-06-30 19:37:32 +02:00
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2020-04-19 10:52:45 +02:00
|
|
|
private serviceHandler(domain: string, service: string, serviceData: { [key: string]: any } = {}) {
|
2019-06-30 19:37:32 +02:00
|
|
|
const thisObj = this;
|
2020-04-19 10:52:45 +02:00
|
|
|
return function (ev) {
|
2019-06-30 19:37:32 +02:00
|
|
|
ev.stopPropagation();
|
|
|
|
thisObj.callServiceForAllEntities(domain, service, serviceData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-19 10:52:45 +02:00
|
|
|
private callServiceForAllEntities(domain: string, service: string, serviceData: { [key: string]: any } = {}) {
|
2019-06-30 19:37:32 +02:00
|
|
|
|
|
|
|
if (!serviceData.hasOwnProperty('entity_id')) {
|
|
|
|
for (let entity_id of this._config!.entities) {
|
|
|
|
serviceData['entity_id'] = entity_id;
|
|
|
|
console.log("Calling service", domain, service, serviceData);
|
|
|
|
this.hass!.callService(domain, service, serviceData);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.log("Calling service with given entity_id", domain, service, serviceData);
|
|
|
|
this.hass!.callService(domain, service, serviceData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private _handleTap() {
|
|
|
|
console.log("Image tap");
|
|
|
|
}
|
|
|
|
|
|
|
|
private _handleHold() {
|
|
|
|
console.log("Image hold");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static get styles(): CSSResult {
|
|
|
|
return css`
|
|
|
|
ha-card {
|
|
|
|
position: relative;
|
|
|
|
min-height: 48px;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
2020-04-19 10:52:45 +02:00
|
|
|
my-image.clickable {
|
2019-06-30 19:37:32 +02:00
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
.box {
|
|
|
|
/* start paper-font-common-nowrap style */
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
/* end paper-font-common-nowrap style */
|
|
|
|
|
|
|
|
position: absolute;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
2020-04-19 10:52:45 +02:00
|
|
|
bottom: 0;
|
|
|
|
|
2019-06-30 19:37:32 +02:00
|
|
|
padding-left: 8px;
|
|
|
|
padding-right: 8px;
|
|
|
|
|
|
|
|
font-size: 16px;
|
|
|
|
line-height: 40px;
|
|
|
|
color: white;
|
|
|
|
display: flex;
|
2020-04-19 10:52:45 +02:00
|
|
|
flex-direction: row;
|
2019-06-30 19:37:32 +02:00
|
|
|
justify-content: space-between;
|
|
|
|
background-color: rgba(0, 0, 0, 0.3);
|
|
|
|
}
|
2020-04-19 11:20:24 +02:00
|
|
|
|
|
|
|
.box-top {
|
|
|
|
bottom: 90px;
|
|
|
|
height:45px;
|
|
|
|
padding-top: 0px;
|
|
|
|
padding-bottom: 0;
|
|
|
|
}
|
2019-06-30 19:37:32 +02:00
|
|
|
|
|
|
|
.box-upper {
|
|
|
|
bottom: 45px;
|
2020-04-19 11:20:24 +02:00
|
|
|
height:45px;
|
|
|
|
padding-top: 0px;
|
2019-06-30 19:37:32 +02:00
|
|
|
padding-bottom: 0;
|
|
|
|
}
|
|
|
|
.box-lower {
|
|
|
|
bottom: 0;
|
|
|
|
padding-top: 0;
|
|
|
|
padding-bottom: 0px;
|
|
|
|
height:45px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.box .title {
|
|
|
|
font-weight: 500;
|
|
|
|
margin-left: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
ha-icon {
|
2022-08-28 22:33:35 +02:00
|
|
|
height: auto;
|
2019-06-30 19:37:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ha-icon.state-on {
|
|
|
|
color: white;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|