lit-element#TemplateResult TypeScript Examples
The following examples show how to use
lit-element#TemplateResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: grid-view.ts From Custom-Grid-View with MIT License | 6 votes |
private _itemRenderer = (key: string): TemplateResult => {
if (!this._cards) {
return html``;
}
return html`
${this._cards[key]}
`;
};
Example #2
Source File: linak-desk-card.ts From linak-desk-card with MIT License | 6 votes |
protected render(): TemplateResult | void {
return html`
<ha-card .header=${this.config.name}>
${this.config.connection_sensor ? html`<div class="connection">
${localize(this.connected ? 'status.connected' : 'status.disconnected')}
<div class="indicator ${this.connected ? 'connected' : 'disconnected'}" ></div>
</div>` : html``}
<div class="preview">
<img src="${tableTopImg}" style="transform: translateY(${this.calculateOffset(90)}px);" />
<img src="${tableMiddleImg}" style="transform: translateY(${this.calculateOffset(60)}px);" />
<img src="${tableBottomImg}" />
<div class="height" style="transform: translateY(${this.calculateOffset(90)}px);">
${this.height}
<span>cm</span>
</div>
<div class="knob">
<div class="knob-button"
@touchstart='${this.goUp}'
@mousedown='${this.goUp}'
@touchend='${this.stop}'
@mouseup='${this.stop}'>
<ha-icon icon="mdi:chevron-up"></ha-icon>
</div>
<div class="knob-button"
@touchstart=${this.goDown}
@mousedown=${this.goDown}
@touchend=${this.stop}
@mouseup=${this.stop}>
<ha-icon icon="mdi:chevron-down"></ha-icon>
</div>
</div>
${this.renderPresets()}
</div>
</ha-card>
`;
}
Example #3
Source File: linak-desk-card.ts From linak-desk-card with MIT License | 6 votes |
renderPresets(): TemplateResult {
const presets = this.config.presets || [];
return html`
<div class="presets">
${presets.map(item => html`
<paper-button @click="${() => this.handlePreset(item.target)}">
${item.label} - ${item.target} cm
</paper-button>`)}
</div>
`;
}
Example #4
Source File: LoadIcons.ts From ExpressiveAnimator with Apache License 2.0 | 6 votes |
export function createIconSet(name: string, icons: any) {
icons = html([icons] as any);
return class extends IconsetSVG {
public constructor() {
super();
this.name = name;
}
protected renderDefaultContent(): TemplateResult {
return icons;
}
}
}
Example #5
Source File: harmony-card.ts From harmony-card with MIT License | 6 votes |
private renderActivityButton(outlined: boolean, command: string, label: string, showIcon = false, icon?: string,): TemplateResult {
return html`
${showIcon && icon
? html`
<ha-icon-button
icon="${icon}"
?outlined="${outlined}"
@click="${e => this.harmonyCommand(e, command)}"
@touchstart="${e => this.preventBubbling(e)}"
><ha-icon icon="${icon}"></ha-icon>
</ha-icon-button>
`
: html`
<mwc-button
?outlined="${outlined}"
label="${label}"
@click="${e => this.harmonyCommand(e, command)}"
@touchstart="${e => this.preventBubbling(e)}"
></mwc-button>
`}
`;
}
Example #6
Source File: select-list-card.ts From select-list-card with MIT License | 6 votes |
private showError(): TemplateResult {
return html`
<ha-card>
<div class="preview not-available">
<div class="metadata">
<div class="not-available">
${localize('error.not_available')}
</div>
<div>
</div>
</ha-card>
`;
}
Example #7
Source File: pwa-auth.ts From pwa-auth with MIT License | 6 votes |
private renderLoginButton(): TemplateResult {
return html`
<div class="dropdown" @focusout="${this.dropdownFocusOut}">
<button class="signin-btn" part="signInButton" ?disabled=${this.disabled} @click="${this.signInClicked}">
${this.signInButtonText}
</button>
<div class="menu ${this.menuOpened ? "open" : ""} ${this.menuPlacement === "end" ? "align-end" : ""}" part="dropdownMenu">
${this.renderListButtons()}
</div>
</div>
`;
}
Example #8
Source File: pwa-auth.ts From pwa-auth with MIT License | 6 votes |
private renderListButtons(): TemplateResult {
return html`
${this.providers
.filter(provider => !!provider.getKey())
.map(provider => html`
<div class="provider" part="${provider.containerPartName}">
<button class="${provider.btnClass}" ?disabled=${this.disabled} part="${provider.buttonPartName}" @click="${provider.signIn}">
<img part="${provider.iconPartName}" loading="${this.iconLoading}" width="20px" height="20px" src="${provider.getIconUrl()}" />
${provider.getButtonText()}
</button>
</div>
`)}
`;
}
Example #9
Source File: pwa-auth.d.ts From pwa-auth with MIT License | 5 votes |
render(): void | TemplateResult;
Example #10
Source File: grid-view.ts From Custom-Grid-View with MIT License | 5 votes |
protected render(): TemplateResult {
return html`
${this.lovelace.editMode
? html`
<div class="toolbar">
<mwc-button @click=${this._saveView} raised>Save Layout</mwc-button>
</div>
`
: ''}
<div id="badges" style=${this.badges.length > 0 ? 'display: block' : 'display: none'}>
${this.badges.map(
badge =>
html`
${badge}
`,
)}
</div>
<lit-grid-layout
rowHeight="40"
.containerPadding=${[8, 8]}
.margin=${[8, 8]}
.resizeHandle=${RESIZE_HANDLE}
.itemRenderer=${this._itemRenderer}
.layout=${this._layout}
.columns=${this._columns}
.dragHandle=${'.overlay'}
.dragDisabled=${!this.lovelace?.editMode}
.resizeDisabled=${!this.lovelace?.editMode}
@item-changed=${this._saveLayout}
></lit-grid-layout>
${this.lovelace?.editMode
? html`
<mwc-fab
class=${classMap({
rtl: computeRTL(this.hass!),
})}
.title=${this.hass!.localize('ui.panel.lovelace.editor.edit_card.add')}
@click=${this._addCard}
>
<ha-svg-icon slot="icon" .path=${mdiPlus}></ha-svg-icon>
</mwc-fab>
`
: ''}
`;
}
Example #11
Source File: harmony-card.ts From harmony-card with MIT License | 5 votes |
protected render(): TemplateResult | void {
if (!this._config || !this.hass) {
return html``;
}
// TODO Check for stateObj or other necessary things and render a warning if missing
if (this._config.show_warning) {
return html`
<ha-card>
<div class="warning">${localize('common.show_warning')}</div>
</ha-card>
`;
}
var hubState = this.hass.states[this._config.entity];
var hubPowerState = hubState.state;
var currentActivity = hubState.attributes.current_activity;
var currentActivityConfig = this._config.activities.find(activity => activity.name === currentActivity);
var currentDevice = currentActivityConfig?.device;
var buttonConfig = this.computeButtonConfig(this._config, currentActivityConfig);
return html`
<ha-card
style=${this.computeStyles()}
.header=${this._config.name}
@action=${this._handleAction}
.actionHandler=${actionHandler({
hasHold: hasAction(this._config.hold_action),
hasDoubleClick: hasAction(this._config.double_tap_action),
})}
tabindex="0"
aria-label=${`Harmony: ${this._config.entity}`}
>
<div class="card-content">
${this.renderActivityButtons(this._config, hubPowerState, currentActivity)}
${this.renderVolumeControls(this.hass, this._config, buttonConfig, currentActivityConfig)}
${this.renderKeyPad(this._config, buttonConfig, currentActivityConfig, currentDevice)}
<div class="play-pause">
${this.renderIconButton(buttonConfig['skip_back'], currentDevice)}
${this.renderIconButton(buttonConfig['play'], currentDevice)}
${this.renderIconButton(buttonConfig['pause'], currentDevice)}
${this.renderIconButton(buttonConfig['skip_forward'], currentDevice)}
</div>
<div class="remote">
${this.renderIconButton(buttonConfig['dpad_left'], currentDevice, { 'grid-column': '1', 'grid-row': '2' })}
${this.renderIconButton(buttonConfig['dpad_right'], currentDevice, { 'grid-column': '3', 'grid-row': '2' })}
${this.renderIconButton(buttonConfig['dpad_up'], currentDevice, { 'grid-column': '2', 'grid-row': '1' })}
${this.renderIconButton(buttonConfig['dpad_down'], currentDevice, { 'grid-column': '2', 'grid-row': '3' })}
${this.renderIconButton(buttonConfig['dpad_center'], currentDevice, { 'grid-column': '2', 'grid-row': '2' })}
</div>
<div class="xbox-buttons">
${this.renderIconButton(buttonConfig['xbox'], currentDevice, { 'grid-column': '1', 'grid-row': '2' })}
${this.renderIconButton(buttonConfig['back'], currentDevice, { 'grid-column': '2', 'grid-row': '2' })}
${this.renderIconButton(buttonConfig['a'], currentDevice, { 'grid-column': '4', 'grid-row': '2' })}
${this.renderIconButton(buttonConfig['b'], currentDevice, { 'grid-column': '5', 'grid-row': '2' })}
${this.renderIconButton(buttonConfig['x'], currentDevice, { 'grid-column': '6', 'grid-row': '2' })}
${this.renderIconButton(buttonConfig['y'], currentDevice, { 'grid-column': '7', 'grid-row': '2' })}
</div>
</div>
</ha-card>
`;
}
Example #12
Source File: pwa-auth.ts From pwa-auth with MIT License | 5 votes |
private renderNoKeysError(): TemplateResult {
return html`<div class="provider-error"><strong>❌ No available sign-ins</strong><br><em>To enable sign-in, pass a Microsoft key, Google key, Facebook, or Apple key to the <pwa-auth> component.</em><br><pre><pwa-auth microsoftkey="..."></pwa-auth></pre></div>`;
}
Example #13
Source File: mini-thermostat.ts From lovelace-mini-thermostat with MIT License | 5 votes |
protected render(): TemplateResult | void {
if (!this.config || !this.hass) {
return html``;
}
if (!this.entity) {
return html`
<ha-card>
<div class="warning">${localize('common.config.not-available')}</div>
</ha-card>
`;
}
return html`
<ha-card
class="${this._computeClasses()}"
tabindex="0"
aria-label="${`MiniThermostat: ${this.config.entity}`}"
.header="${this.config!.name}"
>
<div class="flex-box">
<div class="state">
${this._renderState()}
</div>
<div class="container-middle">
${this._renderMiddle()}
</div>
${this._renderEnd()}
</div>
</ha-card>
`;
}
Example #14
Source File: search.ts From medblocks-ui with Apache License 2.0 | 5 votes |
/**Function to get results from an external source */
async getResults(): Promise<TemplateResult | TemplateResult[]> {
if (this._debouncing) {
return this._loadingResults;
}
if (this.mock.length) {
return this.mock.map(
r => html`<sl-menu-item value=${r} .label=${r}>${r}</sl-menu-item>`
);
}
if (!this.searchTerm) {
return [];
}
try {
const axios = this.axios ? this.axios : this._parentAxios;
const result = await this.plugin.search({
maxHits: this._maxHits,
searchString: this.searchTerm,
axios,
constraint: this._constraint,
});
const results = result.map(
r =>
html`
<sl-menu-item
value=${r.value}
.label=${r.label}
.terminology=${this.terminology}
>
${r.star
? html`<sl-icon slot="suffix" name="star"></sl-icon>`
: null}
${r.label}
</sl-menu-item>
`
);
if (results?.length === 0) {
return html`<sl-menu-item disabled>No results</sl-menu-item>`;
}
return this._maxHits === results.length
? [...results, this._viewMore]
: results;
} catch (e) {
console.error(e);
return html`
<sl-menu-item disabled>
<sl-icon name="exclamation-triangle" slot="prefix"></sl-icon>
An unexpected error occured
</sl-menu-item>
`;
}
}
Example #15
Source File: select-list-card.ts From select-list-card with MIT License | 5 votes |
protected render(): TemplateResult | void { if (!this.config.entity) { return this.showError(); } const stateObj = this.stateObj; const selected = stateObj.state; this.options = stateObj.attributes.options; const style = this.config.max_options === 0 ? '' : `max-height: ${(this.config.max_options || 5) * 48 + 16}px`; return html` <ha-card aria-label=${`Select list card: ${this.config.entity}`}> ${this.config.title && this.config.title.length ? html` <div class="card-header ${this.config.show_toggle ? 'pointer' : ''}" @click=${this.toggle} ?open=${this.open} > <div class="name"> ${this.config.icon && this.config.icon.length ? html` <ha-icon class="icon" .icon="${this.config.icon}"></ha-icon> ` : ''} ${this.config.title} </div> ${this.config.show_toggle ? html` <ha-icon class="pointer" .icon="${this.open ? 'mdi:chevron-up' : 'mdi:chevron-down'}"></ha-icon> ` : ''} </div> ` : ''} <paper-listbox id="list" @iron-select=${this.selectedOptionChanged} .selected=${this.options.indexOf(selected)} style="${style}" ?open=${this.open} > ${this.options.map(option => { if (this.config.truncate) { return html` <paper-item title="${option}"><div class="truncate-item">${option}</div></paper-item> `; } return html` <paper-item>${option}</paper-item> `; })} </paper-listbox> </ha-card> `; }
Example #16
Source File: ha-card-weather-conditions.ts From ha-card-weather-conditions with MIT License | 4 votes |
Promise.all(findImagePath).then((testResults) => {
let hacsImages: boolean, manImages: boolean ;
hacsImages = hacsImagePathExist = testResults[0] ;
manImages = manImagePathExist = testResults[1] ;
globalImagePath = (hacsImages ? hacsImagePath : manImages ? manImagePath : null) ;
let translPath = globalImagePath + '/../transl/' ;
let findTranslation = [
loadJSON(translPath + 'en.json'),
loadJSON(translPath + 'it.json'),
loadJSON(translPath + 'nl.json'),
loadJSON(translPath + 'es.json'),
loadJSON(translPath + 'de.json'),
loadJSON(translPath + 'fr.json'),
loadJSON(translPath + 'sr-latn.json'),
loadJSON(translPath + 'pt.json'),
loadJSON(translPath + 'da.json'),
loadJSON(translPath + 'no-NO.json')
] ;
if( hacsImages ) console.info(logo + "%c use HACS path to retrieve icons.", optConsoleParam1, optConsoleParam2, optConsoleParam3);
else if ( manImages ) console.info(logo + "%c use www root path to retrieve icons.", optConsoleParam1, optConsoleParam2, optConsoleParam3);
else console.info(logo + "%c error setting right icons path.", optConsoleParam1, optConsoleParam2, optConsoleParam3);
Promise.all(findTranslation).then((translations) => {
@customElement("ha-card-weather-conditions")
class HaCardWeatherConditions extends LitElement {
@property() public hass?: HomeAssistant;
@property() private _config?: CardConfig;
private _iconsConfig: IconsConfig = new class implements IconsConfig {
iconType: string;
icons_model: string ;
iconsDay: { [p: string]: string };
iconsNight: { [p: string]: string };
path: string ;
};
private _terms: ITerms = new class implements ITerms {
windDirections;
words;
};
private invalidConfig: boolean = false ;
private numberElements: number = 0 ;
private _header: boolean = true ;
private _name: string = '' ;
private _language: string ;
private _hasCurrent: boolean = false ;
private _hasForecast: boolean = false ;
private _hasMeteogram: boolean = false ;
private _hasAirQuality: boolean = false ;
private _hasPollen: boolean = false ;
private _hasUv: boolean = false ;
private _hasAlert: boolean = false ;
private _hasSea: boolean = false ;
private _displayTop: boolean = true ;
private _displayCurrent: boolean = true ;
private _displayForecast: boolean = true ;
private _classNameSuffix: string ;
private _showSummary: boolean = true ;
private _showPresent: boolean = true ;
private _showUv: boolean = true ;
private _showAirQuality: boolean = true ;
private _showPollen: boolean = true ;
private _showForecast: boolean = true ;
private _showAlert: boolean = true ;
private _showSea: boolean = true ;
/**
*
* @param {CardConfig} config
*/
public setConfig(config: CardConfig) {
console.log({card_config: config});
if (!config) {
this.invalidConfig = true;
throw new Error("Invalid configuration");
}
if (config.name && config.name.length > 0) {
this._name = config.name;
}
if (config.language && config.language.length > 0) {
this._language = config.language.toLowerCase();
} else this._language = 'en';
let transls ;
try {
transls = JSON.parse(translations[cwcLocale[this._language]]);
this._terms.windDirections = transls.cwcLocWindDirections ;
this._terms.words = transls.cwcTerms ;
console.info(logo + "%c card \"" + this._name + "\", locale is '" + this._language + "'.",
optConsoleParam1, optConsoleParam2, optConsoleParam3);
} catch(e) {
transls = JSON.parse(translations[cwcLocale['en']]);
this._terms.windDirections = transls.cwcLocWindDirections ;
this._terms.words = transls.cwcTerms ;
console.info(logo + "%c card \"" + this._name + "\" unable to use '" + this._language + "' locale, set as default 'en'.",
optConsoleParam1, optConsoleParam2, optConsoleParam3);
}
numberFormat_0dec = new Intl.NumberFormat(this._language, { maximumFractionDigits: 0 }) ;
numberFormat_1dec = new Intl.NumberFormat(this._language, { maximumFractionDigits: 1 }) ;
if (undefined !== config.display) {
this._displayTop = config.display.findIndex(item => 'top' === item.toLowerCase()) >= 0;
this._displayCurrent = config.display.findIndex(item => 'current' === item.toLowerCase()) >= 0;
this._displayForecast = config.display.findIndex(item => 'forecast' === item.toLowerCase()) >= 0;
}
this._hasCurrent = (!!config.weather) && (!!config.weather.current);
this._hasForecast = (!!config.weather) && (!!config.weather.forecast);
this._hasMeteogram = this._hasForecast && (!!config.weather.forecast.meteogram);
this._hasAirQuality = !!config.air_quality;
this._hasPollen = !!config.pollen && (!!config.pollen.tree || !!config.pollen.weed || !!config.pollen.grass);
this._hasUv = !!config.uv;
this._hasAlert = !!config.alert;
this._hasSea = !!config.sea;
this._iconsConfig.path = hacsImages ? hacsImagePath : manImages ? manImagePath : null;
// this._iconsConfig.iconType = config.animation ? "animated" : "static";
this._iconsConfig.iconType = config.animation ? "animated" : "static";
this._iconsConfig.iconsDay = cwcClimacellDayIcons;
this._iconsConfig.iconsNight = cwcClimacellNightIcons;
this._iconsConfig.icons_model = "climacell";
if ((!!config.weather) && (!!config.weather.icons_model))
switch (config.weather.icons_model.toLowerCase()) {
case 'darksky':
this._iconsConfig.iconsDay = cwcDarkskyDayIcons;
this._iconsConfig.iconsNight = cwcDarkskyNightIcons;
this._iconsConfig.icons_model = "darksky";
break;
case 'openweathermap':
this._iconsConfig.iconsDay = cwcOpenWeatherMapDayIcons;
this._iconsConfig.iconsNight = cwcOpenWeatherMapNightIcons;
this._iconsConfig.icons_model = "openweathermap";
break;
case 'buienradar':
this._iconsConfig.iconsDay = cwcBuienradarDayIcons;
this._iconsConfig.iconsNight = cwcBuienradarNightIcons;
this._iconsConfig.icons_model = "buienradar";
break;
case 'defaulthass':
this._iconsConfig.iconsDay = cwcDefaultHassDayIcons;
this._iconsConfig.iconsNight = cwcDefaultHassNightIcons;
this._iconsConfig.icons_model = "defaulthass";
break;
}
this._config = config;
}
/**
* get the current size of the card
* @return {Number}
*/
getCardSize() {
return 1;
}
/**
*
* @returns {CSSResult}
*/
static get styles(): CSSResult {
return css`${style}${styleSummary}${styleForecast}${styleMeter}${styleCamera}${styleNightAndDay}${unsafeCSS(getSeaStyle(globalImagePath))}`;
}
/**
* generates the card HTML
* @return {TemplateResult}
*/
render() {
if (this.invalidConfig) return html`
<ha-card class="ha-card-weather-conditions">
<div class='banner'>
<div class="header">ha-card-weather-conditions</div>
</div>
<div class='content'>
Configuration ERROR!
</div>
</ha-card>
`;
else {
return this._render();
}
}
/**
*
* @returns {TemplateResult}
* @private
*/
_render() {
let sunrise, sunriseEnd, sunsetStart, sunset, now ;
let dynStyle, condition, habgImage ;
let _renderedSummary, _renderedPresent, _renderedUv, _renderedAirQuality, _renderedPollen, _renderedForecast,
_renderedAlert, _renderedSea ;
// let _renderSummury: boolean = false ;
let posix:number = 0 ;
let states = this.hass.states ;
if( this._showSummary && this._hasCurrent ) {
let current = this._config.weather.current ;
if((current.current_conditions && typeof states[ current.current_conditions ] !== undefined)
|| (current.temperature && typeof states[ current.temperature ] !== undefined)) {
_renderedSummary = renderSummary(this.hass,
this._config.weather.current, this._config.name, this._iconsConfig, this._terms) ;
posix++ ;
} else _renderedSummary = "" ;
} else _renderedSummary = "" ;
// Test if render >Present<
if( this._showPresent && this._hasCurrent) {
let current = this._config.weather.current ;
if((current.sun && typeof states[ current.sun ] !== undefined)
|| (current.humidity && typeof states[ current.humidity ] !== undefined)
|| (current.pressure && typeof states[ current.pressure ] !== undefined)
|| (current.visibility && typeof states[ current.visibility ] !== undefined)
|| (current.wind_bearing && typeof states[ current.wind_bearing ] !== undefined)
|| (current.wind_speed && typeof states[ current.wind_speed ] !== undefined)) {
_renderedPresent = renderPresent(this.hass,
this._config.weather.current, this._config.weather.forecast, this._language, this._terms, posix > 0) ;
posix++ ;
} else {
if(current.forecast && this._hasForecast) {
let forecast = this._config.weather.forecast ;
if((forecast.temperature_low && forecast.temperature_low.day_1 && typeof states[ forecast.temperature_low.day_1 ] !== undefined)
|| (forecast.temperature_high && forecast.temperature_high.day_1 && typeof states[ forecast.temperature_high.day_1 ] !== undefined)
|| (forecast.precipitation_intensity && forecast.precipitation_intensity.day_1 && typeof states[ forecast.precipitation_intensity.day_1 ] !== undefined)
|| (forecast.precipitation_probability && forecast.precipitation_probability.day_1 && typeof states[ forecast.precipitation_probability.day_1 ] !== undefined)) {
_renderedPresent = renderPresent(this.hass,
this._config.weather.current, this._config.weather.forecast, this._language, this._terms, posix > 0) ;
posix++ ;
} else _renderedPresent = "" ;
} else _renderedPresent = "" ;
}
} else _renderedPresent = "" ;
// Test AirQuality
if(this._showAirQuality && this._hasAirQuality ) {
let airQuality = this._config.air_quality ;
if((airQuality.co && typeof states[ airQuality.co ] !== undefined)
|| (airQuality.epa_aqi && typeof states[ airQuality.epa_aqi ] !== undefined)
|| (airQuality.epa_health_concern && typeof states[ airQuality.epa_health_concern ] !== undefined)
|| (airQuality.no2 && typeof states[ airQuality.no2 ] !== undefined)
|| (airQuality.o3 && typeof states[ airQuality.o3 ] !== undefined)
|| (airQuality.pm10 && typeof states[ airQuality.pm10 ] !== undefined)
|| (airQuality.pm25 && typeof states[ airQuality.pm25 ] !== undefined)
|| (airQuality.so2 && typeof states[ airQuality.so2 ] !== undefined)) {
_renderedAirQuality = renderAirQualities(this.hass, this._config.air_quality, posix > 0) ;
posix++ ;
} else _renderedAirQuality = "" ;
} else _renderedAirQuality = "" ;
// Test uv
if(this._showUv && this._hasUv ) {
let uv = this._config.uv ;
if((uv.protection_window && typeof states[ uv.protection_window ] !== undefined)
|| (uv.ozone_level && typeof states[ uv.ozone_level ] !== undefined)
|| (uv.uv_index && typeof states[ uv.uv_index ] !== undefined)
|| (uv.uv_level && typeof states[ uv.uv_level ] !== undefined)
|| (uv.max_uv_index && typeof states[ uv.max_uv_index ] !== undefined)) {
_renderedUv = renderUv(this.hass, this._config.uv, posix > 0) ;
posix++ ;
} else _renderedUv = "" ;
} else _renderedUv = "" ;
if(this._showPollen && this._hasPollen ) {
let pollen = this._config.pollen ;
if((pollen.grass && pollen.grass.entity && typeof states[ pollen.grass.entity ] !== undefined)
|| (pollen.tree && pollen.tree.entity && typeof states[ pollen.tree.entity ] !== undefined)
|| (pollen.weed && pollen.weed.entity && typeof states[ pollen.weed.entity ] !== undefined)) {
_renderedPollen = renderPollens(this.hass, this._config.pollen, posix > 0) ;
posix++ ;
} else _renderedPollen = "" ;
} else _renderedPollen = "" ;
if( this._showForecast && this._hasForecast ) {
let forecast = this._config.weather.forecast ;
_renderedForecast = renderForecasts(this.hass,
this._config.weather.current, forecast, this._iconsConfig, this._language, posix > 0) ;
posix++ ;
} else _renderedForecast = "" ;
// Test Alert
if( this._showAlert && this._hasAlert ) {
let alert = this._config.alert ;
_renderedAlert = renderAlert(this.hass, alert, posix > 0) ;
posix++ ;
} else _renderedAlert = "" ;
// Test Sea
if( this._showSea && this._hasSea ) {
let sea = this._config.sea ;
_renderedSea = renderSeaForecast(this.hass, sea, this._iconsConfig, this._language, posix > 0) ;
posix++ ;
} else _renderedSea = "" ;
return html`
${dynStyle ? html`
<style>${dynStyle}</style>` : "" }
<ha-card class="ha-card-weather-conditions ">
<div class="nd-container ${habgImage ? habgImage : ''}">
${this._header ? html`
${_renderedSummary}
${_renderedAlert}
${_renderedPresent}
${_renderedUv}
${_renderedAirQuality}
${_renderedPollen}
${_renderedForecast}
${_renderedSea}
${this._hasMeteogram ? this.renderCamera(this.hass, this._config.weather.forecast.meteogram) : ""}
${this._config.camera ? this.renderCamera(this.hass, this._config.camera) : ""}
` : html``}
</div>
</ha-card>
`;
}
/**
*
* @param hass
* @param camId
*/
renderCamera(hass: HomeAssistant, camId: string) {
let camera = hass.states[camId];
let entity_picture: string = camera ? camera.attributes.entity_picture : undefined ;
return entity_picture ? html`
<div @click=${e => this.handlePopup(e, camId)} class="camera-container">
<div class="camera-image">
<img src="${entity_picture}" alt="${camera.attributes.friendly_name}"/>
</div>
</div>
` : html``;
}
/**
*
* @param e
* @param entityId
*/
handlePopup(e, entityId: string) {
e.stopPropagation();
let ne = new Event('hass-more-info', {composed: true});
// @ts-ignore
ne.detail = {entityId};
this.dispatchEvent(ne);
}
}
}) ;
}) ;
Example #17
Source File: editor.ts From harmony-card with MIT License | 4 votes |
protected render(): TemplateResult | void {
if (!this.hass) {
return html``;
}
// You can restrict on domain type
const entities = Object.keys(this.hass.states).filter(eid => eid.substr(0, eid.indexOf('.')) === 'remote');
const volume_entities = Object.keys(this.hass.states).filter(eid => eid.substr(0, eid.indexOf('.')) === 'media_player');
return html`
<div class="card-config">
<div class="option" @click=${this._toggleOption} .option=${'required'}>
<div class="row">
<ha-icon .icon=${`mdi:${options.required.icon}`}></ha-icon>
<div class="title">${options.required.name}</div>
</div>
<div class="secondary">${options.required.secondary}</div>
</div>
${options.required.show
? html`
<div class="values">
<paper-dropdown-menu
label="Harmony Entity (Required)"
@value-changed=${this._valueChanged}
.configValue=${'entity'}
>
<paper-listbox slot="dropdown-content" .selected=${entities.indexOf(this._entity)}>
${entities.map(entity => {
return html`
<paper-item>${entity}</paper-item>
`;
})}
</paper-listbox>
</paper-dropdown-menu>
</div>
<div class="values">
<paper-dropdown-menu
label="Volume Entity"
@value-changed=${this._valueChanged}
.configValue=${'volume_entity'}
>
<paper-listbox slot="dropdown-content" .selected=${volume_entities.indexOf(this._volume_entity)}>
${volume_entities.map(entity => {
return html`
<paper-item>${entity}</paper-item>
`;
})}
</paper-listbox>
</paper-dropdown-menu>
</div>
`
: ''}
<div class="option" @click=${this._toggleOption} .option=${'actions'}>
<div class="row">
<ha-icon .icon=${`mdi:${options.actions.icon}`}></ha-icon>
<div class="title">${options.actions.name}</div>
</div>
<div class="secondary">${options.actions.secondary}</div>
</div>
${options.actions.show
? html`
<div class="values">
<div class="option" @click=${this._toggleAction} .option=${'tap'}>
<div class="row">
<ha-icon .icon=${`mdi:${options.actions.options.tap.icon}`}></ha-icon>
<div class="title">${options.actions.options.tap.name}</div>
</div>
<div class="secondary">${options.actions.options.tap.secondary}</div>
</div>
${options.actions.options.tap.show
? html`
<div class="values">
<paper-item>Action Editors Coming Soon</paper-item>
</div>
`
: ''}
<div class="option" @click=${this._toggleAction} .option=${'hold'}>
<div class="row">
<ha-icon .icon=${`mdi:${options.actions.options.hold.icon}`}></ha-icon>
<div class="title">${options.actions.options.hold.name}</div>
</div>
<div class="secondary">${options.actions.options.hold.secondary}</div>
</div>
${options.actions.options.hold.show
? html`
<div class="values">
<paper-item>Action Editors Coming Soon</paper-item>
</div>
`
: ''}
<div class="option" @click=${this._toggleAction} .option=${'double_tap'}>
<div class="row">
<ha-icon .icon=${`mdi:${options.actions.options.double_tap.icon}`}></ha-icon>
<div class="title">${options.actions.options.double_tap.name}</div>
</div>
<div class="secondary">${options.actions.options.double_tap.secondary}</div>
</div>
${options.actions.options.double_tap.show
? html`
<div class="values">
<paper-item>Action Editors Coming Soon</paper-item>
</div>
`
: ''}
</div>
`
: ''}
<div class="option" @click=${this._toggleOption} .option=${'appearance'}>
<div class="row">
<ha-icon .icon=${`mdi:${options.appearance.icon}`}></ha-icon>
<div class="title">${options.appearance.name}</div>
</div>
<div class="secondary">${options.appearance.secondary}</div>
</div>
${options.appearance.show
? html`
<div class="values">
<paper-input
label="Name (Optional)"
.value=${this._name}
.configValue=${'name'}
@value-changed=${this._valueChanged}
></paper-input>
<br />
<ha-switch
aria-label=${`Toggle warning ${this._show_warning ? 'off' : 'on'}`}
.checked=${this._show_warning !== false}
.configValue=${'show_warning'}
@change=${this._valueChanged}
>Show Warning?</ha-switch
>
<ha-switch
aria-label=${`Toggle error ${this._show_error ? 'off' : 'on'}`}
.checked=${this._show_error !== false}
.configValue=${'show_error'}
@change=${this._valueChanged}
>Show Error?</ha-switch
>
</div>
`
: ''}
</div>
`;
}
Example #18
Source File: editor.ts From select-list-card with MIT License | 4 votes |
protected render(): TemplateResult | void {
if (!this.hass) {
return html``;
}
// You can restrict on domain type
const entities = Object.keys(this.hass.states).filter(eid => eid.substr(0, eid.indexOf('.')) === 'input_select');
return html`
<div class="card-config">
<div class="values">
<div class="row">
<paper-dropdown-menu
label="${localize('editor.entity')}"
@value-changed=${this._valueChanged}
.configValue=${'entity'}
>
<paper-listbox slot="dropdown-content" .selected=${entities.indexOf(this._entity)}>
${entities.map(entity => {
return html`
<paper-item>${entity}</paper-item>
`;
})}
</paper-listbox>
</paper-dropdown-menu>
</div>
<div class="row">
<div class="side-by-side">
<paper-input
label="${localize('editor.title')}"
.value=${this._title}
.configValue=${'title'}
@value-changed=${this._valueChanged}
></paper-input>
<paper-input
.configValue=${'icon'}
.value=${this._icon}
.label="${localize('editor.icon')}"
.placeholder=${this._icon || stateIcon(this.hass.states[this._entity])}
@value-changed=${this._valueChanged}
pattern="^\\\\S+:\\\\S+$"
>
${this._icon || stateIcon(this.hass.states[this._entity])
? html`
<ha-icon .icon=${this._icon || stateIcon(this.hass.states[this._entity])} slot="suffix">
</ha-icon>
`
: ''}
</paper-input>
</div>
</div>
<div class="row">
<paper-input
label="${localize('editor.max_options')}"
.value=${this._max_options}
.configValue=${'max_options'}
type="number"
@value-changed=${this._valueChanged}
></paper-input>
</div>
<div class="row">
<ha-switch
aria-label=${`Toggle truncate ${this._truncate ? 'off' : 'on'}`}
.checked=${this._truncate}
.configValue=${'truncate'}
@change=${this._valueChanged}
>
</ha-switch>
<span class="switch-label">${localize('editor.truncate')}</span>
</div>
<div class="row">
<ha-switch
aria-label=${`Toggle scroll to selected ${this._scroll_to_selected ? 'off' : 'on'}`}
.checked=${this._scroll_to_selected}
.configValue=${'scroll_to_selected'}
@change=${this._valueChanged}
>
</ha-switch>
<span class="switch-label">${localize('editor.scroll_to_selected')}</span>
</div>
<div class="row">
<ha-switch
aria-label=${`Toggle show toggle ${this._show_toggle ? 'off' : 'on'}`}
.checked=${this._show_toggle}
.configValue=${'show_toggle'}
@change=${this._valueChanged}
>
</ha-switch>
<span class="switch-label">${localize('editor.show_toggle')}</span>
</div>
</div>
</div>
`;
}
Example #19
Source File: editor.ts From linak-desk-card with MIT License | 4 votes |
protected render(): TemplateResult | void {
if (!this.hass || !this._helpers) {
return html``;
}
const covers = Object.keys(this.hass.states).filter(eid => eid.substr(0, eid.indexOf('.')) === 'cover');
const binarySensors = Object.keys(this.hass.states).filter(eid => eid.substr(0, eid.indexOf('.')) === 'binary_sensor');
const sensors = Object.keys(this.hass.states).filter(eid => eid.substr(0, eid.indexOf('.')) === 'sensor');
return html`
<div class="card-config">
<div class="option">
<paper-input
label=${localize('editor.name')}
.value=${this._config.name}
.configValue=${'name'}
@value-changed=${this._valueChanged}
></paper-input>
</div>
<div class="option">
<paper-dropdown-menu
label=${localize('editor.desk')}
@value-changed=${this._valueChanged}
.configValue=${'desk'}
>
<paper-listbox slot="dropdown-content" .selected=${covers.indexOf(this._config.desk)}>
${covers.map(entity => {
return html`
<paper-item>${entity}</paper-item>
`;
})}
</paper-listbox>
</paper-dropdown-menu>
</div>
<div class="option">
<paper-dropdown-menu
label=${localize('editor.height_sensor')}
@value-changed=${this._valueChanged}
.configValue=${'height_sensor'}
>
<paper-listbox slot="dropdown-content" .selected=${sensors.indexOf(this._config.height_sensor)}>
${sensors.map(entity => {
return html`
<paper-item>${entity}</paper-item>
`;
})}
</paper-listbox>
</paper-dropdown-menu>
</div>
<div class="option">
<paper-dropdown-menu
label=${localize('editor.connection_sensor')}
@value-changed=${this._valueChanged}
.configValue=${'connection_sensor'}
>
<paper-listbox slot="dropdown-content" .selected=${binarySensors.indexOf(this._config.connection_sensor)}>
${binarySensors.map(entity => {
return html`
<paper-item>${entity}</paper-item>
`;
})}
</paper-listbox>
</paper-dropdown-menu>
</div>
<div class="option">
<paper-dropdown-menu
label=${localize('editor.moving_sensor')}
@value-changed=${this._valueChanged}
.configValue=${'moving_sensor'}
>
<paper-listbox slot="dropdown-content" .selected=${binarySensors.indexOf(this._config.moving_sensor)}>
${binarySensors.map(entity => {
return html`
<paper-item>${entity}</paper-item>
`;
})}
</paper-listbox>
</paper-dropdown-menu>
</div>
<div class="option">
<paper-input
label=${localize('editor.min_height')}
.value=${this._config.min_height}
auto-validate
allowed-pattern="[0-9]"
.configType=${'integer'}
.configValue=${'min_height'}
@value-changed=${this._valueChanged}
></paper-input>
<paper-input
label=${localize('editor.max_height')}
.value=${this._config.max_height}
auto-validate
allowed-pattern="[0-9]"
.configType=${'integer'}
.configValue=${'max_height'}
@value-changed=${this._valueChanged}
></paper-input>
</div>
<h4>${localize('editor.presets')}</h4>
<div class="option">
${(this._config.presets || []).map((p, i) => html`
<div class="preset">
<paper-input
.value=${p.label}
.presetValue=${'label'}
.presetIndex=${i}
@value-changed=${this._presetChanged}
></paper-input>
<paper-input
.value=${p.target}
.presetValue=${'target'}
.presetIndex=${i}
allowed-pattern="[0-9]"
.configType=${'integer'}
@value-changed=${this._presetChanged}
></paper-input>
<ha-icon icon="mdi:close" .presetIndex=${i} @click=${this.removePreset}></ha-icon>
</div>
`)}
<ha-icon icon="mdi:plus" @click=${this.addPreset} ></ha-icon>
</div>
</div>
`;
}