Skip to main content

lifx-lib

Build Status codecov Documentation Status

A Python 3 library able to encode/decode Lifx (lan) messages.

It can be used with an asynchronous or synchronous client.

Examples

Encode

    >>> import lifx
    >>> body = lifx.lan.light.SetColor()
    >>> header = lifx.lan.header.make(body.state)
    >>> body.rgb = (0, 255, 0)
    >>> body.kelvin = 3500
    >>> body.duration = 1024
    >>> msg = lifx.lan.Msg.encode(header, body)
    >>> msg
    [0x31, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, 0xFF, 0xFF, 0xFF, 0xFE, 0xAC, 0x0D, 0x00, 0x04, 0x00, 0x00]

Encode from a dictionary

   >>> import lifx
   >>> dictionary = {"hue": 335, "saturation": 90, "brightness": 90, "kelvin": 3500, "duration": 1000,
   ...               "transient": True, "period": 180000, "cycles": 30, "skew_ratio": 0.5, "waveform": "sine"}
   >>> body = lifx.lan.light.State_Factory.make("SetWaveform", dictionary)
   >>> header = lifx.lan.header.make(body.state)
   >>> msg = lifx.lan.Msg.encode(header, body)
   >>> msg
   [0x39, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0x00, 0x00, 0x00, 0x00, 0x01, 0x38, 0xEE, 0x66, 0xE6, 0x66, 0xE6, 0xAC, 0x0D, 0x20, 0xBF, 0x02, 0x00, 0x00, 0x00, 0xF0, 0x41, 0x00, 0x00, 0x01]

Decode

    >>> import lifx
    >>> msg = lifx.lan.Msg.from_bytes([0x58, 0x00, 0x00, 0x54, 0xB9, 0x71, 0x5D, 0x07, 0xD0, 0x73, 0xD5, 0x12, 0x1A, 0xF1, 0x00, 0x00, 0x4C, 0x49, 0x46, 0x58, 0x56, 0x32, 0x00, 0x4D, 0x18, 0x52, 0x42, 0x1E, 0xB5, 0xFC, 0x82, 0x14, 0x6B, 0x00, 0x00, 0x00, 0x71, 0x7E, 0xCC, 0x4C, 0x09, 0x57, 0xAC, 0x0D, 0x00, 0x00, 0xFF, 0xFF, 0x4C, 0x49, 0x46, 0x58, 0x20, 0x42, 0x75, 0x6C, 0x62, 0x20, 0x31, 0x32, 0x31, 0x61, 0x66, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
    >>> (header, body) = msg.decode()
    >>> header.type
    <State.state_light: 107>
    >>> body.kelvin
    3500
    >>> body.rgb
    (61, 87, 86)
    >>> str(body)
    'State {power: 65535, hue: 178, saturation: 30, brightness: 34, kelvin: 3500, rgb: (61, 87, 86), label: LIFX Bulb 121af1}'

Decode to a dictionary

    >>> import lifx
    >>> msg = lifx.lan.Msg.from_bytes([0x39, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0x00, 0x00, 0x00, 0x00, 0x01, 0x38, 0xEE, 0x66, 0xE6, 0x66, 0xE6, 0xAC, 0x0D, 0x20, 0xBF, 0x02, 0x00, 0x00, 0x00, 0xF0, 0x41, 0x00, 0x00, 0x01])
    >>> (header, body) = msg.decode()
    >>> header.type
    <State.set_waveform_light: 103>
    >>> factory = lifx.lan.light.Description_Factory()
    >>> s = factory.make(body)
    >>> s[0]
    'SetWaveform'
    >>> s[1]['waveform']
    'sine'

Getting Started

pip install lifx-lib

Diving In

Documentation

Contributing

Pull requests are welcome!.

License

lifx-lib is licensed under the MIT license.

Metadata

Release files for lifx-lib 0.9.1

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

Source distribution (sdist)

Source distribution for lifx-lib 0.9.1
File Size Uploaded
lifx-lib-0.9.1.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lifx-lib 0.9.1
File Interpreter ABI Platform
lifx_lib-0.9.1-py3-none-any.whl Python 3 none any Details

Total release size: 24.8 kB

Release files / lifx-lib-0.9.1.tar.gz

Download URL lifx-lib-0.9.1.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7b90bbdfbf897f62870b264b9212f1d27cad0b5b413121755846d36974f24151
BLAKE2b-256 checksum
How to use checksums
567a20f0a784044b21656c5c9314c85fadc1c5de55da16d8f1d3b5673dcc85fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / lifx_lib-0.9.1-py3-none-any.whl

Download URL lifx_lib-0.9.1-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15cbffdc8aa27c55a0bbd3845ef9c66e185544b4ca387017d173fc3b69129257
BLAKE2b-256 checksum
How to use checksums
8143ce9d170ec03f8f53afc0ccd37d34bfbdb6ba081888a3a572d45d77283d46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.9.1 This release

2 release files

0.9

1 release file

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