Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Nov 15, 2023
1 parent d5874b9 commit e93c837
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { customElement } from "lit/decorators";
import { LovelaceConfig } from "../../../../data/lovelace";
import { LovelaceDashboardStrategyConfig } from "../../../../data/lovelace/config/types";
import { getLovelaceStrategy } from "../../strategies/get-strategy";
import { LovelaceStrategyEditor } from "../../strategies/types";
import { HuiElementEditor } from "../hui-element-editor";

@customElement("hui-dashboard-strategy-element-editor")
export class HuiDashboardStrategyElementEditor extends HuiElementEditor<LovelaceConfig> {
export class HuiDashboardStrategyElementEditor extends HuiElementEditor<LovelaceDashboardStrategyConfig> {
protected async getConfigElement(): Promise<
LovelaceStrategyEditor | undefined
> {
Expand Down
10 changes: 6 additions & 4 deletions src/panels/lovelace/hui-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ import type { Lovelace } from "./types";
import "./views/hui-view";
import type { HUIView } from "./views/hui-view";
import { LovelaceViewConfig } from "../../data/lovelace/config/view";
import { LovelaceConfig } from "../../data/lovelace/config/types";
import {
LovelaceConfig,
isStrategyDashboard,
} from "../../data/lovelace/config/types";

@customElement("hui-root")
class HUIRoot extends LitElement {
Expand Down Expand Up @@ -805,11 +808,10 @@ class HUIRoot extends LitElement {
});
return;
}
if (this.lovelace!.rawConfig?.strategy != null) {
if (isStrategyDashboard(this.lovelace!.rawConfig)) {
showDashboardStrategyEditorDialog(this, {
lovelaceConfig: this.lovelace!.rawConfig,
config: this.lovelace!.rawConfig,
saveConfig: this.lovelace!.saveConfig,
strategyConfig: this.lovelace!.rawConfig.strategy,
});
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { fireEvent, HASSDomEvent } from "../../../../common/dom/fire_event";
import "../../../../components/ha-button";
import { createCloseHeading } from "../../../../components/ha-dialog";
import { LovelaceStrategyConfig } from "../../../../data/lovelace";
import { LovelaceStrategyConfig } from "../../../../data/lovelace/config/strategy";
import { haStyle, haStyleDialog } from "../../../../resources/styles";
import type { HomeAssistant } from "../../../../types";
import { showSaveSuccessToast } from "../../../../util/toast-saved-success";
import "../../editor/dashboard-strategy-editor/hui-dashboard-strategy-element-editor";
import type { HuiDashboardStrategyElementEditor } from "../../editor/dashboard-strategy-editor/hui-dashboard-strategy-element-editor";
import { ConfigChangedEvent } from "../../editor/hui-element-editor";
import { GUIModeChangedEvent } from "../../editor/types";
import type { DashboardStrategyEditorDialogParams } from "./show-dialog-dashboard-strategy-editor";
import { cleanLegacyStrategyConfig } from "../legacy-strategy";
import type { DashboardStrategyEditorDialogParams } from "./show-dialog-dashboard-strategy-editor";

@customElement("dialog-dashboard-strategy-editor")
class DialogDashboardStrategyEditor extends LitElement {
Expand All @@ -32,7 +33,7 @@ class DialogDashboardStrategyEditor extends LitElement {
params: DashboardStrategyEditorDialogParams
): Promise<void> {
this._params = params;
this._strategyConfig = params.strategyConfig;
this._strategyConfig = params.config.strategy;
await this.updateComplete;
}

Expand Down Expand Up @@ -64,8 +65,8 @@ class DialogDashboardStrategyEditor extends LitElement {

private async _save(): Promise<void> {
await this._params!.saveConfig({
...this._params!.lovelaceConfig,
strategy: this._strategyConfig,
...this._params!.config,
strategy: this._strategyConfig!,
});
showSaveSuccessToast(this, this.hass);
this.closeDialog();
Expand All @@ -87,15 +88,15 @@ class DialogDashboardStrategyEditor extends LitElement {
>
<hui-dashboard-strategy-element-editor
.hass=${this.hass}
.lovelace=${this._params.lovelaceConfig}
.lovelace=${this._params.config}
.value=${config}
@config-changed=${this._handleConfigChanged}
@GUImode-changed=${this._handleGUIModeChanged}
dialogInitialFocus
></hui-dashboard-strategy-element-editor>
${this._strategyConfig !== undefined
? html`
<mwc-button
<ha-button
slot="secondaryAction"
@click=${this._toggleMode}
.disabled=${!this._guiModeAvailable}
Expand All @@ -106,10 +107,10 @@ class DialogDashboardStrategyEditor extends LitElement {
? "ui.panel.lovelace.editor.edit_card.show_code_editor"
: "ui.panel.lovelace.editor.edit_card.show_visual_editor"
)}
</mwc-button>
<mwc-button @click=${this._save} slot="primaryAction">
</ha-button>
<ha-button @click=${this._save} slot="primaryAction">
${this.hass!.localize("ui.common.save")}
</mwc-button>
</ha-button>
`
: nothing}
</ha-dialog>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { fireEvent } from "../../../../common/dom/fire_event";
import {
LovelaceConfig,
LovelaceStrategyConfig,
} from "../../../../data/lovelace";
import { LovelaceDashboardStrategyConfig } from "../../../../data/lovelace/config/types";

export interface DashboardStrategyEditorDialogParams {
lovelaceConfig: LovelaceConfig;
saveConfig: (config: LovelaceConfig) => void;
strategyConfig: LovelaceStrategyConfig;
config: LovelaceDashboardStrategyConfig;
saveConfig: (config: LovelaceDashboardStrategyConfig) => void;
}

export const loadDashboardStrategyEditorDialog = () =>
Expand Down

0 comments on commit e93c837

Please sign in to comment.