diff --git a/src/panels/lovelace/editor/config-elements/hui-sensor-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-sensor-card-editor.ts index d42fba0fb6..1fb42284fe 100644 --- a/src/panels/lovelace/editor/config-elements/hui-sensor-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-sensor-card-editor.ts @@ -5,22 +5,24 @@ import "@polymer/paper-listbox/paper-listbox"; import { customElement, html, + internalProperty, LitElement, property, - internalProperty, TemplateResult, } from "lit-element"; +import { assert, number, object, optional, string } from "superstruct"; import { fireEvent } from "../../../../common/dom/fire_event"; import { stateIcon } from "../../../../common/entity/state_icon"; import "../../../../components/entity/ha-entity-picker"; +import "../../../../components/ha-formfield"; import "../../../../components/ha-icon-input"; +import "../../../../components/ha-switch"; import { HomeAssistant } from "../../../../types"; import { SensorCardConfig } from "../../cards/types"; import "../../components/hui-theme-select-editor"; import { LovelaceCardEditor } from "../../types"; import { EditorTarget, EntitiesEditorEvent } from "../types"; import { configElementStyle } from "./config-elements-style"; -import { string, assert, object, optional, number } from "superstruct"; const cardConfigStruct = object({ type: string(), @@ -68,8 +70,8 @@ export class HuiSensorCardEditor extends LitElement return this._config!.unit || ""; } - get _detail(): number | string { - return this._config!.number || "1"; + get _detail(): number { + return this._config!.detail ?? 1; } get _theme(): string { @@ -97,10 +99,10 @@ export class HuiSensorCardEditor extends LitElement "ui.panel.lovelace.editor.card.config.required" )})" .hass=${this.hass} - .value="${this._entity}" + .value=${this._entity} .configValue=${"entity"} .includeDomains=${includeDomains} - @change="${this._valueChanged}" + @change=${this._valueChanged} allow-custom-entity >
${graphs.map((graph) => { - return html` ${graph} `; + return html`${graph}`; })} @@ -152,28 +154,28 @@ export class HuiSensorCardEditor extends LitElement )} (${this.hass.localize( "ui.panel.lovelace.editor.card.config.optional" )})" - .value="${this._unit}" - .configValue="${"unit"}" - @value-changed="${this._valueChanged}" - > - + + +
`; } + private _change(ev: Event) { + if (!this._config || !this.hass) { + return; + } + + const value = (ev.target! as EditorTarget).checked ? 2 : 1; + + if (this._detail === value) { + return; + } + + this._config = { + ...this._config, + detail: value, + }; + + fireEvent(this, "config-changed", { config: this._config }); + } + private _valueChanged(ev: EntitiesEditorEvent): void { if (!this._config || !this.hass) { return; diff --git a/src/translations/en.json b/src/translations/en.json index 5504fd17df..843cfefea7 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2386,7 +2386,7 @@ }, "sensor": { "name": "Sensor", - "graph_detail": "Graph Detail", + "show_more_detail": "Show more detail", "graph_type": "Graph Type", "description": "The Sensor card gives you a quick overview of your sensors state with an optional graph to visualize change over time." },