|
| 1 | +import types |
| 2 | +from typing import Any, Generic, Literal, TypedDict, TypeVar, overload |
| 3 | +from typing_extensions import Self |
| 4 | + |
| 5 | +from gi.repository import Gio |
| 6 | + |
| 7 | +from .bus_names import OwnMixin, WatchMixin |
| 8 | +from .generic import bound_signal |
| 9 | +from .proxy import CompositeObject, ProxyMixin |
| 10 | +from .publication import PublicationMixin |
| 11 | +from .registration import RegistrationMixin |
| 12 | +from .request_name import RequestNameMixin |
| 13 | +from .subscription import SubscriptionMixin |
| 14 | + |
| 15 | +_T = TypeVar("_T") |
| 16 | +_ST = TypeVar("_ST") # signal type |
| 17 | + |
| 18 | +def bus_get(type: Gio.BusType) -> Bus[object]: ... |
| 19 | +def connect(address: str) -> Bus[object]: ... |
| 20 | + |
| 21 | +class DBusOrgFreedesktopDBus: |
| 22 | + # Incomplete interface to org.freedesktop.DBus |
| 23 | + Features: list[str] |
| 24 | + |
| 25 | + def GetId(self) -> str: ... |
| 26 | + |
| 27 | +class DBusOrgFreedesktopPolicyKit1Authority: |
| 28 | + # Incomplete interface to org.freedesktop.PolicyKit1.Authority |
| 29 | + BackendFeatures: int # flags |
| 30 | + BackendName: str |
| 31 | + BackendVersion: str |
| 32 | + |
| 33 | +class OrgBluezAdapter1Dict(TypedDict, total=False): |
| 34 | + Address: str |
| 35 | + AddressType: Literal["public", "random"] |
| 36 | + Alias: str |
| 37 | + Class: int |
| 38 | + Connectable: bool |
| 39 | + Discoverable: bool |
| 40 | + DiscoverableTimeout: int |
| 41 | + Discovering: bool |
| 42 | + Manufacturer: int |
| 43 | + Modalias: str |
| 44 | + Name: str |
| 45 | + Pairable: bool |
| 46 | + PairableTimeout: int |
| 47 | + Powered: bool |
| 48 | + Roles: list[str] |
| 49 | + UUIDs: list[str] |
| 50 | + Version: int |
| 51 | + |
| 52 | +class OrgBluezDevice1Dict(TypedDict, total=False): |
| 53 | + Adapter: str |
| 54 | + Address: str |
| 55 | + AddressType: Literal["public", "random"] |
| 56 | + Alias: str |
| 57 | + Appearance: int |
| 58 | + Blocked: bool |
| 59 | + Bonded: bool |
| 60 | + Class: int |
| 61 | + Connected: bool |
| 62 | + Icon: str |
| 63 | + LegacyPairing: bool |
| 64 | + Modalias: str |
| 65 | + Name: str |
| 66 | + Paired: bool |
| 67 | + ServicesResolved: bool |
| 68 | + Trusted: bool |
| 69 | + UUIDs: list[str] |
| 70 | + WakeAllowed: bool |
| 71 | + |
| 72 | +class OrgBluezInput1Dict(TypedDict, total=False): |
| 73 | + ReconnectMode: str |
| 74 | + |
| 75 | +class OrgBluezMedia1Dict(TypedDict, total=False): |
| 76 | + SupportedUUIDs: list[str] |
| 77 | + |
| 78 | +class OrgBluezMediaControl1Dict(TypedDict, total=False): |
| 79 | + Connected: bool |
| 80 | + |
| 81 | +class OrgBluezBattery1Dict(TypedDict, total=False): |
| 82 | + Percentage: int |
| 83 | + Source: str |
| 84 | + |
| 85 | +class OrgBluezGattService1Dict(TypedDict, total=False): |
| 86 | + Device: str |
| 87 | + Handle: int |
| 88 | + Includes: list[str] |
| 89 | + Primary: bool |
| 90 | + UUID: str |
| 91 | + |
| 92 | +class OrgBluezGattCharacteristic1Dict(TypedDict, total=False): |
| 93 | + Flags: list[str] |
| 94 | + Handle: int |
| 95 | + MTU: int |
| 96 | + Service: str |
| 97 | + UUID: str |
| 98 | + Value: list[int] |
| 99 | + |
| 100 | +class OrgBluezGattDescriptor1Dict(TypedDict, total=False): |
| 101 | + Characteristic: str |
| 102 | + Handle: int |
| 103 | + UUID: str |
| 104 | + Value: list[int] |
| 105 | + |
| 106 | +class OrgBluezLEAdvertisingManager1Dict(TypedDict, total=False): |
| 107 | + ActiveInstances: int |
| 108 | + SupportedCapabilities: dict[str, int] # e.g. MaxTxPower: 7 |
| 109 | + SupportedFeatures: list[str] |
| 110 | + SupportedIncludes: list[str] |
| 111 | + SupportedInstances: int |
| 112 | + SupportedSecondaryChannels: list[str] |
| 113 | + |
| 114 | +# This is for keys under /org/bluez/hci0/* |
| 115 | +OrgBluezDict = TypedDict( |
| 116 | + "OrgBluezDict", |
| 117 | + { |
| 118 | + "org.bluez.Adapter1": OrgBluezAdapter1Dict, |
| 119 | + "org.bluez.Battery1": OrgBluezBattery1Dict, |
| 120 | + "org.bluez.Device1": OrgBluezDevice1Dict, |
| 121 | + "org.bluez.GattCharacteristic1": OrgBluezGattCharacteristic1Dict, |
| 122 | + "org.bluez.GattDescriptor1": OrgBluezGattDescriptor1Dict, |
| 123 | + "org.bluez.GattService1": OrgBluezGattService1Dict, |
| 124 | + "org.bluez.Input1": OrgBluezInput1Dict, |
| 125 | + "org.bluez.LEAdvertisingManager1": OrgBluezLEAdvertisingManager1Dict, |
| 126 | + "org.bluez.Media1": OrgBluezMedia1Dict, |
| 127 | + "org.bluez.MediaControl1": OrgBluezMediaControl1Dict, |
| 128 | + # The following always appear as empty dictionaries on my system. |
| 129 | + "org.bluez.AgentManager1": dict[str, Any], |
| 130 | + "org.bluez.BatteryProviderManager1": dict[str, Any], |
| 131 | + "org.bluez.NetworkServer1": dict[str, Any], |
| 132 | + "org.bluez.ProfileManager1": dict[str, Any], |
| 133 | + "org.freedesktop.DBus.Introspectable": dict[str, Any], |
| 134 | + "org.freedesktop.DBus.Properties": dict[str, Any], |
| 135 | + }, |
| 136 | + total=False, |
| 137 | +) |
| 138 | + |
| 139 | +class OrgFreedesktopDBusObjectManager: |
| 140 | + @staticmethod |
| 141 | + def GetManagedObjects() -> dict[str, OrgBluezDict]: ... |
| 142 | + |
| 143 | +class OrgBluez(CompositeObject[_T]): |
| 144 | + def __getitem__( # type: ignore[override] |
| 145 | + self, key: Literal["org.freedesktop.DBus.ObjectManager"] |
| 146 | + ) -> OrgFreedesktopDBusObjectManager: ... |
| 147 | + |
| 148 | +class OrgFreedesktopNotifications(CompositeObject[_T], Generic[_T, _ST]): |
| 149 | + Inhibited: bool |
| 150 | + ActivationToken: bound_signal[_ST] |
| 151 | + ActionInvoked: bound_signal[_ST] |
| 152 | + NotificationClosed: bound_signal[_ST] |
| 153 | + |
| 154 | + def CloseNotification(self, id: int) -> None: ... |
| 155 | + def GetCapabilities(self) -> list[str]: ... # We could use Literal[] here but KDE also returns its own not in the spec. |
| 156 | + def GetServerInformation(self) -> tuple[str, str, str, str]: ... |
| 157 | + def Inhibit(self, name: str, reason: str, hints: dict[str, bool | bytes | int | str]) -> int | None: ... |
| 158 | + def Notify( |
| 159 | + self, |
| 160 | + app_name: str, |
| 161 | + replaces_id: int, |
| 162 | + app_icon: str, |
| 163 | + summary: str, |
| 164 | + body: str, |
| 165 | + actions: list[str], |
| 166 | + hints: dict[str, bool | bytes | int | str], # See https://specifications.freedesktop.org/notification-spec/1.3/hints.html |
| 167 | + expire_timeout: int, |
| 168 | + ) -> int: ... |
| 169 | + def UnInhibit(self, key: int) -> int | None: ... |
| 170 | + |
| 171 | +class Bus(ProxyMixin[_T], RequestNameMixin[_T], OwnMixin, WatchMixin, SubscriptionMixin, RegistrationMixin[_T], PublicationMixin): |
| 172 | + Type: type[Gio.BusType] = ... |
| 173 | + autoclose: bool |
| 174 | + con: Gio.DBusConnection |
| 175 | + |
| 176 | + def __init__(self, gio_con: Gio.DBusConnection) -> None: ... |
| 177 | + def __enter__(self) -> Self: ... |
| 178 | + def __exit__( |
| 179 | + self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: types.TracebackType | None |
| 180 | + ) -> None: ... |
| 181 | + @property |
| 182 | + def dbus(self) -> DBusOrgFreedesktopDBus: ... |
| 183 | + @property |
| 184 | + def polkit_authority(self) -> DBusOrgFreedesktopPolicyKit1Authority: ... |
| 185 | + @overload # type: ignore[override] |
| 186 | + def get(self, bus_name: Literal[".Notifications"]) -> OrgFreedesktopNotifications[_T, object]: ... |
| 187 | + @overload |
| 188 | + def get(self, bus_name: Literal["org.freedesktop.Notifications"]) -> OrgFreedesktopNotifications[_T, object]: ... |
| 189 | + @overload |
| 190 | + def get(self, bus_name: Literal["org.bluez"], object_path: Literal["/"]) -> OrgBluez[_T]: ... |
| 191 | + @overload |
| 192 | + def get(self, bus_name: str, object_path: str) -> Any: ... |
| 193 | + |
| 194 | +def SystemBus() -> Bus[object]: ... |
| 195 | +def SessionBus() -> Bus[object]: ... |
0 commit comments