Skip to content

bluetooth_emulation

CentralState

Bases: Enum

Indicates the various states of Central.

Source code in zendriver/cdp/bluetooth_emulation.py
class CentralState(enum.Enum):
    """
    Indicates the various states of Central.
    """

    ABSENT = "absent"
    POWERED_OFF = "powered-off"
    POWERED_ON = "powered-on"

    def to_json(self) -> str:
        return self.value

    @classmethod
    def from_json(cls, json: str) -> CentralState:
        return cls(json)

ABSENT = 'absent' class-attribute instance-attribute

POWERED_OFF = 'powered-off' class-attribute instance-attribute

POWERED_ON = 'powered-on' class-attribute instance-attribute

from_json(json) classmethod

Source code in zendriver/cdp/bluetooth_emulation.py
@classmethod
def from_json(cls, json: str) -> CentralState:
    return cls(json)

to_json()

Source code in zendriver/cdp/bluetooth_emulation.py
def to_json(self) -> str:
    return self.value

ManufacturerData dataclass

Stores the manufacturer data

Source code in zendriver/cdp/bluetooth_emulation.py
@dataclass
class ManufacturerData:
    """
    Stores the manufacturer data
    """

    #: Company identifier
    #: https://bitbucket.org/bluetooth-SIG/public/src/main/assigned_numbers/company_identifiers/company_identifiers.yaml
    #: https://usb.org/developers
    key: int

    #: Manufacturer-specific data (Encoded as a base64 string when passed over JSON)
    data: str

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["key"] = self.key
        json["data"] = self.data
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> ManufacturerData:
        return cls(
            key=int(json["key"]),
            data=str(json["data"]),
        )

data: str instance-attribute

key: int instance-attribute

__init__(key, data)

from_json(json) classmethod

Source code in zendriver/cdp/bluetooth_emulation.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> ManufacturerData:
    return cls(
        key=int(json["key"]),
        data=str(json["data"]),
    )

to_json()

Source code in zendriver/cdp/bluetooth_emulation.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["key"] = self.key
    json["data"] = self.data
    return json

ScanEntry dataclass

Stores the advertisement packet information that is sent by a Bluetooth device.

Source code in zendriver/cdp/bluetooth_emulation.py
@dataclass
class ScanEntry:
    """
    Stores the advertisement packet information that is sent by a Bluetooth device.
    """

    device_address: str

    rssi: int

    scan_record: ScanRecord

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["deviceAddress"] = self.device_address
        json["rssi"] = self.rssi
        json["scanRecord"] = self.scan_record.to_json()
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> ScanEntry:
        return cls(
            device_address=str(json["deviceAddress"]),
            rssi=int(json["rssi"]),
            scan_record=ScanRecord.from_json(json["scanRecord"]),
        )

device_address: str instance-attribute

rssi: int instance-attribute

scan_record: ScanRecord instance-attribute

__init__(device_address, rssi, scan_record)

from_json(json) classmethod

Source code in zendriver/cdp/bluetooth_emulation.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> ScanEntry:
    return cls(
        device_address=str(json["deviceAddress"]),
        rssi=int(json["rssi"]),
        scan_record=ScanRecord.from_json(json["scanRecord"]),
    )

to_json()

Source code in zendriver/cdp/bluetooth_emulation.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["deviceAddress"] = self.device_address
    json["rssi"] = self.rssi
    json["scanRecord"] = self.scan_record.to_json()
    return json

ScanRecord dataclass

Stores the byte data of the advertisement packet sent by a Bluetooth device.

Source code in zendriver/cdp/bluetooth_emulation.py
@dataclass
class ScanRecord:
    """
    Stores the byte data of the advertisement packet sent by a Bluetooth device.
    """

    name: typing.Optional[str] = None

    uuids: typing.Optional[typing.List[str]] = None

    #: Stores the external appearance description of the device.
    appearance: typing.Optional[int] = None

    #: Stores the transmission power of a broadcasting device.
    tx_power: typing.Optional[int] = None

    #: Key is the company identifier and the value is an array of bytes of
    #: manufacturer specific data.
    manufacturer_data: typing.Optional[typing.List[ManufacturerData]] = None

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        if self.name is not None:
            json["name"] = self.name
        if self.uuids is not None:
            json["uuids"] = [i for i in self.uuids]
        if self.appearance is not None:
            json["appearance"] = self.appearance
        if self.tx_power is not None:
            json["txPower"] = self.tx_power
        if self.manufacturer_data is not None:
            json["manufacturerData"] = [i.to_json() for i in self.manufacturer_data]
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> ScanRecord:
        return cls(
            name=str(json["name"]) if json.get("name", None) is not None else None,
            uuids=[str(i) for i in json["uuids"]]
            if json.get("uuids", None) is not None
            else None,
            appearance=int(json["appearance"])
            if json.get("appearance", None) is not None
            else None,
            tx_power=int(json["txPower"])
            if json.get("txPower", None) is not None
            else None,
            manufacturer_data=[
                ManufacturerData.from_json(i) for i in json["manufacturerData"]
            ]
            if json.get("manufacturerData", None) is not None
            else None,
        )

appearance: typing.Optional[int] = None class-attribute instance-attribute

manufacturer_data: typing.Optional[typing.List[ManufacturerData]] = None class-attribute instance-attribute

name: typing.Optional[str] = None class-attribute instance-attribute

tx_power: typing.Optional[int] = None class-attribute instance-attribute

uuids: typing.Optional[typing.List[str]] = None class-attribute instance-attribute

__init__(name=None, uuids=None, appearance=None, tx_power=None, manufacturer_data=None)

from_json(json) classmethod

Source code in zendriver/cdp/bluetooth_emulation.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> ScanRecord:
    return cls(
        name=str(json["name"]) if json.get("name", None) is not None else None,
        uuids=[str(i) for i in json["uuids"]]
        if json.get("uuids", None) is not None
        else None,
        appearance=int(json["appearance"])
        if json.get("appearance", None) is not None
        else None,
        tx_power=int(json["txPower"])
        if json.get("txPower", None) is not None
        else None,
        manufacturer_data=[
            ManufacturerData.from_json(i) for i in json["manufacturerData"]
        ]
        if json.get("manufacturerData", None) is not None
        else None,
    )

to_json()

Source code in zendriver/cdp/bluetooth_emulation.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    if self.name is not None:
        json["name"] = self.name
    if self.uuids is not None:
        json["uuids"] = [i for i in self.uuids]
    if self.appearance is not None:
        json["appearance"] = self.appearance
    if self.tx_power is not None:
        json["txPower"] = self.tx_power
    if self.manufacturer_data is not None:
        json["manufacturerData"] = [i.to_json() for i in self.manufacturer_data]
    return json

disable()

Disable the BluetoothEmulation domain.

Source code in zendriver/cdp/bluetooth_emulation.py
def disable() -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Disable the BluetoothEmulation domain.
    """
    cmd_dict: T_JSON_DICT = {
        "method": "BluetoothEmulation.disable",
    }
    json = yield cmd_dict

enable(state)

Enable the BluetoothEmulation domain.

Parameters:

Name Type Description Default
state CentralState

State of the simulated central.

required
Source code in zendriver/cdp/bluetooth_emulation.py
def enable(state: CentralState) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Enable the BluetoothEmulation domain.

    :param state: State of the simulated central.
    """
    params: T_JSON_DICT = dict()
    params["state"] = state.to_json()
    cmd_dict: T_JSON_DICT = {
        "method": "BluetoothEmulation.enable",
        "params": params,
    }
    json = yield cmd_dict

simulate_advertisement(entry)

Simulates an advertisement packet described in entry being received by the central.

Parameters:

Name Type Description Default
entry ScanEntry
required
Source code in zendriver/cdp/bluetooth_emulation.py
def simulate_advertisement(
    entry: ScanEntry,
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Simulates an advertisement packet described in ``entry`` being received by
    the central.

    :param entry:
    """
    params: T_JSON_DICT = dict()
    params["entry"] = entry.to_json()
    cmd_dict: T_JSON_DICT = {
        "method": "BluetoothEmulation.simulateAdvertisement",
        "params": params,
    }
    json = yield cmd_dict

simulate_preconnected_peripheral(address, name, manufacturer_data, known_service_uuids)

Simulates a peripheral with address, name and knownServiceUuids that has already been connected to the system.

Parameters:

Name Type Description Default
address str
required
name str
required
manufacturer_data List[ManufacturerData]
required
known_service_uuids List[str]
required
Source code in zendriver/cdp/bluetooth_emulation.py
def simulate_preconnected_peripheral(
    address: str,
    name: str,
    manufacturer_data: typing.List[ManufacturerData],
    known_service_uuids: typing.List[str],
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Simulates a peripheral with ``address``, ``name`` and ``knownServiceUuids``
    that has already been connected to the system.

    :param address:
    :param name:
    :param manufacturer_data:
    :param known_service_uuids:
    """
    params: T_JSON_DICT = dict()
    params["address"] = address
    params["name"] = name
    params["manufacturerData"] = [i.to_json() for i in manufacturer_data]
    params["knownServiceUuids"] = [i for i in known_service_uuids]
    cmd_dict: T_JSON_DICT = {
        "method": "BluetoothEmulation.simulatePreconnectedPeripheral",
        "params": params,
    }
    json = yield cmd_dict