import {LitElement, html, css, customElement, property, TemplateResult, CSSResult} from "lit-element"; import {classMap} from "lit-html/directives/class-map"; import {styleMap} from "lit-html/directives/style-map"; import {HomeAssistant} from "./home-assistant-interface"; //import '@polymer/paper-icon-button/paper-icon-button.js'; //import '@polymer/iron-icons/iron-icons.js'; @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 { if(this._config.scenes.length >= 5) { return html`
${this._config.name}
${this.renderCoverControl()}
${this.renderLightControl()}
${this._config.scenes.map((sceneButtonCfg) => this.renderSceneButton(sceneButtonCfg))}
`; } else { return html`
${this._config.name}
${this.renderCoverControl()}
${this._config.scenes.map((sceneButtonCfg) => this.renderSceneButton(sceneButtonCfg))} ${this.renderLightControl()}
`; } } private renderSceneButton(buttonCfg: any) { return html` `; } private renderLightControl() { return html` `; } private renderCoverControl() { return html` `; } private serviceHandler(domain: string, service: string, serviceData: { [key: string]: any } = {}) { const thisObj = this; return function (ev) { ev.stopPropagation(); thisObj.callServiceForAllEntities(domain, service, serviceData); } } private callServiceForAllEntities(domain: string, service: string, serviceData: { [key: string]: any } = {}) { 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; } my-image.clickable { 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; bottom: 0; padding-left: 8px; padding-right: 8px; font-size: 16px; line-height: 40px; color: white; display: flex; flex-direction: row; justify-content: space-between; background-color: rgba(0, 0, 0, 0.3); } .box-top { bottom: 90px; height:45px; padding-top: 0px; padding-bottom: 0; } .box-upper { bottom: 45px; height:45px; padding-top: 0px; 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 { cursor: pointer; padding: 8px; color: #a9a9a9; } ha-icon.state-on { color: white; } `; } }