indigo.Dict() question

Posted on
Sun Oct 15, 2017 2:55 pm
racarter offline
User avatar
Posts: 477
Joined: Jun 18, 2016
Location: North Yorkshire, UK

indigo.Dict() question

I'm writing a plugin in which I want to save a dictionary of values in the prefs file. On startup I want to retrieve the dictionary, but what if it doesn't yet exist?

For prefs you'd normally write:

Code: Select all
self.pluginPrefs.get("somePrefKey", "default value if key doesn't exist")


but what is the default value if an indigo.Dict() doesn't exist and you need to create an empty one? I've tried '{}' but that doesn't appear to work.

Posted on
Sun Oct 15, 2017 3:43 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: indigo.Dict() question

It should return the default value (either [] or indigo.Dict()) correctly. I think the problem you are seeing is that your new dict isn't getting copied into the pluginPrefs once you are done creating / editing it. There are some differences between how indigo.Dicts work compared to python dicts. I think if you post more of your code and an explanation of how it is failing we can help you get it working.

Image

Posted on
Sun Oct 15, 2017 3:55 pm
racarter offline
User avatar
Posts: 477
Joined: Jun 18, 2016
Location: North Yorkshire, UK

Re: indigo.Dict() question

Thanks Matt, but during development to get going I created a dictionary manually. The dictionary saves and loads perfectly well, but I sent the plugin to a beta tester and he was having problems because the dictionary didn't exist in prefs yet and the default of an empty dictionary wasn't getting created.

Update: I've actually got around the problem by:

Code: Select all
if self.deviceList == None:
         self.deviceList = indigo.Dict()

Posted on
Sun Oct 15, 2017 3:58 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: indigo.Dict() question

I tried this:

foo = self.pluginPrefs.get("somePrefKey", indigo.Dict())

and it worked correctly in that foo was an indigo.Dict instance. That doesn't insert it into the pluginPrefs though, since the get method just extracts out the item if it exists and returns the default if it doesn't.

Image

Posted on
Sun Oct 15, 2017 4:07 pm
racarter offline
User avatar
Posts: 477
Joined: Jun 18, 2016
Location: North Yorkshire, UK

Re: indigo.Dict() question

Strange. I tried that and got an error.

Thanks though Matt :)

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests

cron