@@ -137,20 +137,15 @@ def full_config(self):
137
137
def minimal_config (self ):
138
138
# CORE.config_path = self.minimal_config_path
139
139
140
- config = OrderedDict ()
141
- config ["esphome" ] = self .full_config ["esphome" ]
142
- config ["esphome" ]["name" ] += "-minimal"
143
-
144
140
platform = self .platform (self .full_config )
145
141
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
+ )
153
146
147
+ config ["esphome" ]["build_path" ] = "build/minimal/" + platform
148
+ config ["esphome" ]["name" ] += "-minimal"
154
149
return config
155
150
156
151
def generate_minimal_config (self ):
@@ -166,3 +161,25 @@ def platform(self, config):
166
161
return "bk72xx"
167
162
else :
168
163
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