How to add an error to validateDeviceConfigUi

Posted on
Thu May 21, 2015 10:25 am
zurich offline
Posts: 103
Joined: Aug 11, 2014

How to add an error to validateDeviceConfigUi

Greetings,

I use 5 EasyDAQ relay/DIO boards. I would like to add some code to validateDeviceConfigUi in plugin.py so that if I try to add a channel (mirror device) for a board and that channel is already used I would get a warning and be prevented from adding it as a mirrored device.

I have com up with the following:

Code: Select all
inUseList = []

isRelay = ('relay %d' %valuesDict["channelSel"])
         
inUseList = [dev.name for dev in indigo.devices]
         
if isRelay in inUseList:         
   errorsDict["channelSel"] = u"relay is already configured"


This works gut with one board but not with multiple boards because other boards have the same channel number. Thus it may see a duplicate channel and give the error but the channel is really from another board (because my code gets all the devices). What I need to get is the list of devices for the inUseList but only for the current device selected but I cannot find a way to do this?

Is it possible for you to give me some direction?

Thanks to you,

Z

Posted on
Thu May 21, 2015 11:03 am
jay (support) offline
Site Admin
User avatar
Posts: 18212
Joined: Mar 19, 2008
Location: Austin, Texas

Re: How to add an error to validateDeviceConfigUi

You're talking about modifying the EasyDAQ plugin? That's really not recommended since your changes will get overwritten every time we upgrade Indigo...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu May 21, 2015 12:47 pm
zurich offline
Posts: 103
Joined: Aug 11, 2014

Re: How to add an error to validateDeviceConfigUi

Greetings,

Yes it is for the EasyDAQ plugin I made my question to reference. I copy over my reworked plugin if there is an update to the software. This not an inconvenience for me.

I have already made changes to the plugin to be able to select an input as a mirror device so it shows in the main UI. Also I have removed the all plugin ACTIONS because I only use my EasyDAQ boards for ON/OFF/Toggle and control the Inputs and Outputs as Devices. This works extremely well for my application and this exercise has given me much understanding of plugin constructions.

I hope you do not mind too much me adjusting your plugin for my use and that you may answer the question to which I posed in the earlier posting.

Kind regards,

Z

Posted on
Thu May 21, 2015 1:50 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: How to add an error to validateDeviceConfigUi

No problem at all for you hacking the plugins for your personal use.

Take a look at the method _addMirrorDevToMap() in the plugin. Note that the plugin keeps track of all mirrored devices inside the self.mirrorDevMap dictionary. Also look at _lookupMirrorDevIterFromMap(). It should be able to tell you if a mirror device given a parent ID and channel ID exists or not. Not positive that is what you are after, but I think it might be.

Image

Posted on
Sat May 23, 2015 4:20 pm
zurich offline
Posts: 103
Joined: Aug 11, 2014

Re: How to add an error to validateDeviceConfigUi

Greetings,

Much thanks for your suggestion. Using your recommendation I came up with the following code added to the "validateDeviceConfigUi" method and it now gives an error if a mirror device is added while it already exists in the UI.

Code: Select all
#hack - give error if trying to add device twice            
dupDev = ('%s.%s' %(valuesDict["deviceSel"], valuesDict["channelSel"]))
        if dupDev in self.mirrorDevMap:
              errorsDict["channelSel"] = u"mirror device has already been added to UI"


thanks to you,

Z

Posted on
Sat May 23, 2015 5:18 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: How to add an error to validateDeviceConfigUi

Great – I'm glad you got it working.

Image

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest