Add coverage for GATT services from dict

This commit is contained in:
J. Nick Koston 2023-11-27 08:28:43 -06:00
parent 60e193e4df
commit 3a1c98d433
No known key found for this signature in database
1 changed files with 39 additions and 0 deletions

View File

@ -3,10 +3,14 @@ from __future__ import annotations
from dataclasses import dataclass, field
import pytest
from google.protobuf import message
from aioesphomeapi.api_pb2 import (
AlarmControlPanelStateResponse,
BinarySensorStateResponse,
BluetoothGATTCharacteristic,
BluetoothGATTDescriptor,
BluetoothGATTService,
ClimateStateResponse,
CoverStateResponse,
DeviceInfoResponse,
@ -49,6 +53,9 @@ from aioesphomeapi.model import (
APIVersion,
BinarySensorInfo,
BinarySensorState,
)
from aioesphomeapi.model import BluetoothGATTService as BluetoothGATTServiceModel
from aioesphomeapi.model import (
BluetoothProxyFeature,
ButtonInfo,
CameraInfo,
@ -497,3 +504,35 @@ def test_supported_color_modes_compat(
)
assert info.supported_color_modes_compat(APIVersion(1, 5)) == capability
assert info.supported_color_modes_compat(APIVersion(1, 9)) == [42]
@pytest.mark.asyncio
async def test_bluetooth_gatt_services_from_dict() -> None:
"""Test bluetooth_gatt_get_services success case."""
service1: message.Message = BluetoothGATTService(
uuid=[1, 1],
handle=1,
characteristics=[
{
"uuid": [1, 2],
"handle": 2,
"properties": 1,
"descriptors": [
{"uuid": [1, 3], "handle": 3},
],
},
],
)
service = BluetoothGATTServiceModel.from_pb(service1)
assert service == BluetoothGATTServiceModel(
uuid=[1, 1],
handle=1,
characteristics=[
BluetoothGATTCharacteristic(
uuid=[1, 2],
handle=2,
properties=1,
descriptors=[BluetoothGATTDescriptor(uuid=[1, 3], handle=3)],
)
],
)