From 7041d322d67c41a92a783b18f0b9c8e5b0d84a2d Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Thu, 23 Feb 2023 10:38:44 +0100 Subject: [PATCH] Allow energy dashboard to be cast (#15397) --- cast/src/receiver/layout/hc-main.ts | 16 ++++++++++++++++ src/panels/energy/ha-panel-energy.ts | 6 +++--- src/panels/energy/strategies/energy-strategy.ts | 2 +- .../cards/energy/hui-energy-distribution-card.ts | 5 +++++ .../config-elements/hui-entities-card-editor.ts | 2 +- src/panels/lovelace/entity-rows/types.ts | 2 +- src/panels/lovelace/special-rows/hui-cast-row.ts | 9 +++------ 7 files changed, 30 insertions(+), 12 deletions(-) diff --git a/cast/src/receiver/layout/hc-main.ts b/cast/src/receiver/layout/hc-main.ts index 298487bd0f..de31b9bce1 100644 --- a/cast/src/receiver/layout/hc-main.ts +++ b/cast/src/receiver/layout/hc-main.ts @@ -252,6 +252,22 @@ export class HcMain extends HassElement { msg.urlPath = null; } this._lovelacePath = msg.viewPath; + if (msg.urlPath === "energy") { + this._lovelaceConfig = { + views: [ + { + strategy: { + type: "energy", + options: { show_date_selection: true }, + }, + }, + ], + }; + this._urlPath = "energy"; + this._lovelacePath = 0; + this._sendStatus(); + return; + } if (!this._unsubLovelace || this._urlPath !== msg.urlPath) { this._urlPath = msg.urlPath; this._lovelaceConfig = undefined; diff --git a/src/panels/energy/ha-panel-energy.ts b/src/panels/energy/ha-panel-energy.ts index a9090dc14d..a81a6afef2 100644 --- a/src/panels/energy/ha-panel-energy.ts +++ b/src/panels/energy/ha-panel-energy.ts @@ -18,7 +18,7 @@ import "../lovelace/components/hui-energy-period-selector"; import { Lovelace } from "../lovelace/types"; import "../lovelace/views/hui-view"; -const LOVELACE_CONFIG: LovelaceConfig = { +const ENERGY_LOVELACE_CONFIG: LovelaceConfig = { views: [ { strategy: { @@ -93,8 +93,8 @@ class PanelEnergy extends LitElement { private _setLovelace() { this._lovelace = { - config: LOVELACE_CONFIG, - rawConfig: LOVELACE_CONFIG, + config: ENERGY_LOVELACE_CONFIG, + rawConfig: ENERGY_LOVELACE_CONFIG, editMode: false, urlPath: "energy", mode: "generated", diff --git a/src/panels/energy/strategies/energy-strategy.ts b/src/panels/energy/strategies/energy-strategy.ts index 6c6122c2af..de5d6aca44 100644 --- a/src/panels/energy/strategies/energy-strategy.ts +++ b/src/panels/energy/strategies/energy-strategy.ts @@ -56,7 +56,7 @@ export class EnergyStrategy { (source) => source.type === "water" ); - if (info.narrow) { + if (info.narrow || info.view.strategy?.options?.show_date_selection) { view.cards!.push({ type: "energy-date-selection", collection_key: "energy_dashboard", diff --git a/src/panels/lovelace/cards/energy/hui-energy-distribution-card.ts b/src/panels/lovelace/cards/energy/hui-energy-distribution-card.ts index 9535c4a6c2..b57b718d59 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-distribution-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-distribution-card.ts @@ -884,6 +884,11 @@ class HuiEnergyDistrubutionCard color: var(--secondary-text-color); font-size: 12px; opacity: 1; + height: 20px; + overflow: hidden; + text-overflow: ellipsis; + max-width: 80px; + white-space: nowrap; } line, path { diff --git a/src/panels/lovelace/editor/config-elements/hui-entities-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-entities-card-editor.ts index 1b0e680850..3b847fa672 100644 --- a/src/panels/lovelace/editor/config-elements/hui-entities-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-entities-card-editor.ts @@ -62,7 +62,7 @@ const buttonEntitiesRowConfigStruct = object({ const castEntitiesRowConfigStruct = object({ type: literal("cast"), - view: union([string(), number()]), + view: optional(union([string(), number()])), dashboard: optional(string()), name: optional(string()), icon: optional(string()), diff --git a/src/panels/lovelace/entity-rows/types.ts b/src/panels/lovelace/entity-rows/types.ts index 47131f09e6..f377c9631b 100644 --- a/src/panels/lovelace/entity-rows/types.ts +++ b/src/panels/lovelace/entity-rows/types.ts @@ -55,7 +55,7 @@ export interface CastConfig { type: "cast"; icon?: string; name?: string; - view: string | number; + view?: string | number; dashboard?: string; // Hide the row if either unsupported browser or no API available. hide_if_unavailable?: boolean; diff --git a/src/panels/lovelace/special-rows/hui-cast-row.ts b/src/panels/lovelace/special-rows/hui-cast-row.ts index c29edd95e8..19d563ad3c 100644 --- a/src/panels/lovelace/special-rows/hui-cast-row.ts +++ b/src/panels/lovelace/special-rows/hui-cast-row.ts @@ -29,13 +29,10 @@ class HuiCastRow extends LitElement implements LovelaceRow { @state() private _noHTTPS = false; public setConfig(config: CastConfig): void { - if (!config || config.view === undefined || config.view === null) { - throw new Error("View required"); - } - this._config = { - icon: "hass:television", + icon: "mdi:television", name: "Home Assistant Cast", + view: 0, ...config, }; } @@ -123,7 +120,7 @@ class HuiCastRow extends LitElement implements LovelaceRow { castSendShowLovelaceView( this._castManager!, this.hass.auth.data.hassUrl, - this._config!.view, + this._config!.view!, this._config!.dashboard ); }