Page 1 of 1

Enabling/disabling plugins from a script

PostPosted: Fri Jan 11, 2019 2:15 pm
by papamac
Are there indigo system call to enable and disable plugins from a standalone python script? I would like to disable HomeKit Bridge when my security system is armed and then re-enable it after a disarm. I couldn't find any way of doing this in the documentation.

Thanks,

papamac

Re: Enabling/disabling plugins from a script

PostPosted: Fri Jan 11, 2019 2:38 pm
by FlyingDiver
You mean a python script running as an Indigo action?

Pretty sure this is right:

Code: Select all
plugin = indigo.server.getPlugin("com.flyingdiver.indigoplugin.betteremail")
if plugin.isEnabled():
   plugin.disable()


You'll need the plugin ID for the plugin you actually want to enable/disable. If it's not in the docs, look in the Info.plist inside the plugin wrapper.

Re: Enabling/disabling plugins from a script

PostPosted: Fri Jan 11, 2019 11:14 pm
by kw123
.disable() does not work . -- plugin.restart() -- does.

Has been on my request list for a LONG time.. (sql logger is busy sometimes and then it can't get back to normal - when your DB is big and a dev.state changes from int to real for example . need to disable / enable for 10 secs, then everything is fine. Right now doing this with an applescript key stroke screen commands.. which is not portable and will break if anything changes


===>>>> we need .disable() and .enable() <<<<<====

Re: Enabling/disabling plugins from a script

PostPosted: Sat Jan 12, 2019 5:26 am
by DaveL17
IMO, .enable() and .disable() are a security risk; being able to turn an arbitrary plugin on or off from Python is too dangerous. I don't think that .enable() and .disable() should be made available. However, a plugin developer could effectively add this feature to an individual plugin without too much difficulty (on/off being different than enabled/disabled).

For the OP, you might be able to do what you want using a derivative of this script which enables/disables Indigo devices. I don't believe that HKB has the facility to enable/disable devices through a plugin action, but you could create two custom actions using each bit of the script to turn on/off HKB server devices.

Code: Select all
# To disable all plugin devices
for dev in indigo.devices.iter("com.eps.indigoplugin.homekit-bridge"):
    indigo.device.enable(dev, value=False)

# To enable all plugin devices
for dev in indigo.devices.iter("com.eps.indigoplugin.homekit-bridge"):
    indigo.device.enable(dev, value=True)

# To disable a single device
dev = indigo.devices[369921985]
indigo.device.enable(dev, value=False)

Re: Enabling/disabling plugins from a script

PostPosted: Sat Jan 12, 2019 8:57 am
by kw123
I understand the security concern. But I really would like have the sgllogger be able to at least pause.




Sent from my iPhone using Tapatalk

Re: Enabling/disabling plugins from a script

PostPosted: Sat Jan 12, 2019 9:22 am
by DaveL17
kw123 wrote:
I understand the security concern. But I really would like have the sgllogger be able to at least pause.




Sent from my iPhone using Tapatalk

But it's an all or nothing proposition.

I think the better option would be to add a pause feature directly to the SQL Logger plugin rather than opening the door for every plugin.

Re: Enabling/disabling plugins from a script

PostPosted: Sat Jan 12, 2019 10:30 am
by kw123
I would be very happy.



Sent from my iPhone using Tapatalk

Re: Enabling/disabling plugins from a script

PostPosted: Sun Jan 13, 2019 8:10 pm
by papamac
DaveL17, you had a nice suggestion about disabling devices... but it doesn't work with HomeKit Bridge. HomeKit Bridge has only one kind of device, the HomeKit Accessory Server. Disabling this device has the effect of removing the check on the Comms Enabled checkbox, but it does nothing to the server. The server keeps functioning as though nothing happened. I will ask Colorado4Wheeler about this.

Re: Enabling/disabling plugins from a script

PostPosted: Mon Jan 14, 2019 3:55 am
by DaveL17
papamac wrote:
DaveL17, you had a nice suggestion about disabling devices... but it doesn't work with HomeKit Bridge. HomeKit Bridge has only one kind of device, the HomeKit Accessory Server. Disabling this device has the effect of removing the check on the Comms Enabled checkbox, but it does nothing to the server. The server keeps functioning as though nothing happened. I will ask Colorado4Wheeler about this.

Without diving into the code, there may be a simple change that the dev could make in order to honor the comm disabled setting within Indigo. It could be that he simply never envisioned that someone would want the server device to be taken offline.

Enabling/disabling plugins from a script

PostPosted: Mon Jan 14, 2019 5:05 am
by siclark
I might be missing something here, but don't you just turn off the relevant HKB device. For instance I have all my alarm and motion devices in their own bridge device and can just turn it on and off as required , for instance from triggers based on whether the alarm itself is armed or not.
I'm pretty sure C4W does the same.
That way I can disable some functionality but still check on lights etc. Or I could turn it all off. Why does the whole plugin need disabling?


Sent from my iPhone using Tapatalk

Re: Enabling/disabling plugins from a script

PostPosted: Mon Jan 14, 2019 4:42 pm
by jay (support)
Plugins that depend on/wrap existing Indigo devices should most definitely honor when the user disables/enables them using the standard mechanisms. Plugins will get a deviceUpdated message for any device change (assuming they've subscribed to device changes as they should) and they should take appropriate action when they see a device is no longer enabled.

Re: Enabling/disabling plugins from a script

PostPosted: Mon Jan 14, 2019 4:46 pm
by jay (support)
DaveL17 wrote:
IMO, .enable() and .disable() are a security risk; being able to turn an arbitrary plugin on or off from Python is too dangerous.


This is exactly why we only allow restarts of plugins from other plugins/scripts.