From: Arturo Buzarra <arturo.buzarra@digi.com>
Date: Mon, 21 Jan 2019 12:15:06 +0100
Subject: [PATCH] port test-discovery to python3

Signed-off-by: Isaac Hermida <isaac.hermida@digi.com>
Signed-off-by: Arturo Buzarra <arturo.buzarra@digi.com>
---
 test/test-discovery | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/test/test-discovery b/test/test-discovery
index cea77683d..852611c86 100755
--- a/test/test-discovery
+++ b/test/test-discovery
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3

 from __future__ import absolute_import, print_function, unicode_literals

@@ -18,9 +18,9 @@ def print_compact(address, properties):
 	name = ""
 	address = "<unknown>"

-	for key, value in properties.iteritems():
+	for key, value in properties.items():
 		if type(value) is dbus.String:
-			value = unicode(value).encode('ascii', 'replace')
+			value = str(value)
 		if (key == "Name"):
 			name = value
 		elif (key == "Address"):
@@ -41,7 +41,7 @@ def print_normal(address, properties):
 	for key in properties.keys():
 		value = properties[key]
 		if type(value) is dbus.String:
-			value = unicode(value).encode('ascii', 'replace')
+			value = str(value)
 		if (key == "Class"):
 			print("    %s = 0x%06x" % (key, value))
 		else:
@@ -61,6 +61,8 @@ def skip_dev(old_dev, new_dev):
 	return False

 def interfaces_added(path, interfaces):
+	if "org.bluez.Device1" not in interfaces.keys():
+		return
 	properties = interfaces["org.bluez.Device1"]
 	if not properties:
 		return
@@ -70,7 +72,7 @@ def interfaces_added(path, interfaces):

 		if compact and skip_dev(dev, properties):
 			return
-		devices[path] = dict(devices[path].items() + properties.items())
+		devices[path] = dict(list(devices[path].items()) + list(properties.items()))
 	else:
 		devices[path] = properties

@@ -93,7 +95,7 @@ def properties_changed(interface, changed, invalidated, path):

 		if compact and skip_dev(dev, changed):
 			return
-		devices[path] = dict(devices[path].items() + changed.items())
+		devices[path] = dict(list(devices[path].items()) + list(changed.items()))
 	else:
 		devices[path] = changed

@@ -152,7 +154,7 @@ if __name__ == '__main__':
 	om = dbus.Interface(bus.get_object("org.bluez", "/"),
 				"org.freedesktop.DBus.ObjectManager")
 	objects = om.GetManagedObjects()
-	for path, interfaces in objects.iteritems():
+	for path, interfaces in objects.items():
 		if "org.bluez.Device1" in interfaces:
 			devices[path] = interfaces["org.bluez.Device1"]
 
