Skip to content

Commit 67a42c3

Browse files
Fix adding new settings array (#434)
This fixes an issue with plugins that use the new "array" setting type. The array setting type allows you to specify an arbitrary number of items for a setting. For instance, you could define "user" as type "array" and then have a name and email address defined for each user. The issue is that when first creating the setting, I was treating the subsettings like dictionaries, but they are actually a tuple of tuples, with the first representing the path and the second the definition. The new "array" type setting is necessary, but overly complex. I wish I could come up with a simpler implementation. Anyway, this fixes a "TypeError" error when attempting to prompt the user for a value for an "array" setting that has not been initialized before.
1 parent 8ea03b0 commit 67a42c3

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

naomi/commandline.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,17 @@ def get_setting(self, setting, definition):
407407
first = True
408408
newarray = [part for part in setting]
409409
newarray.extend([currentvalue])
410-
for subsetting in definition['each']:
410+
for settingindex in range(len(definition['each'])):
411+
subsetting = definition['each'][settingindex]
411412
newsetting = newarray.copy()
412-
newsetting.extend([subsetting[0]])
413-
self.get_setting(tuple(newsetting), definition['each'][subsetting])
413+
# Subsetting looks something like:
414+
# (('id',), {'title': 'ID of your light', 'description': 'The ID of your light as reported by HomeAssistant'})
415+
# subsetting[0] could be a path with multiple nodes
416+
# subsetting[1] is the definition of this setting
417+
# Add the path nodes to newsetting
418+
for subnode in subsetting[0]:
419+
newsetting.append(subnode)
420+
self.get_setting(tuple(newsetting), subsetting[1])
414421
if first:
415422
first = False
416423
if not profile.get(newsetting):

0 commit comments

Comments
 (0)