MCPcopy Index your code
hub / github.com/LIFX/lifx-sdk-android

github.com/LIFX/lifx-sdk-android @0.5

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.5 ↗ · + Follow
1,388 symbols 2,669 edges 50 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

LIFX Android SDK - the LIFX SDK for Android

The SDK currently supports Android only. Java support is coming soon.

Installation

Library Project Installation

The LIFX SDK will be published as a JAR archive when it is released publicly, but until then you can still use the SDK by cloning the repository and importing it into your project as an Android Library Project. Users should note that the library is currently in an early Beta stage, so the API itself could change in the future.

Eclipse Sub-Project Installation

  1. Clone the SDK repository into a directory on your local machine.
  2. Open Eclipse and choose to import a "existing android code"
  3. Import the library project.
  4. Open the project properties for your application, select android then add the library project.

Quick Examples

Initializing the library:

Before using the Library functions, a connection must be established with the LIFX lights that are on the current network. First a reference to local network is gathered, then a connection is requested.

LFXNetworkContext localNetworkContext = LFXClient.getSharedInstance( this).getLocalNetworkContext();
localNetworkContext.connect();

Turn off all lights:

LFXNetworkContext localNetworkContext = LFXClient.getSharedInstance( this).getLocalNetworkContext();
localNetworkContext.getAllLightsCollection().setPowerState( LFXPowerState.OFF);

Turn on the light named "Hallway":

LFXNetworkContext localNetworkContext = LFXClient.getSharedInstance( this).getLocalNetworkContext();
LFXLight hallway = localNetworkContext.getAllLightsCollection().getFirstLightForLabel( "Hallway");
hallway.setPowerState( LFXPowerState.ON);

Turn on all lights that are tagged "Kitchen":

LFXNetworkContext localNetworkContext = LFXClient.getSharedInstance( this).getLocalNetworkContext();
LFXTaggedLightCollection kitchen = localNetworkContext.getTaggedLightCollectionForTag( "Kitchen");
kitchen.setPowerState( LFXPowerState.ON);

Set every light to a random color:

LFXNetworkContext localNetworkContext = LFXClient.getSharedInstance( this).getLocalNetworkContext();

for( LFXLight aLight : localNetworkContext.getAllLightsCollection().getLights())
{
    LFXHSBKColor color = LFXHSBKColor.getColor( (float)(Math.random() * 360), 1.0f, 1.0f, 3500);
    aLight.setColor( color);
}

Disconnect:

When the application is finished with the LIFX bulbs, you will need to signal the Library to end it's connections.

LFXNetworkContext localNetworkContext = LFXClient.getSharedInstance( this).getLocalNetworkContext();
localNetworkContext.disconnect();

Quick overview of LIFX SDK terminology

Network Context

A Network Context (LFXNetworkContext) denotes a context within which you will be accessing LIFX devices. The SDK currently only has support for a "Local Network Context", which refers to devices accessible on your LAN. We plan on adding Network Contexts for accessing LIFX devices via the upcoming cloud service.

Lights, Light Collections and Addressing

The underlying LIFX system has three types of internal address: device, tag and broadcast. Device addressing will target an individual device, tag addressing will target all devices that have a particular tag, and broadcast addressing addressing will target all devices. Due to the way the underlying LIFX Binary Protocol works, you'll see much faster responses by targetting a tag (using a Tagged Light Collection) rather than targetting every device within that tag individually. The same goes for targetting all lights - if you want to change the state on all lights, you'll see much faster performance targetting LFXNetworkContext.getAllLightsCollection() instead of targetting each device individually.

Lights

A LFXLight object represents an individual LIFX Light, and there will be only one LFXLight corresponding to each device per Network Context.

Light Collections

Light Collections (LFXLightCollection) are classes that encapsulate a group of LIFX lights. They can have their light state manipulated in the same way that an individual light can. You can access the lights within a Light Collection through the .getLights() method.

The All Lights Collection

Each LFXNetworkContext has an .getAllLightCollections() method, which is how you get the list of lights. If you want to manipulate every light in the same way (e.g. to turn every light off), you should use the All Lights Collection property directly, instead of targetting each device individually.

Tagged Light Collections

A Tagged Light Collection (LFXTaggedLightCollection) represents the lights contained within a particular tag. If you want to manipulate every device within a tag, you should always use the Tagged Light Collection instead of dealing with each Light individually. Tagged Light Collections are unique within a Network Context.

HSBK Color

LIFX makes use of a "HSBK" color representation. The "HSB" part refers to the HSB color space, and the "K" part refers to the Color Temperature of the white point, in Kelvin. At full saturation, HSBK colors will correspond to the edge of the realisable color gamut, and at zero saturation, HSBK colors will correspond to the color described by the Color Temperature in the K component.

Extension points exported contracts — how you extend this code

LFXWiFiObserverCallback (Interface)
(no doc) [11 implementers]
library/src/lifx/java/android/internal/LFXWiFiObserver.java
LFXMessageObserverCallback (Interface)
(no doc) [11 implementers]
library/src/lifx/java/android/entities/internal/LFXMessageObservationDescriptor.java
LFXNetworkContextListener (Interface)
(no doc) [6 implementers]
library/src/lifx/java/android/network_context/LFXNetworkContext.java
LFXLightCollectionListener (Interface)
(no doc) [6 implementers]
library/src/lifx/java/android/light/LFXLightCollection.java
LFXLightListener (Interface)
(no doc) [10 implementers]
library/src/lifx/java/android/light/LFXLight.java

Core symbols most depended-on inside this repo

printValue
called by 96
library/src/lifx/java/android/entities/internal/structle/StructleTypes.java
getBytes
called by 76
library/src/lifx/java/android/entities/internal/structle/LxProtocolDevice.java
getBytes
called by 72
library/src/lifx/java/android/entities/internal/structle/LxProtocolLight.java
getBytes
called by 29
library/src/lifx/java/android/entities/internal/structle/Lx.java
getType
called by 26
library/src/lifx/java/android/entities/internal/LFXMessage.java
getBytes
called by 23
library/src/lifx/java/android/entities/internal/structle/LxProtocolWifi.java
equals
called by 22
library/src/lifx/java/android/entities/LFXHSBKColor.java
getSiteID
called by 19
library/src/lifx/java/android/entities/internal/LFXTagMapping.java

Shape

Method 1,215
Class 147
Enum 16
Interface 10

Languages

Java100%

Modules by API surface

library/src/lifx/java/android/entities/internal/structle/LxProtocolDevice.java332 symbols
library/src/lifx/java/android/entities/internal/structle/LxProtocolLight.java144 symbols
library/src/lifx/java/android/entities/internal/structle/StructleTypes.java88 symbols
library/src/lifx/java/android/entities/internal/structle/LxProtocolWifi.java62 symbols
library/src/lifx/java/android/entities/internal/structle/LxProtocolWan.java56 symbols
library/src/lifx/java/android/entities/internal/LFXMessage.java44 symbols
library/src/lifx/java/android/network_context/LFXNetworkContext.java41 symbols
library/src/lifx/java/android/entities/internal/structle/Lx.java41 symbols
library/src/lifx/java/android/network_context/internal/transport_manager/gateway_connection/LFXSocketGeneric.java35 symbols
library/src/lifx/java/android/light/LFXLight.java31 symbols
library/src/lifx/java/android/entities/internal/structle/LxProtocolSensor.java31 symbols
library/src/lifx/java/android/light/LFXLightCollection.java29 symbols

For agents

$ claude mcp add lifx-sdk-android \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact