[SOLVED]: Accessing self.pluginPrefs __init__() or startup()

Posted on
Wed Dec 30, 2015 3:35 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

[SOLVED]: Accessing self.pluginPrefs __init__() or startup()

Is there a way of accessing self.pluginPrefs[] in either the __init__() or startup() methods?

I've got a checkbox in my PluginConfig.xml for enabling debug mode (self.debug) but I'm struggling to access it before runConcurrentThread() so I can't enable/disable debugging based on the user preferences.

Whilst I'm developing, I've hardcoded self.debug = true inside __init__() but I don't want that there when I release it.

Peter

Posted on
Wed Dec 30, 2015 4:15 pm
FlyingDiver offline
User avatar
Posts: 7265
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Accessing self.pluginPrefs in __init__() or startup()

Code: Select all
def __init__(self, pluginId, pluginDisplayName, pluginVersion, pluginPrefs):
      indigo.PluginBase.__init__(self, pluginId, pluginDisplayName, pluginVersion, pluginPrefs)
      self.debug = pluginPrefs.get(u"showDebugInfo", False)


Code: Select all
<PluginConfig>
   <Field id="showDebugInfo" type="checkbox">
      <Label>Enable debugging:</Label>
      <Description>(not recommended)</Description>
   </Field>
</PluginConfig>

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Dec 30, 2015 10:17 pm
RogueProeliator offline
User avatar
Posts: 2506
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Accessing self.pluginPrefs in __init__() or startup()

Is there a way of accessing self.pluginPrefs[] in either the __init__() or startup() methods?

To expand on Joe's answer, make sure you make the call to the base class first, before the you attempt to read the configuration values.

Posted on
Thu Dec 31, 2015 2:19 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Accessing self.pluginPrefs in __init__() or startup()

Thanks both.

It was the "pluginPrefs.get()" I was missing; I had the rest, including the base call, copied from the 'Example plugin' in the SDK.

Peter

Posted on
Thu Dec 31, 2015 2:21 pm
FlyingDiver offline
User avatar
Posts: 7265
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Accessing self.pluginPrefs in __init__() or startup()

Whenever I can't figure out something like that, I look at the source code for a plugin that does what I need to do....

:D :D :D :D

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Dec 31, 2015 2:23 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Accessing self.pluginPrefs in __init__() or startup()

I looked in a couple - I've got DSC Alarm and Wunderground copied and renamed on my dev machine so I don't confuse myself, but I didn't find this particular answer in those two. :-)


Sent from my iPhone using Tapatalk

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests