My People Plugin - Comments, Suggestions, Issues:

Posted on
Sat Dec 19, 2020 10:56 am
whmoorejr offline
User avatar
Posts: 532
Joined: Jan 15, 2013
Location: Houston, TX

My People Plugin - Comments, Suggestions, Issues:

Brief bio.... Anyone that makes plugins regularly will look at the guts of my plugin and probably chuckle. It's a bare bones plugin that does one specific thing, data repository for people. I would like to expand on it, make it more user friendly and that will come as my programming skills improve or as other more knowledgeable Indigoites contribute to it... (Once I get a better grip on how GitHub works)

For script babies out there like me, download this plugin, right click, show package contents and polk around. This plugin is 1/10 as complex as the SDK examples (still about 350% above my skill level).

Next up for this plugin (which will require significant learning on my part)
    Backup data, export device / states to a local CSV file.
    Import data from a local CSV file.
    New action that can update all fields at the same time (It's kinda a PITA to start with a fresh person and go through each action individually).

Ideally all fields would be entered in a big configuration page, but it would have to be able to mirror states and the configure UI would have to update when a state is updated and visa-versa. <-- I'm only at about 5% of the way to figuring out how to do that.

Lastly, based on reviews, input and modifications to this plugin, I would like to eventually make similar plugins, like "My Rooms" that would do the same thing but be a repository for all devices in a "Room device" reflected as custom states: MyRoom.Lamp, MyRoom.Motion, MyRoom.Occpancy, etc....

Bill
My Plugin: My People

Posted on
Wed Jan 20, 2021 11:38 pm
mundmc offline
User avatar
Posts: 863
Joined: Sep 14, 2012

Re: My People Plugin - Comments, Suggestions, Issues:

Hey Bill!
Sorry it toook me so long to take a whirl at this!

Okay- some possible errors in the log (your guess is far better than mine):
Plugins->MyPeople->Configure gets this message:
Code: Select all

Error (client)                  getXmlFromPlugin() caught exception: incorrect type returned (expected XML string)
   Error (client)                  runConfigDialog() caught exception: NSInvalidArgumentException -- *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
   My People Error                 Error in plugin execution CallPluginFunc:

Traceback (most recent call last):
  File "/Library/Application Support/Perceptive Automation/Indigo 7.4/IndigoPluginHost.app/Contents/Resources/PlugIns/plugin_base.py", line 929, in getPrefsConfigUiXml
  File "/Library/Application Support/Perceptive Automation/Indigo 7.4/IndigoPluginHost.app/Contents/Resources/PlugIns/plugin_base.py", line 557, in _parseConfigUINode
  File "/Library/Application Support/Perceptive Automation/Indigo 7.4/IndigoPluginHost.app/Contents/Resources/PlugIns/plugin_base.py", line 479, in _getElementAttribute2
ValueError: required XML attribute 'type' is missing or empty in <Field> of file PluginConfig.xml


Thoughts?

Posted on
Thu Jan 21, 2021 10:26 am
whmoorejr offline
User avatar
Posts: 532
Joined: Jan 15, 2013
Location: Houston, TX

Re: My People Plugin - Comments, Suggestions, Issues:

mundmc wrote:
Hey Bill!
Sorry it toook me so long to take a whirl at this!

Okay- some possible errors in the log (your guess is far better than mine):

I'll talk through this because I know you (and others) would like to learn how to make a plugin, so maybe people can learn from my trials....

I'm thinking I either need to figure out how to configure the configure dialog thing or how to take it out. The good news is there isn't anything to configure with the plugin. (I got the same message).

I'm guessing it's the "PluginConfig.xml" file.
The "Traceback (most recent call last):" is showing some indigo python code "plugin_base.py" that doesn't like my "PluginConfig.xml" file. When you are working on your own plugin, and you get an error, you will see line numbers in your plugin's python code "plugin.py" where it gets jacked up. So, you open up your plugin.py file in your plugin, go to that line and figure out where you screwed up.

As an FYI, when you make a plugin, you put a bunch of files in a folder. When done, you change the extension of the folder to ".indigoPlugin" and Poof, it turns into that little lego block looking thing. To veiw the contents and see what makes a plugin tick, Right-Click on the plugin to "Show Package Contents"

Anyway, the file "PluginConfig.xml" isn't a required file. I only use it as a persistent place to store the variable for "recordRequested". That variable (a number), gets updated when you use the Show Next, Show Previous, Show First, Show Last actions. I'll start tweaking it until the error thing goes away and then I'll post a new version.

By the way, thank you for finding it. :)

Bill
My Plugin: My People

Posted on
Thu Jan 21, 2021 2:47 pm
whmoorejr offline
User avatar
Posts: 532
Joined: Jan 15, 2013
Location: Houston, TX

Re: My People Plugin - Comments, Suggestions, Issues:

I'm packaging an update up now, but I thought this is a good example for anyone that wants to know the basics of how a plugin works...
The changes in the forthcoming update will fix the "Configure..." option for the plugin. (nothing to configure, but now there is a pop up that says so.)
The next change is I added a few new states: homeLast, awayLast, alertsOn. Like every other custom state with this plugin, they are blank text blocks where you can enter anything (including a variable or device.state substitution)

As an example (for your information), how I added the "alertsOn" state to the plugin.

1) Device.xml: define the state for the "person" device.
Code: Select all
         <State id="alertsOn">
            <ValueType>String</ValueType>
            <TriggerLabel>Alerts On</TriggerLabel>
            <ControlPageLabel>Alerts On</ControlPageLabel>
         </State>
From the code, you can also see this is how that state is defined on a trigger or a control page.

2) Actions.xml: where you define what actions your plugin can take. Basically its the information for a dialog box and a field to store the data in...
The action to add data to the alertsOn state:
Code: Select all
   </Action>
      <Action id="setAlertsOn" deviceFilter="self">
      <Name>Set Alerts On</Name>
      <CallbackMethod>setAlertsOn</CallbackMethod>
      <ConfigUI>
         <Field type="textfield" id="alertsOnField">
            <Label>Alerts On:</Label>
         </Field>
         <Field id="label" type="label" fontSize="small" fontColor="darkgray">
            <Label>You can insert variable substitution %%v:VARIABLEID%% or device state %%d:DEVICEID:STATEKEY%%</Label>
         </Field>
      </ConfigUI>
   </Action>   

Part of the action to update all the states of a person device:
Code: Select all
            <Field type="textfield" id="alertsOnAllField">   
            <Label>Alerts On:</Label>   
         </Field>   
The last bits are in the "plugin.py" document that ties everything together with python code.

3) plugin.py:
Code: Select all
## Action to update custom state of a person device
   
   def setAlertsOn(self, pluginAction, dev):
      substitutedTitle = self.substitute(pluginAction.props.get("alertsOnField", ""))
      dev.updateStateOnServer(key="alertsOn", value=substitutedTitle)
      self.debugLog("Set Alerts On: " + str(pluginAction.props.get(u"alertsOnField")) + " Entered.  State alertsOn set to: " + substitutedTitle)
      
      
## Part of the Action to update all states of a person device      
      substitutedTitle21 = self.substitute(pluginAction.props.get("alertsOnAllField", ""))
      self.debugLog("21: " + str(pluginAction.props.get(u"alertsOnAllField")) + " Entered.  " + "State alertsOn set to: " + substitutedTitle21)
      dev.updateStateOnServer(key="alertsOn", value=substitutedTitle21)
      
   
## Part added to the actions that forward and reverse the "Now Showing" device.   
      self.aPersonDev.updateStateOnServer(key="alertsOn", value=alertsOn)   
If you notice in the first paragraph "def setAlertsOn" is from the Actions.xml as the "CallbackMethod". You can also see where its moving around data... alertsOn versus alertsOnField versus alertsOnAllField.

You may also notice in the debug log what looks like two different ways to say the same thing.... substitutedTitle versus str(pluginAction.pprops.get(u"alertsOnField")).

If you enter "Chicken Taco" in the action, the log will say:
"SetAlertsOn: Chicken Taco Entered. State alertsOn set to: Chicken Taco.

However, if "Chicken Taco" is saved as a variable %%v:135790123%%, then if you enter "%%v:135790123%%" in the action, the log will say:
"SetAlertsOn: %%v:135790123%% Entered. State alertsOn set to: Chicken Taco"
Thats because the first is a string of what you entered and the second is the value of what you entered. (The value is what is stored in the state for the device)

Bill
My Plugin: My People

Posted on
Mon Sep 06, 2021 11:36 am
whmoorejr offline
User avatar
Posts: 532
Joined: Jan 15, 2013
Location: Houston, TX

Re: My People Plugin - Comments, Suggestions, Issues:

Lat/Long Discussion:
Adding Lat/Long is simple-ish to do.
I wrote a different version of this plugin which I'm still polishing, but it is a little easier to navigate, edit fields, etc. The downside... it's different enough, I'm not sure if a "People" device from the original (currently published) plugin will work with the new version. <-- I still have some testing to do.


Since Lat/Long is definitely a constantly changing variable... what is the source you are using and is there any other related variables?
Currently there is an "Address" variable (Which could be populated from a trigger that watches any number of location based plugins). Those same plugins generally also spit out Latitude and Longitude. Like would a "Map" variable be of use? The "Find Friends Mini" plugin translates the "Address" variable into a "Google Map URL". That could ? populate a control page with a map image? <-- guessing, but I think that is how that would work.... I know it's possible to view a URL from a variable.. I'll have to brush up on how to do that.

Any other thoughts on it?

Bill
My Plugin: My People

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest