// I Used weather-card-editor.js from Weather Card as template // https://github.com/bramkragten/weather-card // 2023-02-25 card editor is likely broken as it doesn't show entities, 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 = customElements.get("hui-masonry-view") ? Object.getPrototypeOf(customElements.get("hui-masonry-view")) : Object.getPrototypeOf(customElements.get("hui-view")); const html = LitElement.prototype.html; const css = LitElement.prototype.css; const HELPERS = window.loadCardHelpers(); export class AirVisualCardEditor extends LitElement { setConfig(config) { this._config = { ...config }; } static get properties() { return { hass: {}, _config: {} }; } get _air_pollution_level() { return this._config.air_pollution_level || "sensor.u_s_air_pollution_level"; } get _air_quality_index() { return this._config.air_quality_index || "sensor.u_s_air_quality_index"; } get _main_pollutant() { return this._config.main_pollutant || "sensor.u_s_main_pollutant"; } get _country() { return this._config.country || ""; } get _city() { return this._config.city || ""; } get _icons() { return this._config.icons || "/hacsfiles/air-visual-card"; } get _weather() { return this._config.weather || "weather.home"; } get _speed_unit() { return this._config.speed_unit || "mp/h"; } get _unit_of_measurement() { return this._config.unit_of_measurement || "AQI"; } get _hide_title() { return this._config.hide_title !== false; } get _hide_face() { return this._config.hide_face !== true; } get _hide_weather() { return this._config.hide_weather !== false; } // WHAT DOES THIS DO? firstUpdated() { HELPERS.then(help => { if (help.importMoreInfoControl) { help.importMoreInfoControl("fan"); } }) } render() { if (!this.hass) { return html``; } // WHAT DOES THIS DO? const entities = Object.keys(this.hass.states).filter( (eid) => eid.substr(0, eid.indexOf(".")) === "sensor" ); return html`
${customElements.get("ha-entity-picker") ? html` ` : html``}
Hide Title
Hide Weather
Hide Face
`; } _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` .switches { margin: 8px 0; display: flex; justify-content: space-between; } .switch { display: flex; align-items: center; justify-items: center; } .switches span { padding: 0 16px; } `; } } customElements.define("air-visual-card-editor", AirVisualCardEditor);