Skip to content

Commit 1d4b115

Browse files
committed
fix ha_theme default
1 parent 60bbdb9 commit 1d4b115

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/parse-config/defaults.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const defaultYamlRequired = {
5858
entity: {},
5959
yaxes: {},
6060
},
61+
layout: {},
6162
};
6263

6364
//
@@ -137,27 +138,30 @@ const defaultYamlOptional: {
137138
};
138139

139140
export function addPreParsingDefaults(
140-
yaml: InputConfig,
141+
yaml_in: InputConfig,
141142
css_vars: HATheme
142-
): Config {
143-
const out = merge(
143+
): InputConfig {
144+
let yaml = merge({}, yaml_in, defaultYamlRequired, yaml_in);
145+
// merging in two steps to ensure ha_theme and raw_plotly_config took its default value
146+
yaml = merge(
144147
{},
145148
yaml,
146-
{ layout: yaml.ha_theme ? getThemedLayout(css_vars) : {} },
147-
defaultYamlRequired,
149+
{
150+
layout: yaml.ha_theme ? getThemedLayout(css_vars) : {},
151+
},
148152
yaml.raw_plotly_config ? {} : defaultYamlOptional,
149-
yaml
153+
yaml_in
150154
);
151155
for (let i = 1; i < 31; i++) {
152156
const yaxis = "yaxis" + (i == 1 ? "" : i);
153-
out.layout[yaxis] = merge(
157+
yaml.layout[yaxis] = merge(
154158
{},
155-
out.layout[yaxis],
156-
out.defaults?.yaxes,
157-
out.layout[yaxis]
159+
yaml.layout[yaxis],
160+
yaml.defaults.yaxes,
161+
yaml.layout[yaxis]
158162
);
159163
}
160-
out.entities = out.entities.map((entity) => {
164+
yaml.entities = yaml.entities.map((entity) => {
161165
if (typeof entity === "string") entity = { entity };
162166
entity.entity ??= "";
163167
const [oldAPI_entity, oldAPI_attribute] = entity.entity.split("::");
@@ -169,13 +173,13 @@ export function addPreParsingDefaults(
169173
{},
170174
entity,
171175
defaultEntityRequired,
172-
out.raw_plotly_config ? {} : defaultEntityOptional,
173-
out.defaults?.entity,
176+
yaml.raw_plotly_config ? {} : defaultEntityOptional,
177+
yaml.defaults?.entity,
174178
entity
175179
);
176180
return entity;
177181
});
178-
return out;
182+
return yaml;
179183
}
180184

181185
export function addPostParsingDefaults(

src/parse-config/parse-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import getDeprecationError from "./deprecations";
1818
class ConfigParser {
1919
private yaml: Partial<Config> = {};
2020
private errors?: Error[];
21-
private yaml_with_defaults?: Config;
21+
private yaml_with_defaults?: InputConfig;
2222
private hass?: HomeAssistant;
2323
cache = new Cache();
2424
private busy = false;

0 commit comments

Comments
 (0)