https://github.com/trychlos/pyjpi
A Python library to interface with JPI-capable Android devices
https://github.com/trychlos/pyjpi
Last synced: 4 months ago
JSON representation
A Python library to interface with JPI-capable Android devices
- Host: GitHub
- URL: https://github.com/trychlos/pyjpi
- Owner: trychlos
- License: mit
- Created: 2025-09-17T09:43:10.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2025-09-18T13:21:43.000Z (9 months ago)
- Last Synced: 2025-09-18T13:30:12.478Z (9 months ago)
- Language: Python
- Size: 32.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# pyJPI - An asynchronous Python module to interact with Android devices running JPI
[](https://github.com/trychlos/pyjpi)
[](https://github.com/trychlos/pyjpi/release)
[](https://github.com/trychlos/pyjpi)
[](https://pypi.org/project/pyJPI/)
[](https://app.codecov.io/gh/trychlos/pyjpi)
[](https://github.com/trychlos/pyjpi)
## Overview
`pyJPI` is an asynchronous Python library designed to programmatically interact with Android devices running JPI.
This library is a key component for a core integration with [Home Assistant](https://www.home-assistant.io).
More details on the integration can be found on the [JPI](https://www.home-assistant.io/integrations/jpi/) page.
## Features
- Asynchronous operations are built with ``aiohttp` for non-blocking I/O, which is perfect for integrations and background tasks.
- API: `battInfo`
- API: `get`
- API: `getDeviceName`
## Installation
You can install `pyJPI` from PyPI using pip:
```Bash
pip install pyjpi
```
## Usage
Here is a more detailed example of how to use the library to connect, fetch status, and perform an action on an Android device running JPI.
```Python
import aiohttp
from pyjpi import jpiInit
async def main():
"""Main function to demonstrate library usage."""
# Create an aiohttp session with SSL verification disabled.
# Be cautious with this setting; it's useful for self-signed certificates
# but not recommended for production environments without proper validation.
session = aiohttp.ClientSession( connector=aiohttp.TCPConnector( verify_ssl=False ))
# Get a handle on the pyJPI library.
handle = await jpiInit( session )
# Have an URL somewhere.
url = "http://myhost.example.com:8080"
# Then just has to call the library functions.
try:
res = await handle.get( url )
# returns a dict { resp: ClientResponse, text: str } or False
res = await handle.getDeviceName( url )
# returns the device name as set by the manufacturer (a single string) or False
res = await handle.battInfo( url )
# returns a dict { level: integer, charging: bool, power: bool }
if __name__ == "__main__":
main()
```
## Available functions
- `async jpiInit( session: aiohttp.ClientSession ) -> JPILibrary`:
Initializes the library.
Returns a handle on it.
## Available classes
- `JPILibrary`:
The class which manages the devices accesses.
## Available `JPILibrary` methods
- `async get( url: str) -> dict`:
Runs a HTTP GET method on the specified URL.
Returns a dict with:
```Python
resp: the `aiohttp.ClientResponse`
text: the resp.text() content
```
- `async getDeviceName( url: str) -> str`:
Runs a HTTP GET method on f"{url}?action=getDeviceName" url.
Returns a string which contains the device name as set by the manufacturer.
- `async battInfo( url: str) -> dict`:
Runs a HTTP GET method on on f"{url}?action=battInfo" url.
Returns a dict with:
```Python
level: an integer with the current battery level in %
charging: a boolean which says if the battery is currently charging
power: a boolean which says if the power is on on the device.
```
## Contributing
We welcome contributions as well as additional codeowners to `pyjpi`.
## Issues & help
In case of support or error, please report your issue request to our [Issues tracker](https://github.com/trychlos/pyjpi/issues).