Passing back errors from a MenuItem w/ ConfigUI

Forum rules

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo

Posted on
Wed Dec 19, 2012 9:18 pm
puppycrack offline
Posts: 60
Joined: Dec 04, 2012
Location: Rochester, NY

Passing back errors from a MenuItem w/ ConfigUI

I am trying to create a plugin w/ a MenuItems file, to set/get values for a SynchroLinc device. The menu item has a ConfigUI element associated with it, like so:

Code: Select all
<?xml version="1.0"?>
<MenuItems>

   <MenuItem id="menu1">
      <Name>Configure SynchroLinc Device</Name>
      <ConfigUI>
         <Field id="insteon_address" type="menu">
            <Label>SynchroLinc Device</Label>
            <List class="self" method="synchrolincDeviceList"/>
         </Field>
         
         <Field id="trigger_watts" type="textfield" defaultValue="">
            <Label>Trigger Watts</Label>
         </Field>
         
         <Field id="threshold_watts" type="textfield" defaultValue="">
            <Label>Threshold Watts</Label>
         </Field>
         
         <Field id="delay_seconds" type="textfield" defaultValue="">
            <Label>Delay Seconds:</Label>
         </Field>
         
         <Field id="label1" type="label">
            <Label>
               Trigger Watts: 0-1800
               Threshold Watts: 0-127.5
               Delay Secs: .15 - 38.25
            </Label>
         </Field>
         
         <Field id="btn_fetch" type="button" tooltip="Get current values">
            <Title>Fetch</Title>
            <CallbackMethod>actionFetch</CallbackMethod>
         </Field>
         
         <Field id="btn_store" type="button" tooltip="Get current values">
            <Title>Store</Title>
            <CallbackMethod>actionStore</CallbackMethod>
         </Field>
         
         <Field id="simpleSeparator1" type="separator"/>
         
         <Field type="checkbox" id="showDebugInfo">
            <Label>Enable debugging:</Label>
            <Description></Description>
         </Field>
      </ConfigUI>
   </MenuItem>
</MenuItems>


In the method actionGet, I am doing some validation, and trying to get errors back to the UI in the event there *are* errors. However, when I try to return (False, errorsDict, valuesDict), I get:

Code: Select all
<type 'exceptions.TypeError'>:No registered converter was able to extract a C++ reference to type CXmlDict from this Python object of type bool


I tried to just return the errors dictionary (of type indigo.Dict()), but I'm not seeing any errors on the dialog:
Code: Select all
errors = indigo.Dict()
errors['insteon_address'] = "no address specified"
return errors


Any help or pointers?

Thank you!

Posted on
Thu Dec 20, 2012 8:35 am
matt (support) offline
Site Admin
User avatar
Posts: 21426
Joined: Jan 27, 2003
Location: Texas

Re: Passing back errors from a MenuItem w/ ConfigUI

Currently, menu item configUI doesn't get the opportunity to validate its UI. I'd like to improve that at some point, but I'm not sure it will happen in the v6 beta time frame.

But there is a workaround. First, you do know there is already a menu action UI defined to get/set SyncroLinc settings, right? It is available in the Interfaces->INSTEON-> sub menu. As an example of how to do validation, here is the technique it uses:

MenuItems.xml
Code: Select all
<?xml version="1.0"?>
<MenuItems>
   <MenuItem id="configureSynchroLinc">
      <Name>Configure SynchroLinc...</Name>
      <ConfigUI actionId="configureSynchroLinc"/>
   </MenuItem>
</MenuItems>

Actions.xml
Code: Select all
<?xml version="1.0"?>
<Actions>
   <Action id="configureSynchroLinc" >
      <Name>Configure SynchroLinc</Name>
      <CallbackMethod>configureSynchroLinc</CallbackMethod>
      <ConfigUI>
         <Field id="synchrolinc" type="menu">
            <Label>SynchroLinc:</Label>
            <List class="self" method="synchroLincListGenerator"/>
         </Field>
         <Field id="triggerWatts" type="textfield" defaultValue="14.5">
            <Label>Trigger Watts:</Label>
         </Field>
...
      </ConfigUI>
   </Action>
</Actions>

plugin.py
Code: Select all
   def validateActionConfigUi(self, valuesDict, typeId, devId):
      errorsDict = indigo.Dict()
      if typeId == "configureSynchroLinc":
         if valuesDict["synchrolinc"] == '':
            errorsDict["synchrolinc"] = u"You must select a SynchroLinc"
         if valuesDict["triggerWatts"] != '':
            try:
               float(valuesDict["triggerWatts"])
            except:
               errorsDict["triggerWatts"] = u"Trigger Watts must be a valid number"
         # ...
      if len(errorsDict) > 0:
         return (False, valuesDict, errorsDict)
      return (True, valuesDict)

   def configureSynchroLinc(self, action):
      devID = self.getDeviceIdNumber(action.props, "synchrolinc", 0)
      dev = indigo.devices[synchroLincID]
      instnAddr = dev.address
      triggerWatts = float(action.props["triggerWatts"])
      # ...
      # use sendRawExtended(instnAddr, ...) here

So the approach here is to define the UI as an action, which can be validated, and then in the Menu Items list just reference the action. When the menu item is selected, Indigo will then look-up and use the Action UI handler instead. Another advantage of this approach is that the UI/action will be available in the Action panel as well (not just in the plugin's menu).

Image

Posted on
Thu Dec 20, 2012 2:05 pm
puppycrack offline
Posts: 60
Joined: Dec 04, 2012
Location: Rochester, NY

Re: Passing back errors from a MenuItem w/ ConfigUI

I did *not* know there was already a pre-configured way of setting up SynchroLinc devices :oops:. Sometimes, it gets a little confusing as to where certain information is (faq, wiki, forums, developers guide, etc...). So thanks for that.

And thank you for showing the proper approach to validating a UI for a MenuItem. Maybe one day, when I actually write a plugin for which there *isn't* already an alternative, it will be useful :)

Thank you.

Posted on
Thu Dec 20, 2012 4:12 pm
jay (support) offline
Site Admin
User avatar
Posts: 18253
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Passing back errors from a MenuItem w/ ConfigUI

In the Indigo 6 docs we've consolidated some of that information: the Managing Your INSTEON Network in Indigo section of the docs contains all the documentation related to INSTEON device support, including actions available from menus to configure specific devices and device features.

Or, at least, that's the goal. :)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests