lifx package¶
Submodules¶
lifx.client module¶
-
class
lifx.client.
Client
(broadcast='255.255.255.255', address='0.0.0.0', discoverpoll=60, devicepoll=5)¶ Bases:
object
The Client object is responsible for discovering lights and managing incoming and outgoing packets. This is the class most people will use to interact with the lights.
Parameters: - broadcast – The address to broadcast to when discovering devices.
- address – The address to receive packet on.
- discoverpoll – The time in second between attempts to discover new bulbs.
- devicepoll – The time is seconds between polls to check if devices still respond.
-
by_group_id
(group_id)¶ Return a list of devices based on their group membership.
Parameters: group_id – The group id to match on each light. Returns: list – The devices that match criteria
-
by_id
(id)¶ Return the device with the id specified.
Parameters: id – The device id Returns: Device – The device with the matching id.
-
by_label
(label)¶ Return a list of devices with the label specified.
Parameters: by_label – The label we are looking for. Returns: list – The devices that match criteria
-
by_location_id
(location_id)¶ Return a list of devices based on their group membership.
Parameters: group_id – The group id to match on each light. Returns: list – The devices that match criteria
-
by_power
(power)¶ Return a list of devices based on power states.
Parameters: power – True returns all devices that are on, False returns ones that are off. Returns: list – The devices that match criteria
-
devices
¶
-
discover
()¶ Perform device discovery now.
-
get_devices
(max_seen=None)¶ Get a list of all responding devices.
Parameters: max_seen – The number of seconds since the device was last seen, defaults to 3 times the devicepoll interval.
-
get_groups
(max_seen=None)¶ Get a list of all groups with responding devices.
Parameters: max_seen – The number of seconds since a device in the group was last seen, defaults to 3 times the devicepoll interval.
-
get_locations
(max_seen=None)¶ Get a list of all locations with responding devices.
Parameters: max_seen – The number of seconds since a device in the location was last seen, defaults to 3 times the devicepoll interval.
-
group_by_label
(label)¶ Return a list of groups with the label specified.
Parameters: by_label – The label we are looking for. Returns: list – The groups that match criteria
-
groups
¶
-
locations
¶
-
poll_devices
()¶ Poll all devices right now.
-
send_packet
(*args, **kwargs)¶ Sends a packet to a device. The client fills in the sequence and source parameters then calls the transport’s packet send_packet.
lifx.color module¶
-
class
lifx.color.
HSBK
(hue, saturation, brightness, kelvin)¶ Bases:
tuple
-
brightness
¶ Alias for field number 2
-
hue
¶ Alias for field number 0
-
kelvin
¶ Alias for field number 3
-
saturation
¶ Alias for field number 1
-
-
lifx.color.
color_from_message
(state)¶ Translates values from a packet into actual color values
Parameters: state – The state data from the light state message Returns: HSBK – The actual color values
-
lifx.color.
message_from_color
(hsbk)¶ Translates values from a color to values suitable for the packet.
Parameters: hsbk – The data from the actual color Returns: HSBK – Color values for a light state message
-
lifx.color.
modify_color
(hsbk, **kwargs)¶ Helper function to make new colors from an existing color by modifying it.
Parameters: - hsbk – The base color
- hue – The new Hue value (optional)
- saturation – The new Saturation value (optional)
- brightness – The new Brightness value (optional)
- kelvin – The new Kelvin value (optional)
lifx.device module¶
-
class
lifx.device.
Device
(device_id, host, client)¶ Bases:
object
-
brightness
¶ The brightness value the bulb is currently set to. Set this to alter only the current brightness of the bulb.
-
color
¶ The color the device is currently set to. Set this value to change the color of the bulb all at once.
-
fade_color
(newcolor, duration=200)¶ Transition the light to a new color.
Parameters: - newcolor – The HSBK tuple of the new color to transition to
- duration – The number of milliseconds to perform the transition over.
-
fade_power
(power, duration=200)¶ Transition to another power state slowly.
Parameters: - power – The new power state
- duration – The number of milliseconds to perform the transition over.
-
get_port
(service_id=1)¶ Get the port for a service, by default the UDP service.
Parameters: service_id – The service whose port we are fetching.
-
group_id
¶ The id of the group that the Device is in. Read Only.
-
host
¶ The ip address of the device. Read Only.
-
host_firmware
¶ The version string representing the firmware version.
-
hue
¶ The hue value of the color the bulb is set to. Set this to alter only the Hue.
-
id
¶ The device id. Read Only.
-
kelvin
¶ The kelvin value the bulb is currently set to. Set this to alter only the current kelvin of the bulb.
-
label
¶ The label for the device, setting this will change the label on the device.
-
latency
¶ The latency to the device. Read Only.
-
location_id
¶ The id of the group that the Device is in. Read Only.
-
power
¶ The power state of the device. Set to False to turn of and True to turn on.
-
power_toggle
(duration=200)¶ Transition to the opposite power state slowly.
Parameters: duration – The number of milliseconds to perform the transition over.
-
saturation
¶ The saturation value the bulb is currently set to. Set this to alter only the saturation.
-
seen_ago
¶ The time in seconds since we last saw a packet from the device. Read Only.
-
send_poll_packet
()¶ Send a poll packet to the device, without waiting for a response. The response will be received later and will update the time we last saw the bulb.
-
stats
¶
-
udp_port
¶ The port of the UDP service. Read Only.
-
wifi_firmware
¶ The version string representing the firmware version.
-
-
exception
lifx.device.
DeviceTimeoutError
(device, timeout, retransmits)¶ Bases:
exceptions.Exception
Raise when we time out waiting for a response
lifx.group module¶
-
class
lifx.group.
Group
(group_id, client, member_func, label_func)¶ Bases:
object
-
fade_color
(newcolor, duration=200)¶ Change the color of the entire group at once.
Parameters: - power – The color to transition every bulb in the group to.
- duration – The amount of time to perform the transition over.
-
fade_power
(power, duration=200)¶ Change the power state of the entire group at once.
Parameters: - power – The power state to transition every bulb in the group to.
- duration – The amount of time to perform the transition over.
-
id
¶ The ID of this group
-
label
¶ The Label on this group
-
members
¶ A list of lights in this group.
-
power_toggle
(duration=200)¶ Toggle the power of every member of the group individually. Essentially it inverts the power state across the group.
Parameters: duration – The amount of time to perform the transition over.
-
lifx.network module¶
-
class
lifx.network.
ListenerThread
(socket, handler)¶ Bases:
threading.Thread
The Listener Thread grabs incoming packets, parses them and forwards them to the right listeners
-
run
()¶
-
-
class
lifx.network.
NetworkTransport
(address='0.0.0.0', broadcast='255.255.255.255')¶ Bases:
object
The network transport manages the network sockets and the networking threads
-
register_packet_handler
(handler, pktfilter=<function <lambda>>)¶
-
send_discovery
(source, sequence)¶
-
send_packet
(*args, **kwargs)¶
-
-
class
lifx.network.
PacketHandler
(handler, pktfilter)¶ Bases:
tuple
-
handler
¶ Alias for field number 0
-
pktfilter
¶ Alias for field number 1
-
-
lifx.network.
default_filter
(x)¶
lifx.protocol module¶
-
lifx.protocol.
bytes_to_label
(label_bytes)¶ Takes the bytes from a TYPE_STATELABEL packet removes the NUL char and and everything after, then converts it to unicode.
Parameters: label_bytes – The bytes from the TYPE_STATELABEL packet Returns: unicode – The label of the device
-
lifx.protocol.
discovery_packet
(source, sequence)¶ Helper function for building a discovery packet easily
Parameters: - source – The source field to put into the frame header
- sequence – The wrap around sequence number for the frame address header
Returns: bytearray – The discovery packet represented as bytes
-
class
lifx.protocol.
lifx_packet
(frame_header, frame_address, protocol_header, payload)¶ Bases:
tuple
-
frame_address
¶ Alias for field number 1
-
frame_header
¶ Alias for field number 0
-
payload
¶ Alias for field number 3
-
protocol_header
¶ Alias for field number 2
-
-
lifx.protocol.
mac_string
(device_id)¶ Converts a device id into a mac address hex string
Parameters: device_id – The device id Returns: str – The mac address represented as a string
-
lifx.protocol.
make_packet
(*args, **kwargs)¶ Builds a packet from data supplied, required arguments depends on the packet type
-
lifx.protocol.
pack_section
(section, *args)¶ Packs bytes into a header including the swap to little-endian
Parameters: - section – The definition of the format and byteswap for this section
- *args – Values to include in the section in the order they are in the format
Returns: bytearray – The packed bytes of the section
-
lifx.protocol.
parse_packet
(data)¶ Takes packet data as composes it into several namedtuple objects
Parameters: data – Byte data for the packet to be parsed Returns: namedtuple – A named tuple representing the packet, with nested namedtuples for each header and the payload
-
lifx.protocol.
section_size
(section)¶ Returns the size of a section
Parameters: section – The definition of the format for this section Returns: int – An integer representing the size in bits of the section
-
lifx.protocol.
unpack_section
(section, data)¶ Unpacks bytes into data, including the endian swap
Parameters: - section – The definition of the format, byteswap and namedtuple for this section
- data – The bytes to unpack into the tuple
Returns: namedtuple – A namedtuple containing the data from the section
-
lifx.protocol.
version_string
(version)¶ Converts a version number into a version string
Parameters: version – The version number from the firmware :returns str – The version string
lifx.util module¶
@author: Brian Curtin http://code.activestate.com/lists/python-ideas/8982/
-
class
lifx.util.
RepeatTimer
(interval, callable, *args, **kwargs)¶ Bases:
threading.Thread
-
cancel
()¶
-
run
()¶
-