Hacking Plug-ins?

Posted on
Wed Dec 18, 2019 1:18 pm
Mark offline
User avatar
Posts: 262
Joined: Apr 21, 2005
Location: California

Hacking Plug-ins?

I'd like to extend the use of a plug-in beyond what the author originally allowed, specifically the Powerview plug-in.

First, am I violating anything by doing so (copyright, best practice, etc)?

The plug-in contains a Python script, and I'd like to use one of its methods in my own Python script, with my own parameters. I can get that to work by copying the Powerview plug-in's python script to Indigo's Scripts/Attachments folder. But I'm wondering if I can somehow access the plug-in's methods, rather than by using that copy.

I tried importing, but Indigo couldn't find the module within the plug-in, not until I copied it to the Scripts/Attachments folder. I guess the plug-in's script is not "in the path."

I found this in your online documentation:
Code: Select all
itunesId = "com.perceptiveautomation.indigoplugin.itunes"
itunesPlugin = indigo.server.getPlugin(itunesId)
if itunesPlugin.isEnabled():
   myWeatherStation = indigo.devices[1798384204]
   outsideTemp = myWeatherStation.states['temperatureF']
   currentCondition = myWeatherStation.states['currentCondition']
   spokenString = "The current temperature is %s degrees. Current condition is %s." % (outsideTemp, currentCondition)
   itunesPlugin.executeAction("pauseAndSay", deviceId=135305663, props={'message':spokenString})

And modified it so that I can get to the Powerview plug-in with this:
Code: Select all
powerviewId = "com.perceptiveautomation.indigoplugin.PowerView"
powerviewPlugin = indigo.server.getPlugin(powerviewId)

Is it then possible to use "powerviewPlugin" to access the plug-in's methods, and send it parameters (by name?)?

The method I'm after (which belongs to a class named "Powerview") is this one (and it's "tNewPosition" that I need to manipulate):
Code: Select all
Powerview().setShadePosition(hubHostname = tHubHostname, shadeId = tShadeId, top = 0, bottom = tNewPosition)

Or is copying the script to the attachments folder the best solution?

Posted on
Wed Dec 18, 2019 2:04 pm
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Hacking Plug-ins?

Mark wrote:
First, am I violating anything by doing so (copyright, best practice, etc)?


The developer put his code up on Github, but he didn't attach a license. I don't think making changes to it for personal use has any issues. If you want however you can fork the repo, make the changes, then issue a pull request which the developer can then decide to accept or not (and generate a new release).

Mark wrote:
The plug-in contains a Python script, and I'd like to use one of its methods in my own Python script, with my own parameters. I can get that to work by copying the Powerview plug-in's python script to Indigo's Scripts/Attachments folder. But I'm wondering if I can somehow access the plug-in's methods, rather than by using that copy.


You probably can if that function is presented as an Action in the plugin - you just need to figure out what properties to pass to the action based on the action's XML definition (in Actions.xml). However, I don't see that using his script directly would be any issue either.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Dec 18, 2019 2:37 pm
Mark offline
User avatar
Posts: 262
Joined: Apr 21, 2005
Location: California

Re: Hacking Plug-ins?

You probably can if that function is presented as an Action in the plugin - you just need to figure out what properties to pass to the action based on the action's XML definition (in Actions.xml). However, I don't see that using his script directly would be any issue either.


And that's the rub, it's not (100%). There is a built-in Action that moves the shade to a position (represented by an integer). But I plug that number into the Action's "Edit Actions" interface. I want to do some math on that number before the Action is executed, which means Python. I can't use the authors Actions for that.

Here's the XML:
Code: Select all
  <Action id="setShadePosition" deviceFilter="self.PowerViewShade">
    <Name>Set Shade Position</Name>
    <CallbackMethod>setShadePosition</CallbackMethod>
    <ConfigUI>
      <Field id="top" type="textfield">
        <Label>Top</Label>
      </Field>
      <Field type="label" id="topDescription">
        <Label>Position of top of shade (for top-down).  0–65535</Label>
      </Field>
      <Field id="bottom" type="textfield">
        <Label>Bottom</Label>
      </Field>
      <Field type="label" id="bottomDescription">
        <Label>Position of bottom of shade (for bottom-up).  0–65535</Label>
      </Field>
    </ConfigUI>
  </Action>


I'll play around with modifying this 'hint" to see if I can't get it to work:
Code: Select all
 itunesPlugin.executeAction("pauseAndSay", deviceId=135305663, props={'message':spokenString})


But maybe on a rainy day. It's working fine as an attachment script. Thanks!

Posted on
Wed Dec 18, 2019 2:53 pm
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Hacking Plug-ins?

Looks like you just have to pass a "top" and a "bottom" key, the value of both should be numeric 0-65535.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Dec 18, 2019 3:08 pm
Mark offline
User avatar
Posts: 262
Joined: Apr 21, 2005
Location: California

Re: Hacking Plug-ins?

I gave this a shot:
Code: Select all
powerviewId = "com.perceptiveautomation.indigoplugin.PowerView"
powerviewPlugin = indigo.server.getPlugin(powerviewId)
indigo.server.log(unicode(powerviewPlugin))

powerviewPlugin.executeAction("setShadePosition", deviceId=1243816754, props={'topDescription':0,'bottomDescription':0,})


But got an error about .executeAction. I guess the author has to specifically support executeAction somehow?

That's OK. Enough time spent "fixing" something that isn't broken. Just thought I'd try to expand my knowledge about plug-ins a bit. Like I said, it's working as an attachment. I guess I'll worry about this if I ever have to upgrade or replace the hub that the plug-in is communicating with. For now, it works.

Posted on
Wed Dec 18, 2019 3:37 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Hacking Plug-ins?

Instead of "topDescription" and "bottomDescription" in the props dict use "top" and "bottom". What you are using is for the UI labels – the editable text fields have the keys "top" and "bottom".

Image

Posted on
Sun Dec 22, 2019 12:26 pm
Mark offline
User avatar
Posts: 262
Joined: Apr 21, 2005
Location: California

Re: Hacking Plug-ins?

Hey, I got it to work! Thanks Matt. I did have those args (params?) wrong, but I also had the bundle identifier wrong. This worked:

Code: Select all
powerviewId = "net.segment7.powerview"
powerviewPlugin = indigo.server.getPlugin(powerviewId)

powerviewPlugin.executeAction("setShadePosition", deviceId=1243816754, props={'top':0,'bottom':35000})

Posted on
Sun Dec 22, 2019 5:15 pm
Mark offline
User avatar
Posts: 262
Joined: Apr 21, 2005
Location: California

Re: Hacking Plug-ins?

OK, so what I'm piecing together:

I now know how to come up with the bundle Identifier. That's in the info.plist file, right?

And any action listed in the actions.xml file I can call with "xxxx.executeAction()" function (method?), where "xxxx" is the result of the indigo.server.getPlugin("bundle Identifier") function.

I'm not clear on whether to use the action's "id" or its "callBackMethod" as the first arg of "xxxx.executeAction()", in quotes, as PowerView named those the same.

And I'm not too clear on how to determine the props. In this case it was the ids of two of the fields within the ConfigUI section of the actions xml, but I'm guessing there's more to it than than.

But that's a start...

Posted on
Sun Dec 22, 2019 5:32 pm
FlyingDiver offline
User avatar
Posts: 7216
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Hacking Plug-ins?

Mark wrote:
OK, so what I'm piecing together:

I now know how to come up with the bundle Identifier. That's in the info.plist file, right?

And any action listed in the actions.xml file I can call with "xxxx.executeAction()" function (method?), where "xxxx" is the result of the indigo.server.getPlugin("bundle Identifier") function.

I'm not clear on whether to use the action's "id" or its "callBackMethod" as the first arg of "xxxx.executeAction()", in quotes, as PowerView named those the same.

And I'm not too clear on how to determine the props. In this case it was the ids of two of the fields within the ConfigUI section of the actions xml, but I'm guessing there's more to it than than.


Yes.

You want the id. The CallBackMethod is the name of the function in the Python code. Indigo uses the id to find the function.

The props are the fields in the ConfigUI section. Some may be optional, but you can specify all. But types "label" and "separator" aren't used.

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

Posted on
Sun Dec 22, 2019 5:33 pm
Mark offline
User avatar
Posts: 262
Joined: Apr 21, 2005
Location: California

Re: Hacking Plug-ins?

Excellent. Thanks Joe!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 7 guests