Allow energy dashboard to be cast (#15397)

This commit is contained in:
Bram Kragten 2023-02-23 10:38:44 +01:00 committed by GitHub
parent f786539f15
commit 7041d322d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 12 deletions

View File

@ -252,6 +252,22 @@ export class HcMain extends HassElement {
msg.urlPath = null; msg.urlPath = null;
} }
this._lovelacePath = msg.viewPath; 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) { if (!this._unsubLovelace || this._urlPath !== msg.urlPath) {
this._urlPath = msg.urlPath; this._urlPath = msg.urlPath;
this._lovelaceConfig = undefined; this._lovelaceConfig = undefined;

View File

@ -18,7 +18,7 @@ import "../lovelace/components/hui-energy-period-selector";
import { Lovelace } from "../lovelace/types"; import { Lovelace } from "../lovelace/types";
import "../lovelace/views/hui-view"; import "../lovelace/views/hui-view";
const LOVELACE_CONFIG: LovelaceConfig = { const ENERGY_LOVELACE_CONFIG: LovelaceConfig = {
views: [ views: [
{ {
strategy: { strategy: {
@ -93,8 +93,8 @@ class PanelEnergy extends LitElement {
private _setLovelace() { private _setLovelace() {
this._lovelace = { this._lovelace = {
config: LOVELACE_CONFIG, config: ENERGY_LOVELACE_CONFIG,
rawConfig: LOVELACE_CONFIG, rawConfig: ENERGY_LOVELACE_CONFIG,
editMode: false, editMode: false,
urlPath: "energy", urlPath: "energy",
mode: "generated", mode: "generated",

View File

@ -56,7 +56,7 @@ export class EnergyStrategy {
(source) => source.type === "water" (source) => source.type === "water"
); );
if (info.narrow) { if (info.narrow || info.view.strategy?.options?.show_date_selection) {
view.cards!.push({ view.cards!.push({
type: "energy-date-selection", type: "energy-date-selection",
collection_key: "energy_dashboard", collection_key: "energy_dashboard",

View File

@ -884,6 +884,11 @@ class HuiEnergyDistrubutionCard
color: var(--secondary-text-color); color: var(--secondary-text-color);
font-size: 12px; font-size: 12px;
opacity: 1; opacity: 1;
height: 20px;
overflow: hidden;
text-overflow: ellipsis;
max-width: 80px;
white-space: nowrap;
} }
line, line,
path { path {

View File

@ -62,7 +62,7 @@ const buttonEntitiesRowConfigStruct = object({
const castEntitiesRowConfigStruct = object({ const castEntitiesRowConfigStruct = object({
type: literal("cast"), type: literal("cast"),
view: union([string(), number()]), view: optional(union([string(), number()])),
dashboard: optional(string()), dashboard: optional(string()),
name: optional(string()), name: optional(string()),
icon: optional(string()), icon: optional(string()),

View File

@ -55,7 +55,7 @@ export interface CastConfig {
type: "cast"; type: "cast";
icon?: string; icon?: string;
name?: string; name?: string;
view: string | number; view?: string | number;
dashboard?: string; dashboard?: string;
// Hide the row if either unsupported browser or no API available. // Hide the row if either unsupported browser or no API available.
hide_if_unavailable?: boolean; hide_if_unavailable?: boolean;

View File

@ -29,13 +29,10 @@ class HuiCastRow extends LitElement implements LovelaceRow {
@state() private _noHTTPS = false; @state() private _noHTTPS = false;
public setConfig(config: CastConfig): void { public setConfig(config: CastConfig): void {
if (!config || config.view === undefined || config.view === null) {
throw new Error("View required");
}
this._config = { this._config = {
icon: "hass:television", icon: "mdi:television",
name: "Home Assistant Cast", name: "Home Assistant Cast",
view: 0,
...config, ...config,
}; };
} }
@ -123,7 +120,7 @@ class HuiCastRow extends LitElement implements LovelaceRow {
castSendShowLovelaceView( castSendShowLovelaceView(
this._castManager!, this._castManager!,
this.hass.auth.data.hassUrl, this.hass.auth.data.hassUrl,
this._config!.view, this._config!.view!,
this._config!.dashboard this._config!.dashboard
); );
} }