Skip to content

Commit

Permalink
fix ha_theme default
Browse files Browse the repository at this point in the history
  • Loading branch information
dbuezas committed Jan 28, 2023
1 parent 60bbdb9 commit 1d4b115
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
32 changes: 18 additions & 14 deletions src/parse-config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const defaultYamlRequired = {
entity: {},
yaxes: {},
},
layout: {},
};

//
Expand Down Expand Up @@ -137,27 +138,30 @@ const defaultYamlOptional: {
};

export function addPreParsingDefaults(
yaml: InputConfig,
yaml_in: InputConfig,
css_vars: HATheme
): Config {
const out = merge(
): InputConfig {
let yaml = merge({}, yaml_in, defaultYamlRequired, yaml_in);
// merging in two steps to ensure ha_theme and raw_plotly_config took its default value
yaml = merge(
{},
yaml,
{ layout: yaml.ha_theme ? getThemedLayout(css_vars) : {} },
defaultYamlRequired,
{
layout: yaml.ha_theme ? getThemedLayout(css_vars) : {},
},
yaml.raw_plotly_config ? {} : defaultYamlOptional,
yaml
yaml_in
);
for (let i = 1; i < 31; i++) {
const yaxis = "yaxis" + (i == 1 ? "" : i);
out.layout[yaxis] = merge(
yaml.layout[yaxis] = merge(
{},
out.layout[yaxis],
out.defaults?.yaxes,
out.layout[yaxis]
yaml.layout[yaxis],
yaml.defaults.yaxes,
yaml.layout[yaxis]
);
}
out.entities = out.entities.map((entity) => {
yaml.entities = yaml.entities.map((entity) => {
if (typeof entity === "string") entity = { entity };
entity.entity ??= "";
const [oldAPI_entity, oldAPI_attribute] = entity.entity.split("::");
Expand All @@ -169,13 +173,13 @@ export function addPreParsingDefaults(
{},
entity,
defaultEntityRequired,
out.raw_plotly_config ? {} : defaultEntityOptional,
out.defaults?.entity,
yaml.raw_plotly_config ? {} : defaultEntityOptional,
yaml.defaults?.entity,
entity
);
return entity;
});
return out;
return yaml;
}

export function addPostParsingDefaults(
Expand Down
2 changes: 1 addition & 1 deletion src/parse-config/parse-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import getDeprecationError from "./deprecations";
class ConfigParser {
private yaml: Partial<Config> = {};
private errors?: Error[];
private yaml_with_defaults?: Config;
private yaml_with_defaults?: InputConfig;
private hass?: HomeAssistant;
cache = new Cache();
private busy = false;
Expand Down

0 comments on commit 1d4b115

Please sign in to comment.