Fix GATT TemplateSerivce annotations

This commit is contained in:
Josh Wu
2026-01-15 12:06:05 +08:00
parent 2cad743f8c
commit 84a6453dda
6 changed files with 16 additions and 24 deletions

View File

@@ -1383,10 +1383,7 @@ class Peer:
def create_service_proxy(
self, proxy_class: type[_PROXY_CLASS]
) -> _PROXY_CLASS | None:
if proxy := proxy_class.from_client(self.gatt_client):
return cast(_PROXY_CLASS, proxy)
return None
return proxy_class.from_client(self.gatt_client)
async def discover_service_and_create_proxy(
self, proxy_class: type[_PROXY_CLASS]

View File

@@ -29,7 +29,7 @@ import functools
import logging
import struct
from collections.abc import Iterable, Sequence
from typing import TypeVar
from typing import ClassVar, TypeVar
from bumble.att import Attribute, AttributeValue, AttributeValueV2
from bumble.colors import color
@@ -403,7 +403,7 @@ class TemplateService(Service):
to expose their UUID as a class property
'''
UUID: UUID
UUID: ClassVar[UUID]
def __init__(
self,

View File

@@ -34,11 +34,14 @@ from datetime import datetime
from typing import (
TYPE_CHECKING,
Any,
ClassVar,
Generic,
TypeVar,
overload,
)
from typing_extensions import Self
from bumble import att, core, l2cap, utils
from bumble.colors import color
from bumble.core import UUID, InvalidStateError
@@ -249,10 +252,10 @@ class ProfileServiceProxy:
Base class for profile-specific service proxies
'''
SERVICE_CLASS: type[TemplateService]
SERVICE_CLASS: ClassVar[type[TemplateService]]
@classmethod
def from_client(cls, client: Client) -> ProfileServiceProxy | None:
def from_client(cls, client: Client) -> Self | None:
return ServiceProxy.from_client(cls, client, cls.SERVICE_CLASS.UUID)

View File

@@ -18,10 +18,7 @@
# -----------------------------------------------------------------------------
from collections.abc import Callable
from bumble import device
from bumble import gatt
from bumble import gatt_adapters
from bumble import gatt_client
from bumble import device, gatt, gatt_adapters, gatt_client
# -----------------------------------------------------------------------------

View File

@@ -19,19 +19,14 @@
from __future__ import annotations
import dataclasses
from typing import Any
from typing_extensions import Self
from collections.abc import Sequence, Callable
import struct
import enum
import struct
from collections.abc import Callable, Sequence
from typing import Any
from bumble import core
from bumble import device
from bumble import utils
from bumble import att
from bumble import gatt
from bumble import gatt_adapters
from bumble import gatt_client
from typing_extensions import Self
from bumble import att, core, device, gatt, gatt_adapters, gatt_client, utils
# -----------------------------------------------------------------------------

View File

@@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from collections.abc import Sequence
import asyncio
import itertools
from collections.abc import Sequence
import pytest