@@ -184,23 +184,38 @@ def _recover_last_command_states(self) -> None:
184
184
def _add_favourites (self ) -> None :
185
185
"""Patch program categories with favourites"""
186
186
for favourite in self ._favourites :
187
- name = favourite .get ("favouriteName" , {})
188
- command = favourite .get ("command" , {})
189
- command_name = command .get ("commandName" , "" )
190
- program_name = self ._clean_name (command .get ("programName" , "" ))
191
- if not (base := self .commands [command_name ].categories .get (program_name )):
187
+ name , command_name , base = self ._get_favourite_info (favourite )
188
+ if base :
192
189
continue
193
190
base_command : HonCommand = copy (base )
194
- for data in command .values ():
195
- if isinstance (data , str ):
191
+ self ._update_base_command_with_data (base_command , favourite )
192
+ self ._update_base_command_with_favourite (base_command )
193
+ self ._update_program_categories (command_name , name , base_command )
194
+
195
+ def _get_favourite_info (self , favourite : Dict [str , Any ]):
196
+ name = favourite .get ("favouriteName" , {})
197
+ command = favourite .get ("command" , {})
198
+ command_name = command .get ("commandName" , "" )
199
+ program_name = self ._clean_name (command .get ("programName" , "" ))
200
+ base_command = self .commands [command_name ].categories .get (program_name )
201
+ return name , command_name , base_command
202
+
203
+ def _update_base_command_with_data (self , base_command , command ):
204
+ for data in command .values ():
205
+ if isinstance (data , str ):
206
+ continue
207
+ for key , value in data .items ():
208
+ if not (parameter := base_command .parameters .get (key )):
196
209
continue
197
- for key , value in data .items ():
198
- if parameter := base_command .parameters .get (key ):
199
- with suppress (ValueError ):
200
- parameter .value = value
201
- extra_param = HonParameterFixed ("favourite" , {"fixedValue" : "1" }, "custom" )
202
- base_command .parameters .update (favourite = extra_param )
203
- program = base_command .parameters ["program" ]
204
- if isinstance (program , HonParameterProgram ):
205
- program .set_value (name )
206
- self .commands [command_name ].categories [name ] = base_command
210
+ with suppress (ValueError ):
211
+ parameter .value = value
212
+
213
+ def _update_base_command_with_favourite (self , base_command ):
214
+ extra_param = HonParameterFixed ("favourite" , {"fixedValue" : "1" }, "custom" )
215
+ base_command .parameters .update (favourite = extra_param )
216
+
217
+ def _update_program_categories (self , command_name , name , base_command ):
218
+ program = base_command .parameters ["program" ]
219
+ if isinstance (program , HonParameterProgram ):
220
+ program .set_value (name )
221
+ self .commands [command_name ].categories [name ] = base_command
0 commit comments