Skip to content

Commit

Permalink
Merge pull request #33 from flixlix/feat-add-energy-date-selection-to…
Browse files Browse the repository at this point in the history
…-ui-editor

feat: `energy_date_selection` in ui editor
  • Loading branch information
flixlix committed May 29, 2023
2 parents 02347a2 + 7cbcd87 commit 7bdc921
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
5 changes: 5 additions & 0 deletions src/ui-editor/schema/_schema-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ export const advancedOptionsSchema = [
label: 'Clickable Entities',
selector: { boolean: {} },
},
{
name: 'energy_date_selection',
label: 'Energy Date Selection',
selector: { boolean: {} },
},
{
name: 'use_new_flow_rate_model',
label: 'New Flow Model?',
Expand Down
29 changes: 15 additions & 14 deletions src/ui-editor/ui-editor.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable no-use-before-define */

import { LitElement, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { fireEvent, HomeAssistant, LovelaceCardEditor } from "custom-card-helpers";
import { assert } from "superstruct";
import { EnergyFlowCardPlusConfig } from "../energy-flow-card-plus-config";
import { cardConfigStruct, generalConfigSchema, entitiesSchema, advancedOptionsSchema } from "./schema/_schema-all";
import { LitElement, css, html, nothing } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { fireEvent, HomeAssistant, LovelaceCardEditor } from 'custom-card-helpers';
import { assert } from 'superstruct';
import { EnergyFlowCardPlusConfig } from '../energy-flow-card-plus-config';
import { cardConfigStruct, generalConfigSchema, entitiesSchema, advancedOptionsSchema } from './schema/_schema-all';

export const loadHaForm = async () => {
if (customElements.get("ha-form")) return;
if (customElements.get('ha-form')) return;

const helpers = await (window as any).loadCardHelpers?.();
if (!helpers) return;
const card = await helpers.createCardElement({ type: "entity" });
const card = await helpers.createCardElement({ type: 'entity' });
if (!card) return;
await card.getConfigElement();
};

@customElement("energy-flow-card-plus-editor")
@customElement('energy-flow-card-plus-editor')
export class EnergyFlowCardPlusEditor extends LitElement implements LovelaceCardEditor {
@property({ attribute: false }) public hass!: HomeAssistant;
@state() private _config?: EnergyFlowCardPlusConfig;
Expand All @@ -39,6 +39,7 @@ export class EnergyFlowCardPlusEditor extends LitElement implements LovelaceCard
}
const data = {
...this._config,
energy_date_selection: this._config.energy_date_selection ?? true,
};

return html`
Expand Down Expand Up @@ -71,15 +72,15 @@ export class EnergyFlowCardPlusEditor extends LitElement implements LovelaceCard
`;
}
private _valueChanged(ev: any): void {
const config = ev.detail.value || "";
const config = ev.detail.value || '';
if (!this._config || !this.hass) {
return;
}
fireEvent(this, "config-changed", { config });
fireEvent(this, 'config-changed', { config });
}

private _computeLabelCallback = (schema) =>
schema?.label || this.hass!.localize(`ui.panel.lovelace.editor.card.generic.${schema?.name}` || schema?.name || "");
private _computeLabelCallback = schema =>
schema?.label || this.hass!.localize(`ui.panel.lovelace.editor.card.generic.${schema?.name}` || schema?.name || '');

static get styles() {
return css`
Expand Down Expand Up @@ -127,6 +128,6 @@ export class EnergyFlowCardPlusEditor extends LitElement implements LovelaceCard

declare global {
interface HTMLElementTagNameMap {
"energy-flow-card-plus-editor": EnergyFlowCardPlusEditor;
'energy-flow-card-plus-editor': EnergyFlowCardPlusEditor;
}
}

0 comments on commit 7bdc921

Please sign in to comment.