Skip to content

Latest commit

 

History

History
97 lines (60 loc) · 3.38 KB

README.md

File metadata and controls

97 lines (60 loc) · 3.38 KB

LIFX

Gem Version Build Status

This gem allows you to control your LIFX lights.

It handles discovery, gateway connections, tags, and provides a object-based API for talking to Lights.

Due to the nature of the current protocol, some methods are asynchronous.

This gem is in an early beta state. Expect breaking API changes.

Requirements

  • Ruby 2.0+
  • Tested on OS X Mavericks, but should work other *nix platforms. Please file an issue if you have any problems.

Installation

Add this line to your application's Gemfile:

gem 'lifx'

And then execute:

$ bundle

Or install the gem with:

gem install lifx        # Add sudo if required.

Usage

client = LIFX::Client.lan                  # Talk to bulbs on the LAN
client.discover! do |c|                    # Discover lights. Blocks until a light with the label 'Office' is found
  c.lights.with_label('Office')
end
                                           # Blocks for a default of 10 seconds or until a light is found
client.lights.turn_on                      # Tell all lights to turn on
light = client.lights.with_label('Office') # Get light with label 'Office'

# Set the Office light to pale green over 5 seconds
green = LIFX::Color.green(saturation: 0.5)
light.set_color(green, duration: 5)        # Light#set_color is asynchronous

sleep 5                                    # Wait for light to finish changing
light.set_label('My Office')

light.add_tag('Offices')                   # Add tag to light

client.lights.with_tag('Offices').turn_off

client.flush                               # Wait until all the packets have been sent

Documentation

Documentation is available at http://rubydoc.info/github/lifx/lifx-gem/master/frames. Please note that undocumented classes/methods and classes/methods marked private are not intended for public use.

LIFX uses the HSBK colour representation. HSB stands for hue, saturation, brightness, and K refers to kelvin.

Examples

Examples are located in the examples/ folder.

  • travis-build-light: Changes the colour of a light based on the build status of a project on Travis.
  • auto-off: Turns a light off after X seconds of it being detected turned on.
  • identify: Use divide-and-conquer search algorithm to identify a light visually.

Useful utilities

Testing

Run with bundle exec rspec.

The integration specs rely on a least one device tagged with Test to function. At this point, they can fail occasionally due to the async nature of the protocol, and there's not much coverage at the moment as the architecture is still in flux.

A more comprehensive test suite is in the works.

Feedback

Please file an issue for general feedback, bugs, clarification, examples, etc etc. Feel free to hit me up on Twitter, too: @chendo.

License

MIT. See LICENSE.txt