xaal.lib


Namexaal.lib JSON
Version 0.7.11 PyPI version JSON
download
home_pageNone
SummaryOfficial Python stack for xAAL protocol
upload_time2025-01-27 14:42:30
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseGPL License
keywords xaal home-automation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
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
 * tabulate
 * aioconsole


Install
~~~~~~~
Please refer to the official `full documentation to install the lib in a virtualenv
<https://gitlab.imt-atlantique.fr/xaal/code/python/-/blob/main/README.rst>`_


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:

.. code-block:: python

   from xaal.lib import Engine

   def display(msg):
       print(msg)

   eng = Engine()
   eng.subscribe(display)
   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 :

.. code-block:: python

   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 <https://gitlab.imt-atlantique.fr/xaal/code/python/-/tree/main/libs/schemas>`_.
This package provides a set of predefined devices, you can use them as a template to create your own device.

.. code-block:: python

   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:

  .. code:: python

     while 1:
         do_some_stuff()
         eng.loop()

* You can use a engine timer, to perform some stuff.

  .. code:: python

     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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "xaal.lib",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "xaal, home-automation",
    "author": null,
    "author_email": "Jerome Kerdreux <Jerome.Kerdreux@imt-atlantique.fr>",
    "download_url": "https://files.pythonhosted.org/packages/08/ec/1fe351667f4ffa0725ee90cd60fa77f880ce088ed1595a9023b797ec6332/xaal_lib-0.7.11.tar.gz",
    "platform": null,
    "description": "\nxaal.lib\n========\n**xaal.lib** is the official Python stack to develop home-automation devices and gateways\nwith the xAAL protocol. For a full description of the protocol check out\nhttp://recherche.imt-atlantique.fr/xaal/\n\n\nDependencies\n~~~~~~~~~~~~\nxaal.lib depends on :\n * cbor2\n * pysodium\n * configobj\n * coloredlogs\n * decorator\n * tabulate\n * aioconsole\n\n\nInstall\n~~~~~~~\nPlease refer to the official `full documentation to install the lib in a virtualenv\n<https://gitlab.imt-atlantique.fr/xaal/code/python/-/blob/main/README.rst>`_\n\n\nUsage\n~~~~~\nThe main goal of xaal.lib is to provide an API to easily develop devices & gateways.\n**xaal.lib.Engine send / receive / parse to|from xAAL Bus**.\n\n\nTo receive / parse / display incoming xAAL messages, you can simply try something like\nthis:\n\n.. code-block:: python\n\n   from xaal.lib import Engine\n\n   def display(msg):\n       print(msg)\n\n   eng = Engine()\n   eng.subscribe(display)\n   eng.run()\n\nThe Engine will call the display function every time it receive a xAAL message.\n\nLet's take a look at a simple lamp device :\n\n.. code-block:: python\n\n   from xaal.lib import Device,Engine,tools\n\n   # create and configure the lamp device, with a random address\n   dev = Device(\"lamp.basic\", tools.get_random_uuid())\n   dev.product_id = 'Dummy Lamp'\n   dev.url  = 'http://www.acme.org'\n   dev.info = 'My fake lamp'\n\n   # add an xAAL attribute 'light'\n   light = dev.new_attribute('light')\n\n   # declare two device methods ON & OFF\n   def on():\n       light.value = True\n\n   def off():\n       light.value = False\n\n   dev.add_method('turn_on',on)\n   dev.add_method('turn_off',off)\n\n   # last step, create an engine and register the lamp\n   eng = Engine()\n   eng.add_device(dev)\n   eng.run()\n\n\nTo avoid to rewrite the same code for each device, you can use the `xaal.schemas package <https://gitlab.imt-atlantique.fr/xaal/code/python/-/tree/main/libs/schemas>`_.\nThis package provides a set of predefined devices, you can use them as a template to create your own device.\n\n.. code-block:: python\n\n   from xaal.schemas import devices\n   from xaal.lib import Engine\n\n   # create and configure the lamp device\n   dev = devices.lamp()\n\n   # last step, create an engine and register the lamp\n   eng = Engine()\n   eng.add_device(dev)\n   eng.run()\n\n\nFAQ\n~~~\nThe core engine run forever so how can I use it in webserver, GUI or to develop device\nwith IO. The whole API is absolutely not thread safe, so **don't use threads** unless you\nexactly know what's going on. Anyways, you have several options to fix this issue:\n\n* You can use you own loop and periodically call *eng.loop()*\n  for example, you can do something like this:\n\n  .. code:: python\n\n     while 1:\n         do_some_stuff()\n         eng.loop()\n\n* You can use a engine timer, to perform some stuff.\n\n  .. code:: python\n\n     def read_io():\n         pass\n\n     # call the read_io function every 10 sec\n     eng.add_timer(read_io,10)\n     eng.run()\n\n* Use the **AsyncEngine**. Python version > 3.8 provides async programming with **asyncio** package.\n  *AsyncEngine* use the same API as *Engine*, but it is a **asynchronous** engine. You can use\n  *coroutines* in device methods, timers functions and callbacks. It provides additionals features\n  like the *on_start* and *on_stop* callbacks.\n\n* Use an alternate coroutine lib, you can use **gevent** or **greenlet** for example. Look at\n  apps/rest for a simple greenlet example.\n",
    "bugtrack_url": null,
    "license": "GPL License",
    "summary": "Official Python stack for xAAL protocol",
    "version": "0.7.11",
    "project_urls": {
        "Documentation": "https://redmine.imt-atlantique.fr/projects/xaal/repository/xaal/entry/code/Python/branches/0.7/libs/lib/README.rst",
        "Homepage": "https://recherche.imt-atlantique.fr/xaal/",
        "Source": "https://redmine.imt-atlantique.fr/projects/xaal/repository/xaal/show/code/Python/branches/0.7/libs/lib"
    },
    "split_keywords": [
        "xaal",
        " home-automation"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1002c5429c2689662fb7229f8b11b601133a8c2bf6c9ff935f84ee3306a83a15",
                "md5": "9b12d8a37761d29b98c911b0f0de5437",
                "sha256": "51e25be6e6db9fe69516675a890b9f3cb13fc98eacb96da0b6c0efb1ba1bb78a"
            },
            "downloads": -1,
            "filename": "xaal.lib-0.7.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9b12d8a37761d29b98c911b0f0de5437",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 31618,
            "upload_time": "2025-01-27T14:42:28",
            "upload_time_iso_8601": "2025-01-27T14:42:28.059437Z",
            "url": "https://files.pythonhosted.org/packages/10/02/c5429c2689662fb7229f8b11b601133a8c2bf6c9ff935f84ee3306a83a15/xaal.lib-0.7.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "08ec1fe351667f4ffa0725ee90cd60fa77f880ce088ed1595a9023b797ec6332",
                "md5": "c1ce65a44f8704f79e44fad3fbc568c3",
                "sha256": "c827b7fb66264c94c4e3c5d5e571fa6cbfdd4ba411989f29db8789be3b874e1d"
            },
            "downloads": -1,
            "filename": "xaal_lib-0.7.11.tar.gz",
            "has_sig": false,
            "md5_digest": "c1ce65a44f8704f79e44fad3fbc568c3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 30035,
            "upload_time": "2025-01-27T14:42:30",
            "upload_time_iso_8601": "2025-01-27T14:42:30.127536Z",
            "url": "https://files.pythonhosted.org/packages/08/ec/1fe351667f4ffa0725ee90cd60fa77f880ce088ed1595a9023b797ec6332/xaal_lib-0.7.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-27 14:42:30",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "xaal.lib"
}
        
Elapsed time: 0.50745s