From d98bd28f466d043fa35cedc88ed6657533822223 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Mon, 20 May 2024 09:52:26 +1200 Subject: [PATCH 1/3] Revert "v3 Climate Component" (#100) --- packages/v3/src/css/esp-entity-table.ts | 10 -- packages/v3/src/esp-entity-table.ts | 184 +++++++++--------------- 2 files changed, 64 insertions(+), 130 deletions(-) diff --git a/packages/v3/src/css/esp-entity-table.ts b/packages/v3/src/css/esp-entity-table.ts index 0fc3fbb..82a93a6 100644 --- a/packages/v3/src/css/esp-entity-table.ts +++ b/packages/v3/src/css/esp-entity-table.ts @@ -76,14 +76,4 @@ export default css` input[type="color"]::-webkit-color-swatch-wrapper { padding: 0 !important; } - - .climate { - width: 100%; - display: grid; - text-align: center; - grid-template-columns: repeat(3, 1fr); - gap: 6px; - padding: 10px; - align-items: center; - } `; diff --git a/packages/v3/src/esp-entity-table.ts b/packages/v3/src/esp-entity-table.ts index fd94157..3b31e5b 100644 --- a/packages/v3/src/esp-entity-table.ts +++ b/packages/v3/src/esp-entity-table.ts @@ -39,8 +39,6 @@ interface entityConfig { current_temperature?: number; modes?: number[]; mode?: number; - presets?: number[]; - preset?: number; speed_count?: number; speed_level?: number; speed: string; @@ -94,12 +92,8 @@ export class EntityTable extends LitElement implements RestAction { unique_id: data.id, id: parts.slice(1).join("-"), entity_category: data.entity_category, + value_numeric_history: [data.value], } as entityConfig; - if (typeof data.value === "number") { - entity.value_numeric_history = [data.value]; - } else if (data.current_temperature) { - entity.value_numeric_history = [Number(data.current_temperature)]; - } entity.has_action = this.hasAction(entity); if (entity.has_action) { this.has_controls = true; @@ -118,13 +112,11 @@ export class EntityTable extends LitElement implements RestAction { }); this.requestUpdate(); } else { - let history = [...this.entities[idx].value_numeric_history]; if (typeof data.value === "number") { + let history = [...this.entities[idx].value_numeric_history]; history.push(data.value); - } else if (data.current_temperature) { - history.push(Number(data.current_temperature)); + this.entities[idx].value_numeric_history = history.splice(-50); } - this.entities[idx].value_numeric_history = history.splice(-50); delete data.id; delete data.domain; @@ -225,8 +217,7 @@ export class EntityTable extends LitElement implements RestAction { ? this.control(component) : html`
${component.state}
`} - ${component.domain === "sensor" || - component.domain === "climate" + ${component.domain === "sensor" ? html`` @@ -247,10 +238,7 @@ export class EntityTable extends LitElement implements RestAction { } _handleEntityRowClick(e: any) { - if ( - e?.currentTarget?.domain === "sensor" || - e?.currentTarget?.domain === "climate" - ) { + if (e?.currentTarget?.domain === "sensor") { if (!e?.ctrlKey) e.stopPropagation(); e?.currentTarget?.classList.toggle( "expanded", @@ -297,71 +285,25 @@ class ActionRenderer { `; } - private _tempSelector(entity: entityConfig, target: string) { - if (!entity) return; - let targetTemp = - target === "high" - ? entity.target_temperature_high - : entity.target_temperature || entity.target_temperature_low; - let upValue = - target === "high" - ? Number(entity.target_temperature_high) + Number(entity.step) - : Number(entity.target_temperature || entity.target_temperature_low) + - Number(entity.step); - let downValue = - target === "high" - ? Number(entity.target_temperature_high) - Number(entity.step) - : Number(entity.target_temperature || entity.target_temperature_low) - - Number(entity.step); - upValue = - upValue > Number(entity.max_temp) ? Number(entity.max_temp) : upValue; - downValue = - downValue > Number(entity.max_temp) ? Number(entity.max_temp) : downValue; - - let upAction = target - ? `set?target_temperature_${target}=${upValue}` - : `set?target_temperature=${upValue}`; - let downAction = target - ? `set?target_temperature_${target}=${downValue}` - : `set?target_temperature=${downValue}`; - - return html`
-
- `; - } - private _datetime( entity: entityConfig, type: string, action: string, opt: string, - value: string + value: string, ) { return html` - `; @@ -386,11 +328,7 @@ class ActionRenderer { val: string | number | undefined ) { return html` - `; + `; } else { - return html` e.target)?.value; + this.actioner?.restAction(entity, `${action}?${opt}=${e.detail.state}`); + }}" >`; } + } private _textinput( @@ -675,50 +612,57 @@ class ActionRenderer { target_temp_label = html`${this.entity .target_temperature_low} .. ${this.entity .target_temperature_high}`; + target_temp_slider = html` + ${this._range( + this.entity, + "set", + "target_temperature_low", + this.entity.target_temperature_low, + this.entity.min_temp, + this.entity.max_temp, + this.entity.step + )} + ${this._range( + this.entity, + "set", + "target_temperature_high", + this.entity.target_temperature_high, + this.entity.min_temp, + this.entity.max_temp, + this.entity.step + )} + `; } else { target_temp_label = html`${this.entity.target_temperature}`; + target_temp_slider = html` + ${this._range( + this.entity, + "set", + "target_temperature", + this.entity.target_temperature!!, + this.entity.min_temp, + this.entity.max_temp, + this.entity.step + )} + `; } let modes = html``; if ((this.entity.modes ? this.entity.modes.length : 0) > 0) { - modes = html` ${this._select( - this.entity, - "set", - "mode", - this.entity.modes || [], - this.entity.mode || "" - )}`; - } - let presets = html``; - if ((this.entity.presets ? this.entity.presets.length : 0) > 0) { - presets = html` ${this._select( - this.entity, - "set", - "preset", - this.entity.presets || [], - this.entity.preset || "" - )}`; + modes = html`Mode:
+ ${this._select( + this.entity, + "set", + "mode", + this.entity.modes || [], + this.entity.mode || "" + )}`; } - return html` -
-
- ${this._tempSelector( - this.entity, - this.entity.target_temperature_low ? "low" : "" - )} -
-
- -
-
- ${this.entity.target_temperature_high - ? this._tempSelector(this.entity, "high") - : ""} -
-
${modes}
-
${this.entity.state}
-
${presets}
-
+ + ${target_temp_slider} ${modes} `; } } From 93f92cb94265b7e648559aa8d858f0b0b896bf9f Mon Sep 17 00:00:00 2001 From: RFDarter Date: Fri, 7 Jun 2024 22:30:07 +0200 Subject: [PATCH 2/3] v3 support datetime-datetime (#103) --- packages/v3/src/esp-entity-table.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/v3/src/esp-entity-table.ts b/packages/v3/src/esp-entity-table.ts index 3b31e5b..4bc224b 100644 --- a/packages/v3/src/esp-entity-table.ts +++ b/packages/v3/src/esp-entity-table.ts @@ -302,7 +302,7 @@ class ActionRenderer { const val = (e.target)?.value; this.actioner?.restAction( entity, - `${action}?${opt}=${val}` + `${action}?${opt}=${val.replace('T', ' ')}` ); }}" /> @@ -481,6 +481,19 @@ class ActionRenderer { `; } + render_datetime() { + if (!this.entity) return; + return html` + ${this._datetime( + this.entity, + "datetime-local", + "set", + "value", + this.entity.value, + )} + `; + } + render_switch() { if (!this.entity) return; if (this.entity.assumed_state) From f264a22ec1d4065b7bd02ad834ea5483a5d90165 Mon Sep 17 00:00:00 2001 From: RFDarter Date: Fri, 7 Jun 2024 22:30:24 +0200 Subject: [PATCH 3/3] v2 support datetime-datetime (#104) --- packages/v2/src/esp-entity-table.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/v2/src/esp-entity-table.ts b/packages/v2/src/esp-entity-table.ts index 6191030..9cc1a30 100644 --- a/packages/v2/src/esp-entity-table.ts +++ b/packages/v2/src/esp-entity-table.ts @@ -302,7 +302,7 @@ class ActionRenderer { const val = (e.target)?.value; this.actioner?.restAction( entity, - `${action}?${opt}=${val}` + `${action}?${opt}=${val.replace('T', ' ')}` ); }}" /> @@ -460,6 +460,19 @@ class ActionRenderer { `; } + render_datetime() { + if (!this.entity) return; + return html` + ${this._datetime( + this.entity, + "datetime-local", + "set", + "value", + this.entity.value, + )} + `; + } + render_text() { if (!this.entity) return; return this._textinput(