Skip to main content

xaal.lib

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

  • 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.

Metadata

Release files for xaal.lib 0.9.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xaal.lib 0.9.2
File Size Uploaded
xaal_lib-0.9.2.tar.gz 34.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xaal.lib 0.9.2
File Interpreter ABI Platform
xaal_lib-0.9.2-py3-none-any.whl Python 3 none any Details

Total release size: 69.3 kB

Release files / xaal_lib-0.9.2.tar.gz

Download URL xaal_lib-0.9.2.tar.gz
Size 34.5 kB
Tags Source
SHA-256 checksum
How to use checksums
cf85d7ed8e5eec37d28a3d0ad86ff007eff3032c437c3d4fd45f29a37c9ac77c
BLAKE2b-256 checksum
How to use checksums
4452caf6bdd550e2fd25348c1ec0a943b8cf1b7890920430be2e2baec0308d1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / xaal_lib-0.9.2-py3-none-any.whl

Download URL xaal_lib-0.9.2-py3-none-any.whl
Size 34.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe3ae814e82b54b50261e1b30ddc7b581d6f09c0255d080232e18e08d701c1e3
BLAKE2b-256 checksum
How to use checksums
a4736d052e7ec8d460d1c355b10bbeb7f07fb010385e91deac626c9bf80498c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

This release

0.9.2 This release

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.21

2 release files

0.7.19

2 release files

0.7.18

2 release files

0.7.17

2 release files

0.7.14

2 release files

0.7.13

2 release files

0.7.12

2 release files

0.7.11

2 release files

0.7.10

2 release files

0.7.9

2 release files

0.7.8

2 release files

0.7.7

2 release files

0.7.6

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page