Metadata-Version: 2.4
Name: busylib
Version: 0.0.2
Summary: Python library for Busy Bar API
Author-email: Valerii Lisai <v.lisai@flipperdevices.com>
Project-URL: Homepage, https://github.com/busy-app/busylib
Project-URL: Repository, https://github.com/busy-app/busylib
Project-URL: Documentation, https://busylib.readthedocs.io
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests==2.32.4
Provides-Extra: dev
Requires-Dist: pytest==8.4.1; extra == "dev"
Requires-Dist: requests-mock==1.12.1; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Dynamic: license-file

# busylib

A simple and intuitive Python client for interacting with the Busy Bar API. This library allows you to programmatically control the device's display, audio, and assets.

## Features

-   Easy-to-use API for all major device functions.
-   Upload and manage assets for your applications.
-   Control the display by drawing text and images.
-   Play and stop audio files.
-   Built-in validation for device IP addresses.

## Installation

You can install `busylib` directly from PyPI:

```bash
pip install busylib
```

## Usage

First, import and initialize the `BusyBar` client with the IP address of your device.

```python
from busylib import BusyBar

try:
    # Default IP is 10.0.4.20, but you can specify your own
    bb = BusyBar("192.168.1.100")
except ValueError as e:
    print(f"Error: {e}")

# Now you can use the bb object to interact with your device.
```

## API Examples

Here are some examples of how to use the library to control your Busy Bar device.

### Uploading an Asset

You can upload files (like images or sounds) to be used by your application on the device.

```python
# Upload a file from bytes
with open("path/to/your/image.png", "rb") as f:
    file_bytes = f.read()
    bb.upload_asset(
        app_id="my-app",
        file_name="logo.png",
        file=file_bytes
    )

# Or upload directly from a file-like object
with open("path/to/your/sound.mp3", "rb") as f:
    bb.upload_asset(
        app_id="my-app",
        file_name="notification.mp3",
        file=f
    )
```

### Drawing on the Display

Draw text or images on the device's screen. The `draw_display` method accepts a list of elements to render.

```python
elements = [
    {
        "type": "text",
        "value": "Hello, World!",
        "x": 10,
        "y": 20,
        "color": "#FFFFFF" # Optional
    },
    {
        "type": "image",
        "path": "logo.png", # Must be uploaded first
        "x": 50,
        "y": 40
    }
]

bb.draw_display(app_id="my-app", elements=elements)
```

### Clearing the Display

To clear everything from the screen:

```python
bb.clear_display()
```

### Playing a Sound

Play an audio file that you have already uploaded.

```python
bb.play_sound(app_id="my-app", path="notification.mp3")
```

### Stopping a Sound

To stop any audio that is currently playing:

```python
bb.stop_sound()
```

### Deleting All Assets for an App

This will remove all files associated with a specific `app_id`.

```python
bb.delete_assets(app_id="my-app")
```

## Development

To set up a development environment, clone the repository and install the package in editable mode with test dependencies:

```bash
git clone https://github.com/busy-app/busylib
cd busylib
python3 -m venv .venv
source .venv/bin/activate
make install-dev
```

To run the tests:

```bash
make test
```
