default values in devices.xml

Posted on
Tue Jan 15, 2019 11:00 am
kw123 offline
User avatar
Posts: 8360
Joined: May 12, 2013
Location: Dallas, TX

default values in devices.xml

Code: Select all
         
in devices.xml:

<Field id="pin_Coil1"        
   type="menu" defaultValue="26" >
    <Label>GPIO pin for coil1-#6:</Label>   
      <List class="self" filter="" method="filtergpioList" dynamicReload="false" /> 
</Field>


in plugin:

_GlobalConst_allGPIOlist = [
     ["1", "do not use"]
   , ["2",  "GPIO02 = pin  # 3 -- I2C"]
   , ["3",  "GPIO03 = pin  # 5 -- I2C"]
   , ["4",  "GPIO04 = pin  # 7 -- ONE WIRE"]
   , ["17", "GPIO17 = pin  # 11 -- DHT"]
   , ["27", "GPIO27 = pin  # 13"]
   , ["22", "GPIO22 = pin  # 15"]
   , ["10", "GPIO10 = pin  # 19 -- SPS MOSI"]
   , ["9",  "GPIO09 = pin  # 21 -- SPS MISO"]
   , ["11", "GPIO11 = pin  # 23 -- SPS SCLK"]
   , ["5",  "GPIO05 = pin  # 29"]
   , ["6",  "GPIO06 = pin  # 31"]
   , ["13", "GPIO13 = pin  # 33"]
   , ["19", "GPIO19 = pin  # 35"]
   , ["26", "GPIO26 = pin  # 37"]
   , ["14", "GPIO14 = pin  # 8  -- TX - REBOOT PIN OUT"]
   , ["15", "GPIO15 = pin  # 10 -- RX - REBOOT PIN IN"]
   , ["18", "GPIO18 = pin  # 12"]
   , ["23", "GPIO23 = pin  # 16"]
   , ["24", "GPIO24 = pin  # 18"]
   , ["25", "GPIO25 = pin  # 22"]
   , ["8",  "GPIO08 = pin  # 24 -- SPS CE0"]
   , ["7",  "GPIO07 = pin  # 26 -- SPS CE1"]
   , ["12", "GPIO12 = pin  # 32"]
   , ["16", "GPIO16 = pin  # 36"]
   , ["20", "GPIO20 = pin  # 38"]
   , ["21", "GPIO21 = pin  # 40"]]

####-------------------------------------------------------------------------####
   def filtergpioList(self, valuesDict=None, filter="", typeId="", devId="x"):
         list = copy.deepcopy(_GlobalConst_allGPIOlist)
         return list


the default value when editing the device should be "26", "GPIO26 = pin # 37" but it shows blank

Any idea what I am doing wrong?

It works fine with regular hard coded lists, textfields ...


Karl

Posted on
Tue Jan 15, 2019 11:11 am
FlyingDiver offline
User avatar
Posts: 7210
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: default values in devices.xml

Your dynamic method needs to return a list (array) of tuples, not lists:

Code: Select all
_GlobalConst_allGPIOlist = [
     ("1", "do not use")
   , ("2",  "GPIO02 = pin  # 3 -- I2C")
   , ("3",  "GPIO03 = pin  # 5 -- I2C")
   , ("4",  "GPIO04 = pin  # 7 -- ONE WIRE")
   , ("17", "GPIO17 = pin  # 11 -- DHT")
   , ("27", "GPIO27 = pin  # 13")
   , ("22", "GPIO22 = pin  # 15")
   , ("10", "GPIO10 = pin  # 19 -- SPS MOSI")
   , ("9",  "GPIO09 = pin  # 21 -- SPS MISO")
   , ("11", "GPIO11 = pin  # 23 -- SPS SCLK")
   , ("5",  "GPIO05 = pin  # 29")
   , ("6",  "GPIO06 = pin  # 31")
   , ("13", "GPIO13 = pin  # 33")
   , ("19", "GPIO19 = pin  # 35")
   , ("26", "GPIO26 = pin  # 37")
   , ("14", "GPIO14 = pin  # 8  -- TX - REBOOT PIN OUT")
   , ("15", "GPIO15 = pin  # 10 -- RX - REBOOT PIN IN")
   , ("18", "GPIO18 = pin  # 12")
   , ("23", "GPIO23 = pin  # 16")
   , ("24", "GPIO24 = pin  # 18")
   , ("25", "GPIO25 = pin  # 22")
   , ("8",  "GPIO08 = pin  # 24 -- SPS CE0")
   , ("7",  "GPIO07 = pin  # 26 -- SPS CE1")
   , ("12", "GPIO12 = pin  # 32")
   , ("16", "GPIO16 = pin  # 36")
   , ("20", "GPIO20 = pin  # 38")
   , ("21", "GPIO21 = pin  # 40")
]

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

Posted on
Tue Jan 15, 2019 12:01 pm
kw123 offline
User avatar
Posts: 8360
Joined: May 12, 2013
Location: Dallas, TX

Re: default values in devices.xml

tried that , no change

tried also
_GlobalConst_allGPIOlist = (
("1", "do not use")
, ("2", "GPIO02 = pin # 3 -- I2C")
, ("3", "GPIO03 = pin # 5 -- I2C")
...
)
all couple but that creates an error message it wants a list not a tuple.

Karl

ps when opening the list everything is there , just the DEFAULT is not populated.

Posted on
Tue Jan 15, 2019 12:04 pm
FlyingDiver offline
User avatar
Posts: 7210
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: default values in devices.xml

Why not just put the list in the xml file. It doesn't appear that you're modifying it in any way.

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

Posted on
Tue Jan 15, 2019 12:09 pm
FlyingDiver offline
User avatar
Posts: 7210
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: default values in devices.xml

Now that I think about it some more, I'm not sure the default value field works at all with a callback generated menu list. I think I implemented the getDeviceConfigUiValues() method to set the "default" value for devices.

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

Posted on
Tue Jan 15, 2019 12:21 pm
kw123 offline
User avatar
Posts: 8360
Joined: May 12, 2013
Location: Dallas, TX

Re: default values in devices.xml

I use that list in many places ( > 50)

instead of having long lists everywhere i just have one def.

Karl

Posted on
Tue Jan 15, 2019 12:31 pm
jay (support) offline
Site Admin
User avatar
Posts: 18212
Joined: Mar 19, 2008
Location: Austin, Texas

Re: default values in devices.xml

[MODERATOR NOTE] Moved to correct forum.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Jan 15, 2019 12:31 pm
jay (support) offline
Site Admin
User avatar
Posts: 18212
Joined: Mar 19, 2008
Location: Austin, Texas

Re: default values in devices.xml

FlyingDiver wrote:
Now that I think about it some more, I'm not sure the default value field works at all with a callback generated menu list. I think I implemented the getDeviceConfigUiValues() method to set the "default" value for devices.


I think this is correct.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Jan 15, 2019 1:22 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: default values in devices.xml

Now that I think about it some more, I'm not sure the default value field works at all with a callback generated menu list. I think I implemented the getDeviceConfigUiValues() method to set the "default" value for devices.


Yeah, we have discussed this previously:
https://forums.indigodomo.com/viewtopic.php?f=108&t=12530&p=84214&hilit=defaultValue+dynamic+list#p84214

That should get you in the right direction...

Posted on
Tue Jan 15, 2019 2:04 pm
kw123 offline
User avatar
Posts: 8360
Joined: May 12, 2013
Location: Dallas, TX

default values in devices.xml

Sh t.

Tooo much logic.

have > 90 devices and several reference to that list for each device and they are all different. Then it would be easier to just include the static list.

Karl
Ps that would add ~90*5*30 lines ~14000 lines to devices.xml

Sent from my iPhone using Tapatalk
Last edited by kw123 on Tue Jan 15, 2019 2:10 pm, edited 1 time in total.

Posted on
Tue Jan 15, 2019 2:09 pm
FlyingDiver offline
User avatar
Posts: 7210
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: default values in devices.xml

kw123 wrote:
Sh t.

Tooo much logic have > 90 devices and several reference to that list for each device and they are all different. Then it would be easier to just include the static list.


My logic only sets the default if nothing has already been selected.

Code: Select all
    def getDeviceConfigUiValues(self, pluginProps, typeId, devId):
        valuesDict = indigo.Dict(pluginProps)
        errorsDict = indigo.Dict()

        if len(valuesDict) == 0:
            if typeId == "foo":
                valuesDict["bar"] = "123"

        return (valuesDict, errorsDict)


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

Posted on
Tue Jan 15, 2019 2:51 pm
kw123 offline
User avatar
Posts: 8360
Joined: May 12, 2013
Location: Dallas, TX

Re: default values in devices.xml

Yes, times 90 times 5 of your example





Sent from my iPhone using Tapatalk

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests