Change generic Gatt Enums to IntEnums
Modify the GattEnum.py enums such that
integer based enums are treated as ints.
This removes the need to add ".value"
when using an int enum.
Bug: b/30372898
Change-Id: I4db69a8fc2d8526c36a3975638d159a030d7fccd
(cherry picked from commit 026bf63a61b0146d67b31b92e8f2c1c437b4072b)
diff --git a/acts/framework/acts/test_utils/bt/GattConnectedBaseTest.py b/acts/framework/acts/test_utils/bt/GattConnectedBaseTest.py
index ef269d4..0507543 100644
--- a/acts/framework/acts/test_utils/bt/GattConnectedBaseTest.py
+++ b/acts/framework/acts/test_utils/bt/GattConnectedBaseTest.py
@@ -63,7 +63,7 @@
orchestrate_gatt_connection(self.cen_ad, self.per_ad))
self.per_ad.droid.bleStopBleAdvertising(self.adv_callback)
- self.mtu = MtuSize.MIN.value
+ self.mtu = MtuSize.MIN
if self.cen_ad.droid.gattClientDiscoverServices(self.bluetooth_gatt):
event = self._client_wait(GattEvent.GATT_SERV_DISC)
@@ -122,8 +122,8 @@
characteristic_input = [
{
'uuid': self.WRITABLE_CHAR_UUID,
- 'property': GattCharacteristic.PROPERTY_WRITE.value |
- GattCharacteristic.PROPERTY_WRITE_NO_RESPONSE.value,
+ 'property': GattCharacteristic.PROPERTY_WRITE.value
+ | GattCharacteristic.PROPERTY_WRITE_NO_RESPONSE.value,
'permission': GattCharacteristic.PERMISSION_WRITE.value
},
{
@@ -133,31 +133,29 @@
},
{
'uuid': self.NOTIFIABLE_CHAR_UUID,
- 'property': GattCharacteristic.PROPERTY_NOTIFY.value |
- GattCharacteristic.PROPERTY_INDICATE.value,
+ 'property': GattCharacteristic.PROPERTY_NOTIFY.value
+ | GattCharacteristic.PROPERTY_INDICATE.value,
'permission': GattCharacteristic.PERMISSION_READ.value
},
]
descriptor_input = [
{
'uuid': self.WRITABLE_DESC_UUID,
- 'property': GattDescriptor.PERMISSION_READ.value |
- GattCharacteristic.PERMISSION_WRITE.value,
- },
- {
+ 'property': GattDescriptor.PERMISSION_READ.value
+ | GattCharacteristic.PERMISSION_WRITE.value,
+ }, {
'uuid': self.READABLE_DESC_UUID,
- 'property': GattDescriptor.PERMISSION_READ.value |
- GattDescriptor.PERMISSION_WRITE.value,
- },
- {
+ 'property': GattDescriptor.PERMISSION_READ.value
+ | GattDescriptor.PERMISSION_WRITE.value,
+ }, {
'uuid': self.CCC_DESC_UUID,
- 'property': GattDescriptor.PERMISSION_READ.value |
- GattDescriptor.PERMISSION_WRITE.value,
+ 'property': GattDescriptor.PERMISSION_READ.value
+ | GattDescriptor.PERMISSION_WRITE.value,
}
]
characteristic_list = setup_gatt_characteristics(droid,
characteristic_input)
- self.notifiable_char_index = characteristic_list[2];
+ self.notifiable_char_index = characteristic_list[2]
descriptor_list = setup_gatt_descriptors(droid, descriptor_input)
return characteristic_list, descriptor_list
@@ -201,7 +199,7 @@
self.per_ad.droid.gattServerCharacteristicAddDescriptor(
characteristic_list[2], descriptor_list[2])
gatt_service3 = self.per_ad.droid.gattServerCreateService(
- self.TEST_SERVICE_UUID, GattService.SERVICE_TYPE_PRIMARY.value)
+ self.TEST_SERVICE_UUID, GattService.SERVICE_TYPE_PRIMARY)
for characteristic in characteristic_list:
self.per_ad.droid.gattServerAddCharacteristicToService(
gatt_service3, characteristic)
diff --git a/acts/framework/acts/test_utils/bt/GattEnum.py b/acts/framework/acts/test_utils/bt/GattEnum.py
index b08f82b..6b8facc 100644
--- a/acts/framework/acts/test_utils/bt/GattEnum.py
+++ b/acts/framework/acts/test_utils/bt/GattEnum.py
@@ -85,7 +85,7 @@
"err": GattCbErr.CHAR_CHANGE_ERR.value}
-class GattConnectionState(Enum):
+class GattConnectionState(IntEnum):
STATE_DISCONNECTED = 0
STATE_CONNECTING = 1
STATE_CONNECTED = 2
@@ -136,18 +136,18 @@
PERMISSION_WRITE_SIGNED_MITM = 0x100
-class GattService(Enum):
+class GattService(IntEnum):
SERVICE_TYPE_PRIMARY = 0
SERVICE_TYPE_SECONDARY = 1
-class GattConnectionPriority(Enum):
+class GattConnectionPriority(IntEnum):
CONNECTION_PRIORITY_BALANCED = 0
CONNECTION_PRIORITY_HIGH = 1
CONNECTION_PRIORITY_LOW_POWER = 2
-class MtuSize(Enum):
+class MtuSize(IntEnum):
MIN = 23
MAX = 217
diff --git a/acts/framework/acts/test_utils/bt/bt_gatt_utils.py b/acts/framework/acts/test_utils/bt/bt_gatt_utils.py
index 86d55a2..4c11221 100644
--- a/acts/framework/acts/test_utils/bt/bt_gatt_utils.py
+++ b/acts/framework/acts/test_utils/bt/bt_gatt_utils.py
@@ -25,7 +25,6 @@
from acts.test_utils.bt.GattEnum import GattDescriptor
from acts.test_utils.bt.GattEnum import GattService
from acts.test_utils.bt.GattEnum import GattTransport
-from acts.test_utils.bt.GattEnum import GattConnectionPriority
import pprint
from queue import Empty
from contextlib import suppress
@@ -52,7 +51,7 @@
log.error(GattCbErr.GATT_CONN_CHANGE_ERR.value.format(expected_event))
test_result = False
return test_result, bluetooth_gatt, gatt_callback
- if event['data']['State'] != GattConnectionState.STATE_CONNECTED.value:
+ if event['data']['State'] != GattConnectionState.STATE_CONNECTED:
log.info("Could not establish a connection to peripheral. Event "
"Details:".format(pprint.pformat(event)))
test_result = False
@@ -67,7 +66,7 @@
except Empty:
log.error(GattCbErr.GATT_CONN_CHANGE_ERR.value.format(expected_event))
return False
- if event['data']['State'] != GattConnectionState.STATE_DISCONNECTED.value:
+ if event['data']['State'] != GattConnectionState.STATE_DISCONNECTED:
return False
return True
@@ -205,13 +204,13 @@
descriptor_list[1])
gattService = per_droid.gattServerCreateService(
"00000000-0000-1000-8000-00805f9b34fb",
- GattService.SERVICE_TYPE_PRIMARY.value)
+ GattService.SERVICE_TYPE_PRIMARY)
gattService2 = per_droid.gattServerCreateService(
"FFFFFFFF-0000-1000-8000-00805f9b34fb",
- GattService.SERVICE_TYPE_PRIMARY.value)
+ GattService.SERVICE_TYPE_PRIMARY)
gattService3 = per_droid.gattServerCreateService(
"3846D7A0-69C8-11E4-BA00-0002A5D5C51B",
- GattService.SERVICE_TYPE_PRIMARY.value)
+ GattService.SERVICE_TYPE_PRIMARY)
for characteristic in characteristic_list:
per_droid.gattServerAddCharacteristicToService(gattService,
characteristic)
diff --git a/acts/tests/google/ble/gatt/GattConnectTest.py b/acts/tests/google/ble/gatt/GattConnectTest.py
index b4f48b6..d25f411 100644
--- a/acts/tests/google/ble/gatt/GattConnectTest.py
+++ b/acts/tests/google/ble/gatt/GattConnectTest.py
@@ -29,7 +29,6 @@
from acts.test_utils.bt.GattEnum import MtuSize
from acts.test_utils.bt.GattEnum import GattCbErr
from acts.test_utils.bt.GattEnum import GattCbStrings
-from acts.test_utils.bt.GattEnum import GattConnectionPriority
from acts.test_utils.bt.GattEnum import GattTransport
from acts.test_utils.bt.bt_gatt_utils import GattTestUtilsError
from acts.test_utils.bt.bt_gatt_utils import disconnect_gatt_connection
@@ -153,13 +152,13 @@
characteristic_list[2], descriptor_list[1])
gatt_service = self.per_ad.droid.gattServerCreateService(
"00000000-0000-1000-8000-00805f9b34fb",
- GattService.SERVICE_TYPE_PRIMARY.value)
+ GattService.SERVICE_TYPE_PRIMARY)
gatt_service2 = self.per_ad.droid.gattServerCreateService(
"FFFFFFFF-0000-1000-8000-00805f9b34fb",
- GattService.SERVICE_TYPE_PRIMARY.value)
+ GattService.SERVICE_TYPE_PRIMARY)
gatt_service3 = self.per_ad.droid.gattServerCreateService(
"3846D7A0-69C8-11E4-BA00-0002A5D5C51B",
- GattService.SERVICE_TYPE_PRIMARY.value)
+ GattService.SERVICE_TYPE_PRIMARY)
for characteristic in characteristic_list:
self.per_ad.droid.gattServerAddCharacteristicToService(
gatt_service, characteristic)
@@ -262,7 +261,8 @@
return False
autoconnect = True
bluetooth_gatt = self.cen_ad.droid.gattClientConnectGatt(
- gatt_callback, mac_address, autoconnect, GattTransport.TRANSPORT_AUTO)
+ gatt_callback, mac_address, autoconnect,
+ GattTransport.TRANSPORT_AUTO)
expected_event = GattCbStrings.GATT_CONN_CHANGE.value.format(
gatt_callback)
try:
@@ -309,7 +309,7 @@
except GattTestUtilsError:
return False
self.adv_instances.append(adv_callback)
- expected_mtu = MtuSize.MIN.value
+ expected_mtu = MtuSize.MIN
self.cen_ad.droid.gattClientRequestMtu(bluetooth_gatt, expected_mtu)
expected_event = GattCbStrings.MTU_CHANGED.value.format(gatt_callback)
try:
@@ -362,7 +362,7 @@
except GattTestUtilsError:
return False
self.adv_instances.append(adv_callback)
- expected_mtu = MtuSize.MAX.value
+ expected_mtu = MtuSize.MAX
self.cen_ad.droid.gattClientRequestMtu(bluetooth_gatt, expected_mtu)
expected_event = GattCbStrings.MTU_CHANGED.value.format(gatt_callback)
try:
@@ -416,8 +416,7 @@
except GattTestUtilsError:
return False
self.adv_instances.append(adv_callback)
- self.cen_ad.droid.gattClientRequestMtu(bluetooth_gatt,
- MtuSize.MIN.value - 1)
+ self.cen_ad.droid.gattClientRequestMtu(bluetooth_gatt, MtuSize.MIN - 1)
expected_event = GattCbStrings.MTU_CHANGED.value.format(gatt_callback)
try:
self.cen_ad.ed.pop_event(expected_event, self.default_timeout)
@@ -738,7 +737,7 @@
else:
self.log.info("Failed to discover services.")
return False
- test_value = [1,2,3,4,5,6,7]
+ test_value = [1, 2, 3, 4, 5, 6, 7]
services_count = self.cen_ad.droid.gattClientGetDiscoveredServicesCount(
discovered_services_index)
for i in range(services_count):
diff --git a/acts/tests/google/ble/gatt/GattNotifyTest.py b/acts/tests/google/ble/gatt/GattNotifyTest.py
index df99e45..58b0180 100644
--- a/acts/tests/google/ble/gatt/GattNotifyTest.py
+++ b/acts/tests/google/ble/gatt/GattNotifyTest.py
@@ -24,7 +24,6 @@
from acts.test_utils.bt.GattEnum import MtuSize
from acts.test_utils.bt.GattEnum import GattEvent
from acts.test_utils.bt.GattEnum import GattCbStrings
-from acts.test_utils.bt.GattEnum import GattConnectionPriority
from math import ceil
diff --git a/acts/tests/google/ble/gatt/GattReadTest.py b/acts/tests/google/ble/gatt/GattReadTest.py
index 3e48e9d..70f6b6e 100644
--- a/acts/tests/google/ble/gatt/GattReadTest.py
+++ b/acts/tests/google/ble/gatt/GattReadTest.py
@@ -24,7 +24,6 @@
from acts.test_utils.bt.GattEnum import MtuSize
from acts.test_utils.bt.GattEnum import GattEvent
from acts.test_utils.bt.GattEnum import GattCbStrings
-from acts.test_utils.bt.GattEnum import GattConnectionPriority
from math import ceil
diff --git a/acts/tests/google/ble/gatt/GattWriteTest.py b/acts/tests/google/ble/gatt/GattWriteTest.py
index 6d70ada..f56f23b 100644
--- a/acts/tests/google/ble/gatt/GattWriteTest.py
+++ b/acts/tests/google/ble/gatt/GattWriteTest.py
@@ -270,7 +270,7 @@
"""
self.cen_ad.droid.gattClientRequestConnectionPriority(
self.bluetooth_gatt,
- GattConnectionPriority.CONNECTION_PRIORITY_HIGH.value)
+ GattConnectionPriority.CONNECTION_PRIORITY_HIGH)
bt_device_id = 0
@@ -344,7 +344,7 @@
"""
self.cen_ad.droid.gattClientRequestConnectionPriority(
self.bluetooth_gatt,
- GattConnectionPriority.CONNECTION_PRIORITY_HIGH.value)
+ GattConnectionPriority.CONNECTION_PRIORITY_HIGH)
for i in range(100):
@@ -412,7 +412,7 @@
"""
self.cen_ad.droid.gattClientRequestConnectionPriority(
self.bluetooth_gatt,
- GattConnectionPriority.CONNECTION_PRIORITY_HIGH.value)
+ GattConnectionPriority.CONNECTION_PRIORITY_HIGH)
bt_device_id = 0
diff --git a/acts/tests/google/bt/gatt/GattOverBrEdrTest.py b/acts/tests/google/bt/gatt/GattOverBrEdrTest.py
index 811c8b6..a6351fd 100644
--- a/acts/tests/google/bt/gatt/GattOverBrEdrTest.py
+++ b/acts/tests/google/bt/gatt/GattOverBrEdrTest.py
@@ -151,13 +151,13 @@
characteristic_list[2], descriptor_list[1])
gatt_service = self.per_ad.droid.gattServerCreateService(
"00000000-0000-1000-8000-00805f9b34fb",
- GattService.SERVICE_TYPE_PRIMARY.value)
+ GattService.SERVICE_TYPE_PRIMARY)
gatt_service2 = self.per_ad.droid.gattServerCreateService(
"FFFFFFFF-0000-1000-8000-00805f9b34fb",
- GattService.SERVICE_TYPE_PRIMARY.value)
+ GattService.SERVICE_TYPE_PRIMARY)
gatt_service3 = self.per_ad.droid.gattServerCreateService(
"3846D7A0-69C8-11E4-BA00-0002A5D5C51B",
- GattService.SERVICE_TYPE_PRIMARY.value)
+ GattService.SERVICE_TYPE_PRIMARY)
for characteristic in characteristic_list:
self.per_ad.droid.gattServerAddCharacteristicToService(
gatt_service, characteristic)
@@ -597,7 +597,7 @@
test_uuid, GattCharacteristic.PROPERTY_WRITE.value,
GattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM.value)
gatt_service = self.per_ad.droid.gattServerCreateService(
- service_uuid, GattService.SERVICE_TYPE_PRIMARY.value)
+ service_uuid, GattService.SERVICE_TYPE_PRIMARY)
self.per_ad.droid.gattServerAddCharacteristicToService(gatt_service,
characteristic)
self.per_ad.droid.gattServerAddService(gatt_server, gatt_service)