Quick Start¶
Get started with LIFX Emulator in just a few minutes.
Start the Emulator¶
The simplest way to start the emulator is with the default configuration:
This creates a single color light device listening on port 56700.
Using Verbose Mode¶
To see all packet traffic (helpful for debugging):
You'll see output like:
INFO - Starting LIFX Emulator on 127.0.0.1:56700
INFO - Created 1 emulated device(s):
INFO - • A19 d073d5 (d073d5000001) - full color
INFO - Server running with verbose packet logging... Press Ctrl+C to stop
DEBUG - Received 36 bytes from ('192.168.1.100', 54321)
DEBUG - Header: GetService (type=2) target=000000000000 source=12345678
DEBUG - Sending StateService to ('192.168.1.100', 54321)
Create Multiple Devices¶
Create different device types:
# Create 2 color lights, 1 multizone strip, and 1 tile
lifx-emulator --color 2 --multizone 1 --tile 1
Use Specific Products¶
Create devices by product ID from the LIFX registry:
# Create LIFX A19 (27), LIFX Z (32), and LIFX Tile (55)
lifx-emulator --product 27 --product 32 --product 55
See all available products:
Python API¶
Use the emulator in your Python tests:
import asyncio
from lifx_emulator import EmulatedLifxServer
from lifx_emulator.factories import create_color_light
from lifx_emulator.repositories import DeviceRepository
from lifx_emulator.devices import DeviceManager
async def main():
# Create a color light
device = create_color_light("d073d5000001")
# Set up repository and manager (required)
device_repository = DeviceRepository()
device_manager = DeviceManager(device_repository)
# Start server
server = EmulatedLifxServer(
[device], device_manager, "127.0.0.1", 56700
)
await server.start()
print(f"Server running with device: {device.state.label}")
# Keep running
try:
await asyncio.Event().wait()
except KeyboardInterrupt:
await server.stop()
if __name__ == "__main__":
asyncio.run(main())
import asyncio
from lifx_emulator import EmulatedLifxServer
from lifx_emulator.factories import (
create_color_light,
create_multizone_light,
create_tile_device,
)
from lifx_emulator.repositories import DeviceRepository
from lifx_emulator.devices import DeviceManager
async def main():
# Create different device types
devices = [
create_color_light("d073d5000001"),
create_multizone_light("d073d8000001", zone_count=16),
create_tile_device("d073d9000001", tile_count=5),
]
# Set up repository and manager (required)
device_repository = DeviceRepository()
device_manager = DeviceManager(device_repository)
# Start server
server = EmulatedLifxServer(
devices, device_manager, "127.0.0.1", 56700
)
await server.start()
print(f"Server running with {len(devices)} devices")
try:
await asyncio.Event().wait()
except KeyboardInterrupt:
await server.stop()
if __name__ == "__main__":
asyncio.run(main())
import pytest
from lifx_emulator import EmulatedLifxServer
from lifx_emulator.factories import create_color_light
from lifx_emulator.repositories import DeviceRepository
from lifx_emulator.devices import DeviceManager
from your_lifx_library import LifxClient
@pytest.fixture
def device_manager():
return DeviceManager(DeviceRepository())
@pytest.mark.asyncio
async def test_discover_devices(device_manager):
# Create emulated devices
device = create_color_light("d073d5000001")
server = EmulatedLifxServer(
[device], device_manager, "127.0.0.1", 56700
)
async with server:
# Use your LIFX library
client = LifxClient()
await client.discover(port=56700)
# Verify discovery
assert len(client.devices) == 1
assert client.devices[0].serial == "d073d5000001"
@pytest.mark.asyncio
async def test_set_color(device_manager):
device = create_color_light("d073d5000001")
server = EmulatedLifxServer(
[device], device_manager, "127.0.0.1", 56700
)
async with server:
client = LifxClient()
await client.discover(port=56700)
# Set color
await client.devices[0].set_color(hue=120, saturation=1.0, brightness=0.5)
# Verify state changed
assert device.state.color.hue == 21845 # 120 degrees in LIFX format
assert device.state.color.saturation == 65535
assert device.state.color.brightness == 32768
Device Discovery¶
The emulator responds to discovery broadcasts on port 56700 (or your chosen port). Your LIFX library should be able to discover emulated devices just like real ones.
Example with a typical discovery flow:
- Your library broadcasts
GetService(packet type 2) - Emulator responds with
StateServicelisting UDP service on port 56700 - Your library sends
GetVersionto get product info - Emulator responds with vendor=1, product=27 (or configured product)
- Your library can now send commands to control the device
Next Steps¶
- CLI Usage Guide - Learn all CLI options
- Device Types - Explore supported devices
- Testing Scenarios - Configure error scenarios
- API Reference - Complete API documentation
- Tutorials - More code examples