XSense Python Module

raw JSON →
0.0.16 verified Fri May 01 auth: no python

Python module to control XSense air purifiers and sensors. Current version 0.0.16, released irregularly with small feature updates.

pip install python-xsense
error RuntimeError: Task <Task pending ...> got Future <Future pending ...> attached to a different loop
cause Creating the XSenseStation outside an async context or mixing event loops (e.g., Jupyter, multi-threading).
fix
Ensure XSenseStation is created inside the same event loop as asyncio.run() or use nest_asyncio in Jupyter.
error AttributeError: 'XSenseStation' object has no attribute 'devices'
cause Calling station.devices before station.update_devices() has been awaited.
fix
Always await station.update_devices() before accessing station.devices.
gotcha Library uses asyncio; all methods are async and must be awaited. Calling them without await will return coroutine objects, not raise errors.
fix Always use async/await or asyncio.run().
breaking The 'XSenseDevice' class changed in 0.0.14; attributes like 'name' now return property objects instead of strings if not properly awaited. Version 0.0.16 still has this risk.
fix Ensure station.update_devices() completes before accessing device attributes.
deprecated The 'get_devices()' method on station is deprecated in favor of 'update_devices()'.
fix Use station.update_devices() and then station.devices list.

Login, fetch devices, and print their names.

import asyncio
from xsense import XSenseDevice, XSenseStation

async def main():
    station = XSenseStation()
    await station.login('username', 'password')
    await station.update_devices()
    for device in station.devices:
        print(device.name, device.type)

asyncio.run(main())