const fireEvent = (node, type, detail, options) => { options = options || {}; detail = detail === null || detail === undefined ? {} : detail; const event = new Event(type, { bubbles: options.bubbles === undefined ? true : options.bubbles, cancelable: Boolean(options.cancelable), composed: options.composed === undefined ? true : options.composed, }); event.detail = detail; node.dispatchEvent(event); return event; }; if ( !customElements.get("ha-switch") && customElements.get("paper-toggle-button") ) { customElements.define("ha-switch", customElements.get("paper-toggle-button")); } const LitElement = Object.getPrototypeOf(customElements.get("hui-view")); const html = LitElement.prototype.html; const css = LitElement.prototype.css; export class WeatherCardEditor extends LitElement { setConfig(config) { this._config = config; } static get properties() { return { hass: {}, _config: {} }; } get _entity() { return this._config.entity || ""; } get _name() { return this._config.name || ""; } get _icons() { return this._config.icons || ""; } get _current() { return this._config.current !== false; } get _details() { return this._config.details !== false; } get _forecast() { return this._config.forecast !== false; } get _graph() { return this._config.graph !== false; } get _forecast_max_Column() { return this._config.forecast_max_Column || 9; } get _hide_precipitation() { return this._config.hide_precipitation === true; } render() { if (!this.hass) { return html``; } const entities = Object.keys(this.hass.states).filter( (eid) => eid.substr(0, eid.indexOf(".")) === "weather" ); return html`
${customElements.get("ha-entity-picker") ? html` ` : html` ${entities.map((entity) => { return html` ${entity} `; })} `} Show current Show details Hide precipitation Show forecast Show graph
`; } _valueChanged(ev) { if (!this._config || !this.hass) { return; } const target = ev.target; if (this[`_${target.configValue}`] === target.value) { return; } if (target.configValue) { if (target.value === "") { delete this._config[target.configValue]; } else { this._config = { ...this._config, [target.configValue]: target.checked !== undefined ? target.checked : target.value, }; } } fireEvent(this, "config-changed", { config: this._config }); } static get styles() { return css` ha-switch { padding-top: 16px; } .side-by-side { display: flex; } .side-by-side > * { flex: 1; padding-right: 4px; } `; } } customElements.define("weather-card-editor", WeatherCardEditor);