My People Plugin - Comments, Suggestions, Issues:

Posted on
Sat Dec 19, 2020 10:56 am
whmoorejr offline
User avatar
Posts: 565
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: 908
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: 565
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: 565
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: 565
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

Posted on
Thu Jan 20, 2022 10:35 am
ryanbuckner offline
Posts: 720
Joined: Oct 08, 2011

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

I. use the Lat / Long from the Life360 Plugin to update the Lat/Long of the people devices defined in the your Plugin

Posted on
Sun Apr 24, 2022 9:21 am
ryanbuckner offline
Posts: 720
Joined: Oct 08, 2011

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

I would like an option to set the error log debug reporting level. On/Off will suffice.

Posted on
Sun Apr 24, 2022 10:00 am
whmoorejr offline
User avatar
Posts: 565
Joined: Jan 15, 2013
Location: Houston, TX

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

ryanbuckner wrote:
I would like an option to set the error log debug reporting level. On/Off will suffice.


I'll take a look into this. Honestly, this was my first plugin, so I'm not even sure where the debug scripting stuff goes yet. The other thing... this plugin doesn't really "do" anything. Meaning that the plugin doesn't calculate anything or activity go out and get data, etc. This plugin just takes data and calculations done elsewhere in indigo and gives you a different way of looking at it. In other words, I'm not sure what errors are possible.

But, if I make more complex actions to go in the plugin or collaborate with another plugin developer, I should probably know how to write up the debugging code stuff.

Thank you for the suggestion and I hope the plugin is working well for you.

Bill
My Plugin: My People

Posted on
Sun Apr 24, 2022 11:16 am
ryanbuckner offline
Posts: 720
Joined: Oct 08, 2011

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

whmoorejr wrote:
ryanbuckner wrote:
I would like an option to set the error log debug reporting level. On/Off will suffice.


I'll take a look into this. Honestly, this was my first plugin, so I'm not even sure where the debug scripting stuff goes yet. The other thing... this plugin doesn't really "do" anything. Meaning that the plugin doesn't calculate anything or activity go out and get data, etc. This plugin just takes data and calculations done elsewhere in indigo and gives you a different way of looking at it. In other words, I'm not sure what errors are possible.

But, if I make more complex actions to go in the plugin or collaborate with another plugin developer, I should probably know how to write up the debugging code stuff.

Thank you for the suggestion and I hope the plugin is working well for you.


No big deal. Here are some of the debug logs I see:

Code: Select all
Apr 24, 2022 at 1:15:28 PM
   Trigger                         Sync BMW People with Connected
   My People Debug                 The Device -Ryan's BMW:userLatitude- value set to: -XXX- From Source: -Ryan's BMW 540ix:gps_lat-
   My People Debug                 metadata added to Ryan's BMW. key= meta_userLatitude with value: %%d:575567701:gps_lat%%
   My People Debug                 The Device -Ryan's BMW:userLongitude- value set to: --YYY- From Source: -Ryan's BMW 540ix:gps_long-
   My People Debug                 metadata added to Ryan's BMW. key= meta_userLongitude with value: %%d:575567701:gps_long%%

Posted on
Sun Apr 24, 2022 12:14 pm
whmoorejr offline
User avatar
Posts: 565
Joined: Jan 15, 2013
Location: Houston, TX

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

ryanbuckner wrote:
No big deal. Here are some of the debug logs I see:

Code: Select all
   My People Debug                 ...

Got it. I was thinking just error stuff. I put a bunch of logging stuff in the code while writing the plugin to watch the log while tinkering.... I left a bunch of that logging stuff in there. So I just need a way to turn it on/off. Shouldn't be too hard once I figure it out.

Side-note: I edited your post to take out the Lat/long of your BMW (assuming you don't need me to know where you parked). :D

Bill
My Plugin: My People

Posted on
Sun Apr 24, 2022 12:36 pm
ryanbuckner offline
Posts: 720
Joined: Oct 08, 2011

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

Haha thanks. I assume a few searches can probably reveal my address.

In your plugin config, you would just put something like this in your PluginConfig.xml

Code: Select all
<Field id="showDebugInfo" type="checkbox">
      <Label>Enable debugging:</Label>
      <Description>(recommended to turn off after specific debug)</Description>
</Field>


And add this to your __init__ in plugin.py

Code: Select all
self.debug = pluginPrefs.get("showDebugInfo", False)


Anything using logger.debug
Code: Select all
self.logger.debug("Starting device: " + device.name)
will then be hidden from the logs unless that checkbox is chosen.

Posted on
Wed May 18, 2022 4:31 pm
whmoorejr offline
User avatar
Posts: 565
Joined: Jan 15, 2013
Location: Houston, TX

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

ryanbuckner wrote:
...In your plugin config, you would just put something like this in your PluginConfig.xml ....


Instead of a checkbox, I used a drop down to select the level of logging. Not really needed for a simple plugin like this (Where there are only debug messages and one warning message <- if you select a record that doesn't exist. )

Anyway, I posted the update... version 2.0.02

it was a learning experience. I think the way logging works changed after the plugin examples were written. So I never imported logging or used self.logger.debug. I was using self.debugLog and indigo.server.log for everything. Well, it's all self.logger.debug now or self.logger.warning so it should be able to run silently in the background now.

Let me know if you run into any issues. I'm on a new computer and I hit a few bumps re-installing GitHub on this computer. But it looks like it all updated okay.

Bill
My Plugin: My People

Posted on
Wed May 18, 2022 4:42 pm
ryanbuckner offline
Posts: 720
Joined: Oct 08, 2011

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

i've installed the update. I'll let you know how it goes. Thx!

Posted on
Wed May 18, 2022 9:04 pm
mundmc offline
User avatar
Posts: 908
Joined: Sep 14, 2012

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

I am so glad you’re still working on this and after our house is repaired (we have been out for 18 months now) I continue to look forward to implementing it!

Posted on
Wed May 18, 2022 9:25 pm
whmoorejr offline
User avatar
Posts: 565
Joined: Jan 15, 2013
Location: Houston, TX

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

mundmc wrote:
I am so glad you’re still working on this and after our house is repaired (we have been out for 18 months now) I continue to look forward to implementing it!
Once I know this plugin is rock solid and no compatibility issues…. I can basically template it to make a room-centric version of it.


Sent from my iPhone using Tapatalk

Bill
My Plugin: My People

Who is online

Users browsing this forum: No registered users and 1 guest

cron