Mock API

Blue Dot also contains a useful mock API for simulating Blue Dot and bluetooth comms. This is useful for testing and allows for prototyping without having to use a Blue Dot client.

MockBlueDot

class bluedot.mock.MockBlueDot(device='hci0', port=1, auto_start_server=True, power_up_device=False, print_messages=True)[source]

MockBlueDot inherits from BlueDot but overrides _create_server(), to create a MockBluetoothServer which can be used for testing and debugging.

launch_mock_app()[source]

Launches a mock Blue Dot app.

The mock app reacts to mouse clicks and movement and calls the mock blue dot methods to simulates presses.

This is useful for testing, allowing you to interact with Blue Dot without having to script mock functions.

The mock app uses pygame which will need to be installed.

mock_blue_dot_moved(x, y)[source]

Simulates the Blue Dot being moved.

Parameters:
  • x (int) – The x position where the mock Blue Dot was moved too
  • y (int) – The y position where the mock Blue Dot was moved too
mock_blue_dot_pressed(x, y)[source]

Simulates the Blue Dot being pressed.

Parameters:
  • x (int) – The x position where the mock Blue Dot was pressed
  • y (int) – The y position where the mock Blue Dot was pressed
mock_blue_dot_released(x, y)[source]

Simulates the Blue Dot being released.

Parameters:
  • x (int) – The x position where the mock Blue Dot was released
  • y (int) – The y position where the mock Blue Dot was released
mock_client_connected()[source]

Simulates a client connecting to the Blue Dot.

Parameters:client_address (string) – The mock client mac address, defaults to ‘11:11:11:11:11:11’
mock_client_disconnected()[source]

Simulates a client disconnecting from the Blue Dot.

MockBluetoothServer

class bluedot.mock.MockBluetoothServer(data_received_callback, auto_start=True, device='mock0', port=1, encoding='utf-8', power_up_device=False, when_client_connects=None, when_client_disconnects=None)[source]

MockBluetoothServer inherits from BluetoothServer but overrides __init__, start() , stop() and send_raw() to create a MockBluetoothServer which can be used for testing and debugging.

mock_client_connected(mock_client=None)[source]

Simulates a client connected to the BluetoothServer.

Parameters:mock_client (MockBluetoothClient) – The mock client to interact with, defaults to None. If None, client address is set to ‘99:99:99:99:99:99’
mock_client_disconnected()[source]

Simulates a client disconnecting from the BluetoothServer.

mock_client_sending_data(data)[source]

Simulates a client sending data to the BluetoothServer.

start()[source]

Starts the Bluetooth server if its not already running. The server needs to be started before connections can be made.

stop()[source]

Stops the Bluetooth server if its running.

MockBluetoothClient

class bluedot.mock.MockBluetoothClient(server, data_received_callback, port=1, device='mock1', encoding='utf-8', power_up_device=False, auto_connect=True)[source]

MockBluetoothClient inherits from BluetoothClient but overrides __init__, connect() and send_raw() to create a MockBluetoothServer which can be used for testing and debugging.

Note - the server parameter should be an instance of MockBluetoothServer.

connect()[source]

Connect to a Bluetooth server.

disconnect()[source]

Disconnect from a Bluetooth server.

mock_server_sending_data(data)[source]

Simulates a server sending data to the BluetoothClient.