# 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/aiolifx/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/aiolifx/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/9c/d7/fbdb0ee469b2d49d6d0be183d17dd928d52bda4fde8e96157984e1682e02/aiolifx-1.1.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/aiolifx/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.1.2",
"project_urls": {
"Homepage": "http://github.com/aiolifx/aiolifx"
},
"split_keywords": [
"lifx",
" light",
" automation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d9d1740ba3d78ef2425e21130678b24e8c8ba83320e961e5cf459c70762fe482",
"md5": "9cf79331d3b364a124a6baeefea287ba",
"sha256": "34246c6433053d05816b4749a1ee6c20360b4de47e6a4a2394cfb7f38fee5fba"
},
"downloads": -1,
"filename": "aiolifx-1.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9cf79331d3b364a124a6baeefea287ba",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.4",
"size": 45473,
"upload_time": "2024-12-14T07:27:21",
"upload_time_iso_8601": "2024-12-14T07:27:21.063876Z",
"url": "https://files.pythonhosted.org/packages/d9/d1/740ba3d78ef2425e21130678b24e8c8ba83320e961e5cf459c70762fe482/aiolifx-1.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9cd7fbdb0ee469b2d49d6d0be183d17dd928d52bda4fde8e96157984e1682e02",
"md5": "51e7c0158b3a49ba929692f01b4a08c7",
"sha256": "33889ff5e4911bbe78e0e6958f71d7b6f3963e6d6683c373e5d87a9e5d21c7ee"
},
"downloads": -1,
"filename": "aiolifx-1.1.2.tar.gz",
"has_sig": false,
"md5_digest": "51e7c0158b3a49ba929692f01b4a08c7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.4",
"size": 43689,
"upload_time": "2024-12-14T07:27:24",
"upload_time_iso_8601": "2024-12-14T07:27:24.022652Z",
"url": "https://files.pythonhosted.org/packages/9c/d7/fbdb0ee469b2d49d6d0be183d17dd928d52bda4fde8e96157984e1682e02/aiolifx-1.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-14 07:27:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "aiolifx",
"github_project": "aiolifx",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "aiolifx"
}