Skip to content

Commit

Permalink
Always add raw config
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Nov 14, 2023
1 parent d2d34b9 commit f36e054
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
11 changes: 7 additions & 4 deletions cast/src/receiver/layout/hc-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ import {
isStrategyDashboard,
LegacyLovelaceConfig,
LovelaceDashboardConfig,
LovelaceDashboardStrategyConfig,
} from "../../../../src/data/lovelace/config/dashboard";
import { fetchResources } from "../../../../src/data/lovelace/resource";
import { loadLovelaceResources } from "../../../../src/panels/lovelace/common/load-resources";
import { HassElement } from "../../../../src/state/hass-element";
import { castContext } from "../cast_context";
import "./hc-launch-screen";

const DEFAULT_STRATEGY = "original-states";
const DEFAULT_CONFIG: LovelaceDashboardStrategyConfig = {
strategy: {
type: "original-states",
},
};

let resourcesLoaded = false;
@customElement("hc-main")
Expand Down Expand Up @@ -336,9 +341,7 @@ export class HcMain extends HassElement {
);
this._handleNewLovelaceConfig(
await generateLovelaceDashboardStrategy(
{
type: DEFAULT_STRATEGY,
},
DEFAULT_CONFIG.strategy,
this.hass!
)
);
Expand Down
26 changes: 13 additions & 13 deletions src/panels/lovelace/ha-panel-lovelace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
isStrategyDashboard,
LovelaceDashboardConfig,
LovelaceDashboardRawConfig,
LovelaceDashboardStrategyConfig,
saveConfig,
} from "../../data/lovelace/config/dashboard";
import { fetchResources } from "../../data/lovelace/resource";
Expand All @@ -35,7 +36,11 @@ import {

(window as any).loadCardHelpers = () => import("./custom-card-helpers");

const DEFAULT_STRATEGY = "original-states";
const DEFAULT_CONFIG: LovelaceDashboardStrategyConfig = {
strategy: {
type: "original-states",
},
};

interface LovelacePanelConfig {
mode: "yaml" | "storage";
Expand Down Expand Up @@ -170,12 +175,10 @@ export class LovelacePanel extends LitElement {

private async _regenerateConfig() {
const conf = await generateLovelaceDashboardStrategy(
{
type: DEFAULT_STRATEGY,
},
DEFAULT_CONFIG.strategy,
this.hass!
);
this._setLovelaceConfig(conf, undefined, "generated");
this._setLovelaceConfig(conf, DEFAULT_CONFIG, "generated");
this._panelState = "loaded";
}

Expand Down Expand Up @@ -276,11 +279,10 @@ export class LovelacePanel extends LitElement {
return;
}
conf = await generateLovelaceDashboardStrategy(
{
type: DEFAULT_STRATEGY,
},
DEFAULT_CONFIG.strategy,
this.hass!
);
rawConf = DEFAULT_CONFIG;
confMode = "generated";
} finally {
// Ignore updates for another 2 seconds.
Expand Down Expand Up @@ -321,7 +323,7 @@ export class LovelacePanel extends LitElement {

private _setLovelaceConfig(
config: LovelaceDashboardConfig,
rawConfig: LovelaceDashboardRawConfig | undefined,
rawConfig: LovelaceDashboardRawConfig,
mode: Lovelace["mode"]
) {
config = this._checkLovelaceConfig(config);
Expand Down Expand Up @@ -411,14 +413,12 @@ export class LovelacePanel extends LitElement {
try {
// Optimistic update
const generatedConf = await generateLovelaceDashboardStrategy(
{
type: DEFAULT_STRATEGY,
},
DEFAULT_CONFIG.strategy,
this.hass!
);
this._updateLovelace({
config: generatedConf,
rawConfig: undefined,
rawConfig: DEFAULT_CONFIG,
mode: "generated",
editMode: false,
});
Expand Down
3 changes: 1 addition & 2 deletions src/panels/lovelace/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ declare global {

export interface Lovelace {
config: LovelaceDashboardConfig;
// If not set, a strategy was used to generate everything
rawConfig: LovelaceDashboardRawConfig | undefined;
rawConfig: LovelaceDashboardRawConfig;
editMode: boolean;
urlPath: string | null;
mode: "generated" | "yaml" | "storage";
Expand Down

0 comments on commit f36e054

Please sign in to comment.