Skip to content

Commit

Permalink
Put options at the root level
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Sep 20, 2023
1 parent ddb8971 commit 584f083
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cast/src/receiver/layout/hc-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export class HcMain extends HassElement {
{
strategy: {
type: "energy",
options: { show_date_selection: true },
show_date_selection: true,
},
},
],
Expand Down
4 changes: 2 additions & 2 deletions src/data/lovelace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export interface LovelacePanelConfig {
mode: "yaml" | "storage";
}

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

export interface LovelaceConfig {
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 @@ -24,14 +24,14 @@ const setupWizard = async (): Promise<LovelaceViewConfig> => {
};
};

export type EnergeryViewStrategyOptions = {
export interface EnergeryViewStrategyConfig extends LovelaceStrategyConfig {
show_date_selection?: boolean;
};
}

@customElement("energy-view-strategy")
export class EnergyViewStrategy extends ReactiveElement {
static async generate(
config: LovelaceStrategyConfig<EnergeryViewStrategyOptions>,
config: EnergeryViewStrategyConfig,
hass: HomeAssistant,
params: LovelaceStrategyParams
): Promise<LovelaceViewConfig> {
Expand Down Expand Up @@ -67,7 +67,7 @@ export class EnergyViewStrategy extends ReactiveElement {
(source) => source.type === "water"
);

if (params.narrow || config.options?.show_date_selection) {
if (params.narrow || config.show_date_selection) {
view.cards!.push({
type: "energy-date-selection",
collection_key: "energy_dashboard",
Expand Down
9 changes: 8 additions & 1 deletion src/panels/lovelace/strategies/get-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ const generateStrategy = async <T extends LovelaceStrategyConfigType>(
}
}

return await strategy.generate(strategyConfig, hass, params);
const config = {
...strategyConfig,
...strategyConfig.options,
};

delete config.options;

return await strategy.generate(config, hass, params);
} catch (err: any) {
if (err.message !== "timeout") {
// eslint-disable-next-line
Expand Down

0 comments on commit 584f083

Please sign in to comment.