Skip to content

Commit

Permalink
Allow undefined views for strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Nov 14, 2023
1 parent 4bb6504 commit 437eedd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/data/lovelace/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export type LovelaceRawConfig =
| LovelaceDashboardStrategyConfig;

export function isStrategyDashboard(
view: LovelaceRawConfig
): view is LovelaceDashboardStrategyConfig {
return "strategy" in view;
config: LovelaceRawConfig
): config is LovelaceDashboardStrategyConfig {
return "strategy" in config;
}

export const fetchConfig = (
Expand Down
17 changes: 15 additions & 2 deletions src/panels/lovelace/hui-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ import type { HomeAssistant } from "../../types";
import { showToast } from "../../util/toast";
import type { Lovelace } from "./types";
import "../../components/ha-top-app-bar-fixed";
import { LovelaceRawConfig } from "../../data/lovelace/config/types";
import {
LovelaceRawConfig,
isStrategyDashboard,
} from "../../data/lovelace/config/types";

const lovelaceStruct = type({
title: optional(string()),
views: array(object()),
});

const strategyStruct = type({
strategy: type({
type: string(),
}),
});

@customElement("hui-editor")
class LovelaceFullConfigEditor extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
Expand Down Expand Up @@ -262,7 +271,11 @@ class LovelaceFullConfigEditor extends LitElement {
return;
}
try {
assert(config, lovelaceStruct);
if (isStrategyDashboard(config)) {
assert(config, strategyStruct);
} else {
assert(config, lovelaceStruct);
}
} catch (err: any) {
showAlertDialog(this, {
text: this.hass.localize(
Expand Down

0 comments on commit 437eedd

Please sign in to comment.