Skip to main content

Official Python stack for xAAL protocol

Project description

xaal.lib is the official Python stack to develop home-automation devices and gateways with the xAAL protocol. For a full description of the protocol check out http://recherche.imt-atlantique.fr/xaal/

Dependencies

xaal.lib depends on :
  • cbor2

  • pysodium

  • configobj

  • coloredlogs

  • decorator

  • tabulate

  • aioconsole

Install

Please refer to the official full documentation to install the lib in a virtualenv

Usage

The main goal of xaal.lib is to provide an API to easily develop devices & gateways. xaal.lib.Engine send / receive / parse to|from xAAL Bus.

To receive / parse / display incoming xAAL messages, you can simply try something like this:

from xaal.lib import Engine, Message

def display(msg: Message):
    print(msg)

eng = Engine()
eng.subscribe(display)
eng.disable_msg_filter()
eng.run()

The Engine will call the display function every time it receive a xAAL message.

Let’s take a look at a simple lamp device :

from xaal.lib import Device,Engine,tools

# create and configure the lamp device, with a random address
dev = Device("lamp.basic", tools.get_random_uuid())
dev.product_id = 'Dummy Lamp'
dev.url  = 'http://www.acme.org'
dev.info = 'My fake lamp'

# add an xAAL attribute 'light'
light = dev.new_attribute('light')

# declare two device methods ON & OFF
def on():
    light.value = True

def off():
    light.value = False

dev.add_method('turn_on',on)
dev.add_method('turn_off',off)

# last step, create an engine and register the lamp
eng = Engine()
eng.add_device(dev)
eng.run()

To avoid to rewrite the same code for each device, you can use the xaal.schemas package. This package provides a set of predefined devices, you can use them as a template to create your own device.

from xaal.schemas import devices
from xaal.lib import Engine

# create and configure the lamp device
dev = devices.lamp()

# last step, create an engine and register the lamp
eng = Engine()
eng.add_device(dev)
eng.run()

FAQ

The core engine run forever so how can I use it in webserver, GUI or to develop device with IO. The whole API is absolutely not thread safe, so don’t use threads unless you exactly know what’s going on. Anyways, you have several options to fix this issue:

  • You can use you own loop and periodically call eng.loop() for example, you can do something like this:

    while 1:
        do_some_stuff()
        eng.loop()
  • You can use a engine timer, to perform some stuff.

    def read_io():
        pass
    
    # call the read_io function every 10 sec
    eng.add_timer(read_io,10)
    eng.run()
  • Use the AsyncEngine. Python version > 3.8 provides async programming with asyncio package. AsyncEngine use the same API as Engine, but it is a asynchronous engine. You can use coroutines in device methods, timers functions and callbacks. It provides additionals features like the on_start and on_stop callbacks.

  • Use an alternate coroutine lib, you can use gevent or greenlet for example. Look at apps/rest for a simple greenlet example.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xaal_lib-0.7.18.tar.gz (30.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xaal_lib-0.7.18-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

Details for the file xaal_lib-0.7.18.tar.gz.

File metadata

  • Download URL: xaal_lib-0.7.18.tar.gz
  • Upload date:
  • Size: 30.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for xaal_lib-0.7.18.tar.gz
Algorithm Hash digest
SHA256 e02bc7530e70c4de349d3eca9970aff9db983b600c62a9c75ca5d11a032fdd04
MD5 d74b91899a925bb72ab7ff564d6ffa0d
BLAKE2b-256 b7755c30b771da18e59615233adb6fb200364a089fcc0d8a3aa26c88fa732414

See more details on using hashes here.

File details

Details for the file xaal_lib-0.7.18-py3-none-any.whl.

File metadata

  • Download URL: xaal_lib-0.7.18-py3-none-any.whl
  • Upload date:
  • Size: 31.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for xaal_lib-0.7.18-py3-none-any.whl
Algorithm Hash digest
SHA256 aef1b23d2afc8663097f8f6b09c8b2d6b033ceaed7b377f56bdeec2a66e0e690
MD5 3449ba06fdae59f95e8a22034afbcffa
BLAKE2b-256 93f68c005711df411cc8e803f796162a0efdac8223650ab898f6628a0b7965cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page