Plugin that requires additional python modules

Posted on
Mon Nov 25, 2019 9:51 am
bap offline
Posts: 33
Joined: Sep 25, 2012

Plugin that requires additional python modules

I'm toying with the idea of writing a python plugin that would make use of websockets, and as such would require the optional websocket-client and wsaccel modules that MacOS doesn't include by default. I'm wondering what the best way of dealing with this is. Testing if the module(s) are imported properly is easy enough:

Code: Select all
try:
  import websoket
  import wsaccel
  websockets_included = True
except:
  websockets_include = False


What I'm wondering is what would be the best way to report this to the user? Clearly a log message is one approach, but what about reporting this in the PluginConfig and/or Device dialogs, preventing devices from being created, etc? Are there any standard/suggested approaches to dealing with something like this?

Thanks,

-Bruce

Posted on
Mon Nov 25, 2019 11:42 am
jay (support) offline
Site Admin
User avatar
Posts: 18225
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Plugin that requires additional python modules

Generally, we encourage plugins to include the modules they need. If the modules are pure python (no compiled C code for instance), then it's pretty simple to do (verify the license allows it). That way you know the modules are present and you don't need special logic to functionally disable the plugin.

The trick is to also get any requirements for the modules. So initially getting it done might take some time, but once you've got that worked out then it's great.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Nov 27, 2019 12:12 pm
bap offline
Posts: 33
Joined: Sep 25, 2012

Re: Plugin that requires additional python modules

Thanks, Jay. Can you point me to . plugin that includes a custom module so I can see how it's done?

Posted on
Wed Nov 27, 2019 1:52 pm
FlyingDiver online
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Plugin that requires additional python modules

bap wrote:
Thanks, Jay. Can you point me to . plugin that includes a custom module so I can see how it's done?


My Twilio plugin includes the Twilio library module. The MQTT Connector includes several additional modules.

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

Posted on
Wed Nov 27, 2019 1:57 pm
bap offline
Posts: 33
Joined: Sep 25, 2012

Re: Plugin that requires additional python modules

FlyingDiver wrote:
bap wrote:
Thanks, Jay. Can you point me to . plugin that includes a custom module so I can see how it's done?


My Twilio plugin includes the Twilio library module. The MQTT Connector includes several additional modules.


Awesome, thanks for the pointers!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 5 guests