2

I am on Ubuntu 16.04 and using Python Dbus. I want to return a list of dictionaries over DBus to my client but seem to only be able to return an array of strings. If I changed my dbus signature decorator to 'as{v}', I get an exception: "ValueError: Corrupt type signature". How can I return a list of dictionaries over DBus?

   @dbus.service.method("com.example.service.BtScanList", in_signature='', out_signature='as')
   def getScanList(self):
      btMsg("Starting BT Scan List...")
      # Populate device lists ( returns dictionary --> { 'mac_address' : xxx , 'name' : xxx }
      self.discoveredDevs = self.getScannedDevices()
      returnList = []
      for dev in self.discoveredDevs:
          returnList.append(dev["name"])
      return returnList

EDIT: This also does NOT work:

   @dbus.service.method("com.example.service.BtScanList", in_signature='', out_signature='a{sv}')
   def getScanList(self):
      btMsg("Starting BT Scan List...")
      # Populate device lists ( returns dictionary --> { 'mac_address' : xxx , 'name' : xxx }
      self.discoveredDevs = self.getScannedDevices()
      returnList = dbus.Array()
      for dev in self.discoveredDevs:
          btMsg(dev)
          returnList.append(dbus.Dictionary(dev, signature='sv'))
      return returnList
Philip Withnall
  • 5,293
  • 14
  • 28
PhilBot
  • 748
  • 18
  • 85
  • 173

1 Answers1

1

I figured it out, answer is here:

   @dbus.service.method("com.example.service.BtPairedList", in_signature='', out_signature='aa{ss}')
   def getPairedList(self):
      btMsg("Starting BT Paired List...")
      # Populate device lists ( returns dictionary --> { 'mac_address' : xxx , 'name' : xxx }
      self.pairedDevs = self.getPairedDevices()
      returnList = dbus.Array()
      for dev in self.pairedDevs:
          btMsg(dev)
          returnList.append(dbus.Dictionary(dev, signature='sv'))
      return returnList
PhilBot
  • 748
  • 18
  • 85
  • 173