Skip to content

Commit

Permalink
Improve typings
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Sep 20, 2023
1 parent 7dca4d2 commit ddb8971
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 27 deletions.
15 changes: 7 additions & 8 deletions src/data/lovelace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export interface LovelacePanelConfig {
mode: "yaml" | "storage";
}

export type LovelaceStrategyConfig<T = Record<string, any>> = {
type: string;
options?: T;
};

export interface LovelaceConfig {
title?: string;
strategy?: {
type: string;
options?: Record<string, unknown>;
};
strategy?: LovelaceStrategyConfig;
views: LovelaceViewConfig[];
background?: string;
}
Expand Down Expand Up @@ -81,10 +83,7 @@ export interface LovelaceViewConfig {
index?: number;
title?: string;
type?: string;
strategy?: {
type: string;
options?: Record<string, unknown>;
};
strategy?: LovelaceStrategyConfig;
badges?: Array<string | LovelaceBadgeConfig>;
cards?: LovelaceCardConfig[];
path?: string;
Expand Down
8 changes: 4 additions & 4 deletions src/panels/energy/strategies/energy-view-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
getEnergyPreferences,
GridSourceTypeEnergyPreference,
} from "../../../data/energy";
import { LovelaceViewConfig } from "../../../data/lovelace";
import { HomeAssistant } from "../../../types";
import {
LovelaceStrategyConfig,
LovelaceStrategyParams,
} from "../../lovelace/strategies/types";
LovelaceViewConfig,
} from "../../../data/lovelace";
import { HomeAssistant } from "../../../types";
import { LovelaceStrategyParams } from "../../lovelace/strategies/types";

const setupWizard = async (): Promise<LovelaceViewConfig> => {
await import("../cards/energy-setup-wizard-card");
Expand Down
10 changes: 7 additions & 3 deletions src/panels/lovelace/strategies/get-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { LovelaceConfig, LovelaceViewConfig } from "../../../data/lovelace";
import {
LovelaceConfig,
LovelaceStrategyConfig,
LovelaceViewConfig,
} from "../../../data/lovelace";
import { AsyncReturnType, HomeAssistant } from "../../../types";
import { isLegacyStrategy } from "./legacy-strategy";
import {
LovelaceDashboardStrategy,
LovelaceStrategy,
LovelaceStrategyConfig,
LovelaceStrategyConfigType,
LovelaceStrategyParams,
LovelaceViewStrategy,
} from "./types";
Expand All @@ -23,6 +25,8 @@ const STRATEGIES: Record<LovelaceStrategyConfigType, Record<string, any>> = {
},
};

export type LovelaceStrategyConfigType = "dashboard" | "view";

type Strategies = {
dashboard: LovelaceDashboardStrategy;
view: LovelaceViewStrategy;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ReactiveElement } from "lit";
import { customElement } from "lit/decorators";
import { LovelaceConfig } from "../../../data/lovelace";
import { LovelaceConfig, LovelaceStrategyConfig } from "../../../data/lovelace";
import { HomeAssistant } from "../../../types";
import { LovelaceStrategyConfig, LovelaceStrategyParams } from "./types";
import { LovelaceStrategyParams } from "./types";

@customElement("original-states-dashboard-strategy")
export class OriginalStatesDashboardStrategy extends ReactiveElement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { ReactiveElement } from "lit";
import { customElement } from "lit/decorators";
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
import { getEnergyPreferences } from "../../../data/energy";
import { LovelaceViewConfig } from "../../../data/lovelace";
import {
LovelaceStrategyConfig,
LovelaceViewConfig,
} from "../../../data/lovelace";
import { HomeAssistant } from "../../../types";
import { generateDefaultViewConfig } from "../common/generate-lovelace-config";
import { LovelaceStrategyConfig, LovelaceStrategyParams } from "./types";
import { LovelaceStrategyParams } from "./types";

@customElement("original-states-view-strategy")
export class OriginalStatesViewStrategy extends ReactiveElement {
Expand Down
13 changes: 5 additions & 8 deletions src/panels/lovelace/strategies/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { LovelaceConfig, LovelaceViewConfig } from "../../../data/lovelace";
import {
LovelaceConfig,
LovelaceStrategyConfig,
LovelaceViewConfig,
} from "../../../data/lovelace";
import { HomeAssistant } from "../../../types";

export type LovelaceStrategyConfigType = "dashboard" | "view";

export type LovelaceStrategyConfig<T = Record<string, any>> = {
type: string;
options?: T;
};

export type LovelaceStrategyParams = {
narrow?: boolean;
};
Expand Down

0 comments on commit ddb8971

Please sign in to comment.