aiolifx


Nameaiolifx JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttp://github.com/frawau/aiolifx
SummaryAPI for local communication with LIFX devices over a LAN with asyncio.
upload_time2024-04-06 10:51:41
maintainerNone
docs_urlNone
authorFrançois Wautier
requires_python>=3.4
licenseMIT
keywords lifx light automation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # aiolifx

aiolifx is a Python 3/asyncio library to control Lifx LED lightbulbs over your LAN.

[![PyPI version fury.io](https://badge.fury.io/py/aiolifx.svg)](https://pypi.python.org/pypi/aiolifx)
[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-licen)
[![GITHUB-BADGE](https://github.com/frawau/aiolifx/workflows/black/badge.svg)](https://github.com/psf/black)
[![Downloads](https://pepy.tech/badge/aiolifx/month)](https://pepy.tech/project/aiolifx)

Most of it was taken from Meghan Clarkk lifxlan package (https://github.com/mclarkk)
and adapted to Python 3 (and asyncio obviously)

# Installation

We are on PyPi so

     pip3 install aiolifx
or
     python3 -m pip install aiolifx

After installation, the utility

    aiolifx

can be used to test/control devices.

NOTE: When installing with Python 3.4, the installation produce an error message
      (syntax error). This can be safely ignored.


# How to use

Essentially, you create an object with at least 2 methods:

    - register
    - unregister

You then start the LifxDiscovery task in asyncio. It will register any new light it finds.
All the method communicating with the bulb can be passed a callback function to react to
the bulb response. The callback should take 2 parameters:

    - a light object
    - the response message


The easiest way is to look at the file in the examples directory. "Wifi" and "Uptime" use
a callback to print the info when it is returned.


In essence, the test program is this

    class bulbs():
    """ A simple class with a register and unregister methods
    """
        def __init__(self):
            self.bulbs=[]

        def register(self,bulb):
            self.bulbs.append(bulb)

        def unregister(self,bulb):
            idx=0
            for x in list([ y.mac_addr for y in self.bulbs]):
                if x == bulb.mac_addr:
                    del(self.bulbs[idx])
                    break
                idx+=1

    def readin():
    """Reading from stdin and displaying menu"""

        selection = sys.stdin.readline().strip("\n")
        DoSomething()

    MyBulbs = bulbs()
    loop = aio.get_event_loop()
    discovery = alix.LifxDiscovery(loop, MyBulbs)
    try:
        loop.add_reader(sys.stdin, readin)
        discovery.start()
        loop.run_forever()
    except:
        pass
    finally:
        discovery.cleanup()
        loop.remove_reader(sys.stdin)
        loop.close()


Other things worth noting:

    -  Whilst LifxDiscovery uses UDP broadcast, the bulbs are
       connected with Unicast UDP

    - The socket connecting to a bulb is not closed unless the bulb is deemed to have
      gone the way of the Dodo. I've been using that for days with no problem

    - You can select to used IPv6 connection to the bulbs by passing an
      IPv6 prefix to LifxDiscovery. It's only been tried with /64 prefix.
      If you want to use a /48 prefix, add ":" (colon) at the end of the
      prefix and pray. (This means 2 colons at the end!)

    - I only have Original 1000, so I could not test with other types
      of bulbs

    - Unlike in lifxlan, set_waveform takes a dictionary with the right
      keys instead of all those parameters

# Development
## Running locally
Run this command each time you make changes to the project. It enters at `__main__.py`

```bash
pip3 install . && aiolifx
```

# Thanks

Thanks to Anders Melchiorsen and Avi Miller for their essential contributions

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/frawau/aiolifx",
    "name": "aiolifx",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.4",
    "maintainer_email": null,
    "keywords": "lifx, light, automation",
    "author": "Fran\u00e7ois Wautier",
    "author_email": "francois@wautier.eu",
    "download_url": "https://files.pythonhosted.org/packages/02/c5/78aab1b25e0037d2c4c16b893bfa5ccba68095f58057c8360a54bdfa3b06/aiolifx-1.0.2.tar.gz",
    "platform": null,
    "description": "# aiolifx\n\naiolifx is a Python 3/asyncio library to control Lifx LED lightbulbs over your LAN.\n\n[![PyPI version fury.io](https://badge.fury.io/py/aiolifx.svg)](https://pypi.python.org/pypi/aiolifx)\n[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-licen)\n[![GITHUB-BADGE](https://github.com/frawau/aiolifx/workflows/black/badge.svg)](https://github.com/psf/black)\n[![Downloads](https://pepy.tech/badge/aiolifx/month)](https://pepy.tech/project/aiolifx)\n\nMost of it was taken from Meghan Clarkk lifxlan package (https://github.com/mclarkk)\nand adapted to Python 3 (and asyncio obviously)\n\n# Installation\n\nWe are on PyPi so\n\n     pip3 install aiolifx\nor\n     python3 -m pip install aiolifx\n\nAfter installation, the utility\n\n    aiolifx\n\ncan be used to test/control devices.\n\nNOTE: When installing with Python 3.4, the installation produce an error message\n      (syntax error). This can be safely ignored.\n\n\n# How to use\n\nEssentially, you create an object with at least 2 methods:\n\n    - register\n    - unregister\n\nYou then start the LifxDiscovery task in asyncio. It will register any new light it finds.\nAll the method communicating with the bulb can be passed a callback function to react to\nthe bulb response. The callback should take 2 parameters:\n\n    - a light object\n    - the response message\n\n\nThe easiest way is to look at the file in the examples directory. \"Wifi\" and \"Uptime\" use\na callback to print the info when it is returned.\n\n\nIn essence, the test program is this\n\n    class bulbs():\n    \"\"\" A simple class with a register and unregister methods\n    \"\"\"\n        def __init__(self):\n            self.bulbs=[]\n\n        def register(self,bulb):\n            self.bulbs.append(bulb)\n\n        def unregister(self,bulb):\n            idx=0\n            for x in list([ y.mac_addr for y in self.bulbs]):\n                if x == bulb.mac_addr:\n                    del(self.bulbs[idx])\n                    break\n                idx+=1\n\n    def readin():\n    \"\"\"Reading from stdin and displaying menu\"\"\"\n\n        selection = sys.stdin.readline().strip(\"\\n\")\n        DoSomething()\n\n    MyBulbs = bulbs()\n    loop = aio.get_event_loop()\n    discovery = alix.LifxDiscovery(loop, MyBulbs)\n    try:\n        loop.add_reader(sys.stdin, readin)\n        discovery.start()\n        loop.run_forever()\n    except:\n        pass\n    finally:\n        discovery.cleanup()\n        loop.remove_reader(sys.stdin)\n        loop.close()\n\n\nOther things worth noting:\n\n    -  Whilst LifxDiscovery uses UDP broadcast, the bulbs are\n       connected with Unicast UDP\n\n    - The socket connecting to a bulb is not closed unless the bulb is deemed to have\n      gone the way of the Dodo. I've been using that for days with no problem\n\n    - You can select to used IPv6 connection to the bulbs by passing an\n      IPv6 prefix to LifxDiscovery. It's only been tried with /64 prefix.\n      If you want to use a /48 prefix, add \":\" (colon) at the end of the\n      prefix and pray. (This means 2 colons at the end!)\n\n    - I only have Original 1000, so I could not test with other types\n      of bulbs\n\n    - Unlike in lifxlan, set_waveform takes a dictionary with the right\n      keys instead of all those parameters\n\n# Development\n## Running locally\nRun this command each time you make changes to the project. It enters at `__main__.py`\n\n```bash\npip3 install . && aiolifx\n```\n\n# Thanks\n\nThanks to Anders Melchiorsen and Avi Miller for their essential contributions\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "API for local communication with LIFX devices over a LAN with asyncio.",
    "version": "1.0.2",
    "project_urls": {
        "Homepage": "http://github.com/frawau/aiolifx"
    },
    "split_keywords": [
        "lifx",
        " light",
        " automation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0a904abfa56a245877e596fedcfdf5a00c7453fc5e8d5b95e9fcb9e1ba77e2ee",
                "md5": "ddddc394dcb3d3c3ebd49a6ad7d56dea",
                "sha256": "fb12df92d6f290baadeb1f80abf92737ddd4cdd6f4789ce2a3226160ff7b41c9"
            },
            "downloads": -1,
            "filename": "aiolifx-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ddddc394dcb3d3c3ebd49a6ad7d56dea",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.4",
            "size": 41471,
            "upload_time": "2024-04-06T10:51:38",
            "upload_time_iso_8601": "2024-04-06T10:51:38.994850Z",
            "url": "https://files.pythonhosted.org/packages/0a/90/4abfa56a245877e596fedcfdf5a00c7453fc5e8d5b95e9fcb9e1ba77e2ee/aiolifx-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "02c578aab1b25e0037d2c4c16b893bfa5ccba68095f58057c8360a54bdfa3b06",
                "md5": "e4354d183fcbf5fb9f1d5a42628c2b85",
                "sha256": "137531353aacb37baba4c4f084b848a009c17a418e232172d3eb0e8f798696cb"
            },
            "downloads": -1,
            "filename": "aiolifx-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "e4354d183fcbf5fb9f1d5a42628c2b85",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.4",
            "size": 39888,
            "upload_time": "2024-04-06T10:51:41",
            "upload_time_iso_8601": "2024-04-06T10:51:41.542865Z",
            "url": "https://files.pythonhosted.org/packages/02/c5/78aab1b25e0037d2c4c16b893bfa5ccba68095f58057c8360a54bdfa3b06/aiolifx-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-06 10:51:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "frawau",
    "github_project": "aiolifx",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "aiolifx"
}
        
Elapsed time: 0.21342s