Giter VIP home page Giter VIP logo

lifx-gem's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.