Skip to content

Commit ba63fde

Browse files
committed
fix: addressed the issue in minimal config generation with missing keys in source
1 parent c0f645b commit ba63fde

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

esphome_plus/two_stage.py

+28-11
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,15 @@ def full_config(self):
137137
def minimal_config(self):
138138
# CORE.config_path = self.minimal_config_path
139139

140-
config = OrderedDict()
141-
config["esphome"] = self.full_config["esphome"]
142-
config["esphome"]["name"] += "-minimal"
143-
144140
platform = self.platform(self.full_config)
145141

146-
config["esphome"]["build_path"] = "build/minimal/" + platform
147-
config[platform] = self.full_config[platform]
148-
149-
config["logger"] = self.full_config["logger"]
150-
config["wifi"] = self.full_config["wifi"]
151-
config["ota"] = self.full_config["ota"]
152-
config["captive_portal"] = self.full_config["captive_portal"]
142+
config = pluck_config(
143+
self.full_config,
144+
["esphome", platform, "logger", "wifi", "ota", "captive_portal"],
145+
)
153146

147+
config["esphome"]["build_path"] = "build/minimal/" + platform
148+
config["esphome"]["name"] += "-minimal"
154149
return config
155150

156151
def generate_minimal_config(self):
@@ -166,3 +161,25 @@ def platform(self, config):
166161
return "bk72xx"
167162
else:
168163
raise ValueError("Unknown platform")
164+
165+
166+
def pluck_config(
167+
source: OrderedDict, keys: list, skip_missing: bool = True
168+
) -> OrderedDict:
169+
"""Extract specified keys from source OrderedDict.
170+
171+
Args:
172+
source: Source OrderedDict to pluck from
173+
keys: List of keys to extract
174+
skip_missing: If True, skip keys that don't exist. If False, raise KeyError
175+
176+
Returns:
177+
OrderedDict containing only the specified keys
178+
"""
179+
result = OrderedDict()
180+
for key in keys:
181+
if key in source:
182+
result[key] = source[key]
183+
elif not skip_missing:
184+
raise KeyError(f"Required key '{key}' not found in config")
185+
return result

0 commit comments

Comments
 (0)