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.
More details on the integration can be found on the JPI page.
- 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
You can install pyJPI from PyPI using pip:
pip install pyjpiHere 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.
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()async jpiInit( session: aiohttp.ClientSession ) -> JPILibrary:
Initializes the library.
Returns a handle on it.
JPILibrary:
The class which manages the devices accesses.
async get( url: str) -> dict:
Runs a HTTP GET method on the specified URL.
Returns a dict with:
resp: the `aiohttp.ClientResponse`
text: the resp.text() contentasync 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:
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.We welcome contributions as well as additional codeowners to pyjpi.
In case of support or error, please report your issue request to our Issues tracker.