From d0e995e7e3e3243b0addbe1ecd3db8563f54b1d1 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Wed, 28 Feb 2024 10:27:26 +0100 Subject: [PATCH] Add grid support to climate card --- src/cards/climate-card/climate-card.ts | 81 ++++++++++++++++++-------- src/shared/card.ts | 3 +- src/utils/card-styles.ts | 6 ++ 3 files changed, 64 insertions(+), 26 deletions(-) diff --git a/src/cards/climate-card/climate-card.ts b/src/cards/climate-card/climate-card.ts index 72b2f4c7f..a5cb1d9eb 100644 --- a/src/cards/climate-card/climate-card.ts +++ b/src/cards/climate-card/climate-card.ts @@ -70,7 +70,31 @@ export class ClimateCard extends MushroomBaseCard implements LovelaceCard { @state() private _activeControl?: ClimateCardControl; - @state() private _controls: ClimateCardControl[] = []; + @state() private _inGrid = false; + + private get _stateObj(): ClimateEntity | undefined { + if (!this._config || !this.hass || !this._config.entity) return undefined; + + const entityId = this._config.entity; + return this.hass.states[entityId] as ClimateEntity | undefined; + } + + private get _controls(): ClimateCardControl[] { + if (!this._config || !this._stateObj) return []; + + const stateObj = this._stateObj; + const controls: ClimateCardControl[] = []; + + if (!this._config.collapsible_controls || isActive(stateObj)) { + if (isTemperatureControlVisible(stateObj) && this._config.show_temperature_control) { + controls.push("temperature_control"); + } + if (isHvacModesVisible(stateObj, this._config.hvac_modes)) { + controls.push("hvac_mode_control"); + } + } + return controls; + } _onControlTap(ctrl, e): void { e.stopPropagation(); @@ -91,39 +115,21 @@ export class ClimateCard extends MushroomBaseCard implements LovelaceCard { }, ...config, }; - this.updateControls(); + this.updateActiveControl(); } protected updated(changedProperties: PropertyValues) { super.updated(changedProperties); if (this.hass && changedProperties.has("hass")) { - this.updateControls(); + this.updateActiveControl(); } } - updateControls() { - if (!this._config || !this.hass || !this._config.entity) return; - - const entityId = this._config.entity; - const stateObj = this.hass.states[entityId] as ClimateEntity | undefined; - - if (!stateObj) return; - - const controls: ClimateCardControl[] = []; - if (!this._config.collapsible_controls || isActive(stateObj)) { - if (isTemperatureControlVisible(stateObj) && this._config.show_temperature_control) { - controls.push("temperature_control"); - } - if (isHvacModesVisible(stateObj, this._config.hvac_modes)) { - controls.push("hvac_mode_control"); - } - } - - this._controls = controls; + updateActiveControl() { const isActiveControlSupported = this._activeControl - ? controls.includes(this._activeControl) + ? this._controls.includes(this._activeControl) : false; - this._activeControl = isActiveControlSupported ? this._activeControl : controls[0]; + this._activeControl = isActiveControlSupported ? this._activeControl : this._controls[0]; } private _handleAction(ev: ActionHandlerEvent) { @@ -167,7 +173,12 @@ export class ClimateCard extends MushroomBaseCard implements LovelaceCard { const rtl = computeRTL(this.hass); return html` - + ::slotted(*:not(:last-child)) { margin-bottom: var(--spacing); diff --git a/src/utils/card-styles.ts b/src/utils/card-styles.ts index 1365a2312..6bd471b5a 100644 --- a/src/utils/card-styles.ts +++ b/src/utils/card-styles.ts @@ -12,6 +12,12 @@ export const cardStyle = css` ha-card.fill-container { height: 100%; } + ha-card.in-grid { + height: 100%; + } + ha-card.in-grid mushroom-card { + height: 100%; + } .actions { display: flex; flex-direction: row;