How to access a list in pluginProps?

Posted on
Wed Jul 29, 2015 5:19 pm
zurich offline
Posts: 103
Joined: Aug 11, 2014

How to access a list in pluginProps?

Greetings:

I am trying to store a list in dev.pluginProps using this code:

Code: Select all
indigo.romIDrevList.append(idRev)
      
sensorList = indigo.romIDrevList
      
localPropsCopy = dev.pluginProps
localPropsCopy.update({'sensorList' : sensorList})
dev.replacePluginPropsOnServer(localPropsCopy)



I see in the database the list is stored like this:

Code: Select all
<sensorList type="vector">
   <Item type="string">28F4F525030000D1</Item>
   <Item type="string">282C102603000034</Item>
   <Item type="string">28622A260300006B</Item>
</sensorList>


I want to access this list with:

Code: Select all
sensorList = dev.pluginProps["sensorList"]


butI get error;

<type 'exceptions.TypeError'>: Expecting an object of type list; got an object of type List instead


Can you help me with dis please?


Kind regards,

Z

Posted on
Thu Jul 30, 2015 9:33 am
jay (support) offline
Site Admin
User avatar
Posts: 18261
Joined: Mar 19, 2008
Location: Austin, Texas

Re: How to access a list in pluginProps?

A couple of things. First, this line:

Code: Select all
indigo.romIDrevList.append(idRev)


is just an invitation for confusion, since the indigo library module is supplied by Indigo and adding arbitrary stuff to it (even though Python allows it) is going to get confusing. That's a practice to avoid unless there's a really good reason to add arbitrary properties to library modules/objects.

Next, to store a list in the plugin props, it has to be an indigo.List object, not a standard Python list object. So:

Code: Select all
sensorList = indigo.List() # this makes an Indigo last
sensorList.append(idRev) # add stuff to the list
localPropsCopy = dev.pluginProps
localPropsCopy["sensorList"] = sensorList
dev.replacePluginPropsOnServer(localPropsCopy)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jul 30, 2015 10:22 am
zurich offline
Posts: 103
Joined: Aug 11, 2014

Re: How to access a list in pluginProps?

Greetings,

Thanks to you Jay for kind assistance, sorry to trouble you again.

I follow your instructions and now the sensorList in the Database as;

Code: Select all
<sensorList type="string">28F4F525030000D1, 282C102603000034, 28622A260300006B</sensorList>

Now that I have the sensorList I want to use in in a Dynamic List as follows;

Code: Select all
def getSlave(self, filter = "indigo.sensor", typeId = 0, valuesDict = None, targetId = 0):
      self.errorLog("running method getSlave")
      
      for dev in indigo.devices.itervalues():
         if (dev.deviceTypeId == "server"):
            sensorList = dev.pluginProps["sensorList"]
            return sensorList

but I get this error;

linkUSB Error Error in plugin execution GetUiDynamicList:

Traceback (most recent call last):
<type 'exceptions.TypeError'>: Expecting an object of type list; got an object of type unicode instead


If I use this :
Code: Select all
sensorList = sensorList.replace(" ","").split(",")

the method works OK with no error but I think to maybe this is not correct way?

Kind regards,

Z

Posted on
Thu Jul 30, 2015 10:30 am
FlyingDiver offline
User avatar
Posts: 7265
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: How to access a list in pluginProps?

Post the code you're using to create your Sensor List. What you have is not a list object, it's a string with three values separated by commas and spaces. Not the same thing at all.

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

Posted on
Thu Jul 30, 2015 2:28 pm
zurich offline
Posts: 103
Joined: Aug 11, 2014

Re: How to access a list in pluginProps?

Greetings,

Thanks to you for assitance to me.

Sorry I made mistake in posting, the code to create list below makes this in the Database;

Code: Select all
<sensorList type="vector">
   <Item type="string">28F4F525030000D1</Item>
   <Item type="string">282C102603000034</Item>
   <Item type="string">28622A260300006B</Item>
</sensorList>

Code to make list;

Code: Select all
sensorList = indigo.List() # this makes an Indigo last

sensorList.append(idRev) # add stuff to the list

localPropsCopy = dev.pluginProps
localPropsCopy["sensorList"] = sensorList
dev.replacePluginPropsOnServer(localPropsCopy)

When I try to access the list for a Dynamic List I get this error:

myplug Error sensorList is sensorList : (list)
Item : 28F4F525030000D1 (string)
Item : 282C102603000034 (string)
Item : 28622A260300006B (string)
myplug Error Error in plugin execution GetUiDynamicList:

Traceback (most recent call last):
<type 'exceptions.TypeError'>: Expecting an object of type list; got an object of type List instead


This is method for Dynamic List;

def getSlave(self, filter = "indigo.sensor", typeId = 0, valuesDict = None, targetId = 0):
Code: Select all
      self.errorLog("running method getSlave")
     
      for dev in indigo.devices.itervalues():
         if (dev.deviceTypeId == "server"):
            sensorList = dev.pluginProps["sensorList"]
            return sensorList


Either I am building the list incorrectly or I am retrieving the list incorrectly. Much appreciation if you can show me my incorrections.

Kind regards,

Z

Posted on
Thu Jul 30, 2015 3:33 pm
FlyingDiver offline
User avatar
Posts: 7265
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: How to access a list in pluginProps?

I had a much longer reply, but the website crashed and ate it...

I think your list is built correctly, as the XML you posted looks fine.

I think it's the code accessing the list that's got the issue. Post all of it, including the XML that's specifying the device filter.

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

Posted on
Thu Jul 30, 2015 3:44 pm
zurich offline
Posts: 103
Joined: Aug 11, 2014

Re: How to access a list in pluginProps?

Greetings,

Thanks to you once more for assistance!

The XML in Device.xml is;

Code: Select all
<Field id = "slaveSelect" type = "menu">
   <Label>slave:</Label>
   <List class = "self" filter = "" method = "getSlave" dynamicReload = "true"/>
</Field>

The method called in the above is :

Code: Select all
def getSlave(self, filter = "indigo.sensor", typeId = 0, valuesDict = None, targetId = 0):
   self.errorLog("running method getSlave")
      
   for dev in indigo.devices.itervalues():
      if (dev.deviceTypeId == "server"):
         sensorList = dev.pluginProps["sensorList"]
         return sensorList


Kind regards,

Z

Posted on
Thu Jul 30, 2015 4:22 pm
FlyingDiver offline
User avatar
Posts: 7265
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: How to access a list in pluginProps?

Try something more like this:

Code: Select all
   def getSlave(self, filter=None, valuesDict=None, typeId=0):
      retList =[]
      for dev in indigo.devices.iter():
         if (dev.pluginId.lower().find("XXXXXX") > -1) and (dev.deviceTypeId == "server"):
            retList.append(dev.pluginProps["sensorList"])
      return retList


You'll need to put a unique string from your pluginID where I have the XXXXs. You could be matching on a deviceTypeID of "server" from some other plugin entirely.

joe

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

Posted on
Thu Jul 30, 2015 9:07 pm
zurich offline
Posts: 103
Joined: Aug 11, 2014

Re: How to access a list in pluginProps?

Greetings,

Looking at your last post I think using indigo.List() is not best way for my application. I was of understanding using indigoList() was better but I do not see in what way in my case.

Instead I use;
Code: Select all
sensorList = ','.join(sensorList)

to make the list a comma separated string then my method below reconstructs the list and the method woks fine and provides my Dynamic list;
Code: Select all
def getSlave(self, filter = "indigo.sensor", typeId = 0, valuesDict = None, targetId = 0):
      self.errorLog("running method getSlave")      
      for dev in indigo.devices.itervalues():
         if (dev.deviceTypeId == "server"):
            sensorList = dev.pluginProps["sensorList"]
            sensorList = sensorList.split(",")
            return sensorList

I don't see how using indigo.List would be any better?

Kind regards,

Z

Posted on
Fri Jul 31, 2015 2:35 am
kw123 offline
User avatar
Posts: 8392
Joined: May 12, 2013
Location: Dallas, TX

Re: How to access a list in pluginProps?

May I suggest to check out json dumps/ loads writing to and reading from indigo props. You then don't need to think about formatting / reconstructing things umlauts etc.

SensorList = json. loads(dev.pluginProps["sensor list"])
And naturally the other way around.

This works for any object dict list and with special characters


Sent from my iPhone using Tapatalk

Posted on
Fri Jul 31, 2015 12:00 pm
jay (support) offline
Site Admin
User avatar
Posts: 18261
Joined: Mar 19, 2008
Location: Austin, Texas

Re: How to access a list in pluginProps?

zurich wrote:
Greetings,

Looking at your last post I think using indigo.List() is not best way for my application. I was of understanding using indigoList() was better but I do not see in what way in my case.

Instead I use;
Code: Select all
sensorList = ','.join(sensorList)

to make the list a comma separated string then my method below reconstructs the list and the method woks fine and provides my Dynamic list;
Code: Select all
def getSlave(self, filter = "indigo.sensor", typeId = 0, valuesDict = None, targetId = 0):
      self.errorLog("running method getSlave")      
      for dev in indigo.devices.itervalues():
         if (dev.deviceTypeId == "server"):
            sensorList = dev.pluginProps["sensorList"]
            sensorList = sensorList.split(",")
            return sensorList

I don't see how using indigo.List would be any better?

Kind regards,

Z


The issue is that a dynamic UI list needs 2 elements for each menu option: a readable name and a value. So you have to convert your indigo list into a list of tuples, even if the visible name is the same as the value (the ID). See the Dynamic Lists section of the docs for details.

You have to use indigo.List() because it's stored in the plugin props, which requires indigo lists vs Python lists.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests

cron