libCEC — Python API

The cec module is the Python binding for libCEC, generated with SWIG from the same C++ interface (cec.h) and protocol types (cectypes.h) as every other binding. It lets Python applications control CEC-capable HDMI devices — power a TV on or to standby, become the active source, send remote keys, read device state — and receive bus events.

Every binding wraps the same engine, so the concepts (logical and physical addresses, device types, opcodes, power states) match the C/C++ reference, which documents them in the most depth.

Requirements

  • A Pulse-Eight USB-CEC adapter (or a supported SoC-native CEC backend).

  • The native libCEC library and its Python module (cec).

  • Python 3.

Installing

Debian / Ubuntu

sudo apt-get install python3-libcec

This installs the cec module against the system libCEC.

Build from source

The Python binding is built automatically when SWIG and the Python development files are present:

sudo apt-get install swig python3-dev      # build prerequisites
git clone https://github.com/Pulse-Eight/libcec.git
mkdir libcec/build && cd libcec/build
cmake ..
make -j4
sudo make install && sudo ldconfig

cmake reports Python support: yes when it detects the prerequisites.

Usage

Create a cec.libcec_configuration, optionally attach callbacks, create the adapter with cec.ICECAdapter.Create(), then open a connection.

import cec

# 1. describe this client
config = cec.libcec_configuration()
config.strDeviceName   = "pyCec"
config.bActivateSource = 0
config.deviceTypes.Add(cec.CEC_DEVICE_TYPE_RECORDING_DEVICE)
config.clientVersion   = cec.LIBCEC_VERSION_CURRENT

# 2. (optional) receive events — callbacks are set on the configuration
def log_callback(level, time, message):
    print("log:", message)
    return 0

config.SetLogCallback(log_callback)

# 3. create the instance and open the first adapter found
lib = cec.ICECAdapter.Create(config)
adapters = lib.DetectAdapters()
if adapters:
    lib.Open(adapters[0].strComName)

    # 4. control the bus
    lib.PowerOnDevices(cec.CECDEVICE_TV)
    print("TV:", lib.GetDeviceOSDName(cec.CECDEVICE_TV))

    # 5. clean up
    lib.Close()

Callbacks (SetLogCallback, SetKeyPressCallback, SetCommandCallback) are invoked from libCEC’s worker thread. See src/pyCecClient/pyCecClient.py in the repository for a complete, runnable example client.

API reference

class cec.SwigPyIterator(*args, **kwargs)[source]

Bases: object

property thisown

The membership flag

value()[source]
incr(n=1)[source]
decr(n=1)[source]
distance(x)[source]
equal(x)[source]
copy()[source]
next()[source]
previous()[source]
advance(n)[source]
class cec.AdapterVector(*args)[source]

Bases: object

property thisown

The membership flag

iterator()[source]
pop()[source]
append(x)[source]
empty()[source]
size()[source]
swap(v)[source]
begin()[source]
end()[source]
rbegin()[source]
rend()[source]
clear()[source]
get_allocator()[source]
pop_back()[source]
erase(*args)[source]
push_back(x)[source]
front()[source]
back()[source]
assign(n, x)[source]
resize(*args)[source]
insert(*args)[source]
reserve(n)[source]
capacity()[source]
cec.CEC_DEFAULT_PHYSICAL_ADDRESS

default physical address 1.0.0.0, HDMI port 1

cec.CEC_DEFAULT_HDMI_PORT

default HDMI port to which the adapter is connected, port 1

cec.CEC_DEFAULT_BASE_DEVICE

default logical address of the device to which the adapter is connected, TV

cec.CEC_BUTTON_TIMEOUT

timeout in milliseconds to send a key release event after receiving a key press

cec.CEC_BUTTON_RELEASE_BACKSTOP_MS

safety timeout in milliseconds after which a held button is force-released once the device has proven it sends its own release messages. it only guards against a lost release, so it is kept generous to leave room for long-presses.

cec.CEC_DOUBLE_TAP_TIMEOUT_MS

don’t send the same key twice within this timeout in milliseconds

cec.CEC_BUTTON_REPEAT_DELAY_MS

delay in milliseconds before a held button starts auto-repeating

cec.CEC_POWER_STATE_REFRESH_TIME

don’t query the power state for the same device within this timeout in milliseconds

cec.CEC_AUDIO_STATUS_REFRESH_TIME

don’t query the audio state for the same device within this timeout in milliseconds

cec.CEC_FW_VERSION_UNKNOWN

unknown firmware version value

cec.CEC_FW_BUILD_UNKNOWN

unknown build date value

cec.CEC_CONNECT_TRIES

maximum number of retries when opening a connection

cec.CEC_PHYSICAL_ADDRESS_TV

physical address of the TV

cec.CEC_MIN_PHYSICAL_ADDRESS

minimum physical address for the adapter

cec.CEC_MAX_PHYSICAL_ADDRESS

maximum physical address for the adapter

cec.CEC_INVALID_PHYSICAL_ADDRESS

invalid physical address value

cec.CEC_MIN_VENDORID

minimum vendor ID value

cec.CEC_MAX_VENDORID

maximum vendor ID value

cec.CEC_INVALID_VENDORID

invalid vendor ID value

cec.CEC_MIN_HDMI_PORTNUMBER

minimum HDMI port number value

cec.CEC_MAX_HDMI_PORTNUMBER

maximum HDMI port number value

cec.CEC_HDMI_PORTNUMBER_NONE

invalid HDMI port number value

cec.CEC_DEFAULT_SETTING_ACTIVATE_SOURCE

default value for settings “activate source”

cec.CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN

default value for settings “power off on shutdown”

cec.CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY

default value for settings “power off on standby”

cec.CEC_DEFAULT_DEVICE_LANGUAGE

default value for settings “device menu language”

cec.CEC_DEFAULT_SETTING_AUTODETECT_ADDRESS

default value for settings “autodetect physical address”

cec.CEC_DEFAULT_SETTING_GET_SETTINGS_FROM_ROM

default value for settings “get settings from ROM”

cec.CEC_DEFAULT_SETTING_CEC_VERSION

default value for settings “libCEC CEC version”

cec.CEC_DEFAULT_TRANSMIT_RETRY_WAIT

wait this amount of milliseconds before retrying to send a failed message

cec.CEC_DEFAULT_TRANSMIT_TIMEOUT

transmission fails when not acked within this amount of milliseconds after sending the initial packet

cec.CEC_DEFAULT_TRANSMIT_WAIT

wait this amount of milliseconds for an ack

cec.CEC_DEFAULT_TRANSMIT_RETRIES

default number of retries

cec.CEC_DEFAULT_CONNECT_TIMEOUT

default connection timeout in milliseconds

cec.CEC_DEFAULT_CONNECT_RETRY_WAIT

wait this amount of milliseconds before retrying when failing to connect

cec.CEC_SERIAL_DEFAULT_BAUDRATE

default serial baudrate

cec.CEC_CLEAR_INPUT_DEFAULT_WAIT

maximum time to wait when clearing input

cec.CEC_ACTIVE_SOURCE_SWITCH_RETRY_TIME_MS

wait this amount of milliseconds before retrying when libCEC failed to make itself the active source

cec.CEC_FORWARD_STANDBY_MIN_INTERVAL

don’t forward any power off command to the client application for this amount of milliseconds after sending a power off command

cec.CEC_DEFAULT_COMBO_TIMEOUT_MS

default timeout in milliseconds for combo keys

cec.CEC_RPI_VIRTUAL_PATH

the virtual device path to use for the Raspberry Pi’s CEC wire

cec.CEC_RPI_VIRTUAL_COM

the name of the virtual COM port to use for the Raspberry Pi’s CEC wire

cec.CEC_TDA995x_PATH

the path to use for the TDA995x’s CEC wire

cec.CEC_TDA995x_VIRTUAL_COM

the name of the virtual COM port to use for the TDA995x’s CEC wire

cec.CEC_EXYNOS_PATH

the path to use for the Exynos HDMI CEC device

cec.CEC_EXYNOS_VIRTUAL_COM

the name of the virtual COM port to use for the EXYNOS’ CEC wire

cec.CEC_MAX_DATA_PACKET_SIZE

Maximum size of a data packet

cec.CEC_MAX_FRAME_SIZE

1 header byte + 1 opcode + up to 14 operands. cec_datapacket can hold more (it is reused for adapter messages), so anything that is actually transmitted must be bound to this via cec_command::Serialize().

Type:

Maximum size of a CEC frame on the wire

cec.CEC_LINUX_PATH

the path to use for the Linux CEC device

cec.CEC_LINUX_PATH_FORMAT

printf format, node prefix and scan range used to locate Linux CEC device nodes. A board may expose several nodes at once (e.g. /dev/cec0 for HDMI0 and /dev/cec1 for HDMI1), and the kernel may recreate a node at a different minor after the adapter is unregistered, so all candidates are probed.

cec.CEC_LINUX_VIRTUAL_COM

the name of the virtual COM port to use for the Linux’ CEC wire

cec.CEC_AOCEC_PATH

the path to use for the AOCEC HDMI CEC device

cec.CEC_AOCEC_VIRTUAL_COM

the name of the virtual COM port to use for the AOCEC’ CEC wire

cec.CEC_IMX_PATH

the path to use for the i.MX CEC wire

cec.CEC_IMX_VIRTUAL_COM

the name of the virtual COM port to use for the i.MX CEC wire

cec.CEC_MIN_LIB_VERSION

Mimimum client version

cec.CEC_ABORT_REASON_UNRECOGNIZED_OPCODE

CEC_ABORT_REASON_UNRECOGNIZED_OPCODE

cec.CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND

CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND

cec.CEC_ABORT_REASON_CANNOT_PROVIDE_SOURCE

CEC_ABORT_REASON_CANNOT_PROVIDE_SOURCE

cec.CEC_ABORT_REASON_INVALID_OPERAND

CEC_ABORT_REASON_INVALID_OPERAND

cec.CEC_ABORT_REASON_REFUSED

CEC_ABORT_REASON_REFUSED

class cec.AdapterDescriptor(*args)[source]

Bases: object

property thisown

The membership flag

property strComPath

USB-tree path (Linux) / device instance id (Windows); does not change with enumeration order

Type:

the adapter’s stable location

property strComName

the com port used to open the adapter, e.g. /dev/ttyACM0 or COM3; may change with enumeration order

property iVendorId
property iProductId
property iFirmwareVersion
property iPhysicalAddress
property iFirmwareBuildDate
property adapterType
property strDeviceName

a human-readable display name for the adapter, e.g. “HDMI 1”

class cec.cec_datapacket[source]

Bases: object

property thisown

The membership flag

property data

the actual data

property size

the size of the data

IsEmpty()[source]
Return type:

boolean

Returns:

True when this packet is empty, false otherwise.

IsFull()[source]
Return type:

boolean

Returns:

True when this packet is false, false otherwise.

At(pos)[source]

Get the byte at the requested position. :type pos: uint8_t :param pos: The position. :rtype: uint8_t :return: The byte, or 0 when out of bounds.

Shift(iShiftBy)[source]

Shift the contents of this packet. :type iShiftBy: uint8_t :param iShiftBy: The number of positions to shift.

PushBack(add)[source]

Push a byte to the end of this packet. :type add: uint8_t :param add: The byte to add.

Clear()[source]

Clear this packet.

class cec.cec_command[source]

Bases: object

property thisown

The membership flag

property initiator

the logical address of the initiator of this message

property destination

the logical address of the destination of this message

property ack

1 when the ACK bit is set, 0 otherwise

property eom

1 when the EOM bit is set, 0 otherwise

property opcode

the opcode of this message

property parameters

the parameters attached to this message

property opcode_set

1 when an opcode is set, 0 otherwise (POLL message)

property transmit_timeout

the timeout to use in ms

Size()[source]
Serialize(buffer, iBufSize, bWithHeader=True)[source]
Serialize this command as an on-wire CEC frame: [header][opcode][operands…].

The frame is capped to a single CEC frame (CEC_MAX_FRAME_SIZE bytes) and to the destination buffer; a command that does not fit is rejected rather than truncated or overrunning the buffer. This is the single place where the transmit length is bounded, so adapter backends do not need their own size checks.

Parameters:
  • buffer (uint8_t) – The destination buffer.

  • iBufSize (uint8_t) – The size of the destination buffer, in bytes.

  • bWithHeader (boolean, optional) – When true (default), byte 0 is the initiator/destination header. When false, serialization starts at the opcode, for backends that carry the addressing in a separate field (e.g. the kernel cec_msg or the TDA995x frame header).

Return type:

int

Returns:

The number of bytes written (>= 0), or -1 when the command exceeds a CEC frame or would not fit the destination buffer.

static Format(command, initiator, destination, opcode, timeout=1000)[source]

Formats a cec_command. :type command: cec_command :param command: The command to format. :type initiator: int :param initiator: The logical address of the initiator. :type destination: int :param destination: The logical address of the destination. :type opcode: int :param opcode: The opcode of the command. :type timeout: int, optional :param timeout: The transmission timeout.

PushBack(data)[source]

Push a byte to the back of this command. :type data: uint8_t :param data: The byte to push.

Clear()[source]

Clear this command, resetting everything to the default values.

static GetResponseOpcode(opcode)[source]
PushArray(len, data)[source]
class cec.cec_device_type_list[source]

Bases: object

property thisown

The membership flag

property types

the list of device types

Clear()[source]

Clear this list.

Add(type)[source]

Add a type to this list. :type type: int :param type: The type to add.

IsSet(type)[source]

Check whether a type is set in this list. :type type: int :param type: The type to check. :rtype: boolean :return: True when set, false otherwise.

IsEmpty()[source]
Return type:

boolean

Returns:

True when this list is empty, false otherwise.

class cec.cec_logical_addresses[source]

Bases: object

property thisown

The membership flag

property primary

the primary logical address to use

property addresses

the list of addresses

Clear()[source]

Clear this list.

IsEmpty()[source]
Return type:

boolean

Returns:

True when empty, false otherwise.

AckMask()[source]

Calculate the ack-mask for this list, the mask to use when determining whether to send an ack message or not. :rtype: int :return: The ack-mask.

Set(address)[source]

Mark a logical address as ‘set’ :type address: int :param address: The logical address to add to this list.

Unset(address)[source]

Mark a logical address as ‘unset’ :type address: int :param address: The logical address to remove from this list.

IsSet(address)[source]

Check whether an address is set in this list. :type address: int :param address: The address to check. :rtype: boolean :return: True when set, false otherwise.

class cec.libcec_parameter[source]

Bases: object

property thisown

The membership flag

property paramType

the type of this parameter

property paramData

the value of this parameter

class cec.cec_adapter_stats[source]

Bases: object

property thisown

The membership flag

property tx_ack
property tx_nack
property tx_error
property rx_total
property rx_error
class cec.libcec_configuration[source]

Bases: object

property thisown

The membership flag

property clientVersion

the version of the client that is connecting

property strDeviceName

the device name to use on the CEC bus, name + 0 terminator

property deviceTypes

the device type(s) to use on the CEC bus for libCEC

property bAutodetectAddress

(read only) set to 1 by libCEC when the physical address was autodetected

property iPhysicalAddress

the physical address of the CEC adapter

property baseDevice

the logical address of the device to which the adapter is connected. only used when iPhysicalAddress = 0 or when the adapter doesn’t support autodetection

property iHDMIPort

the HDMI port to which the adapter is connected. only used when iPhysicalAddress = 0 or when the adapter doesn’t support autodetection

property tvVendor

override the vendor ID of the TV. leave this untouched to autodetect

property wakeDevices

list of devices to wake when initialising libCEC or when calling PowerOnDevices() without any parameter.

property powerOffDevices

list of devices to power off when calling StandbyDevices() without any parameter.

property serverVersion

the version number of the server. read-only

property bGetSettingsFromROM

true to get the settings from the ROM (if set, and a v2 ROM is present), false to use these settings.

property bActivateSource

make libCEC the active source on the bus when starting the player application

property bPowerOffOnStandby

put this PC in standby mode when the TV is switched off. only used when bShutdownOnStandby = 0

property logicalAddresses

(read-only) the current logical addresses. added in 1.5.3

property iFirmwareVersion

(read-only) the firmware version of the adapter. added in 1.6.0

property strDeviceLanguage

//www.loc.gov/standards/iso639-2/ added in 1.6.2

Type:

the menu language used by the client. 3 character ISO 639-2 country code. see http

Type:

//http

property iFirmwareBuildDate

(read-only) the build date of the firmware, in seconds since epoch. if not available, this value will be set to 0. added in 1.6.2

property bMonitorOnly

won’t allocate a CCECClient when starting the connection when set (same as monitor mode). added in 1.6.3

property cecVersion

CEC spec version to use by libCEC. defaults to v1.4. added in 1.8.0

property adapterType

type of the CEC adapter that we’re connected to. added in 1.8.2

property comboKey

key code that initiates combo keys. defaults to CEC_USER_CONTROL_CODE_STOP. CEC_USER_CONTROL_CODE_UNKNOWN to disable. added in 2.0.5

property iComboKeyTimeoutMs

timeout until the combo key is sent as normal keypress

property iButtonRepeatRateMs

rate at which buttons autorepeat. 0 means rely on CEC device

property iButtonReleaseDelayMs

duration after last update until a button is considered released

property iDoubleTapTimeoutMs

prevent double taps within this timeout. defaults to 200ms. added in 4.0.0

property bAutoWakeAVR

set to 1 to automatically waking an AVR when the source is activated. added in 4.0.0

property bAutoPowerOn

set to 1 and save eeprom config to wake the tv when usb is powered. added in 5.0.0 / fw v9

property bAutonomousMode

set to 1 (default) to let the adapter stay active on the CEC bus when the host isn’t running (ack polls and wake the host on a CEC request), or 0 to keep it silent when unattended so the TV/CEC bus can’t wake the host. save eeprom config to persist. added in 8.0.0

property iButtonRepeatDelayMs

delay before a held button starts auto-repeating, when iButtonRepeatRateMs is set. defaults to 200ms. added in 8.0.0

property iDeviceVendorId

the vendor ID to announce for this device. CEC_VENDOR_UNKNOWN (default) to keep libCEC’s default identity. added in 8.0.0

Clear()[source]

Reset this configution struct to the default values.

SetLogCallback(pyfunc)[source]
SetKeyPressCallback(pyfunc)[source]
SetCommandCallback(pyfunc)[source]
SetMenuStateCallback(pyfunc)[source]
SetSourceActivatedCallback(pyfunc)[source]
SetAlertCallback(pyfunc)[source]
SetConfigurationChangedCallback(pyfunc)[source]
SetCommandHandlerCallback(pyfunc)[source]
ClearCallbacks()[source]
class cec.ICECAdapter(*args, **kwargs)[source]

Bases: object

To create a new libCEC instance, call CECInitialise() and pass the configuration as argument. Then call Open() to open a connection to the adapter. Close() closes the connection and CECDestroy() cleans up the libCEC instance.

libCEC can send commands to other devices on the CEC bus via the methods on this interface, and all commands that libCEC received are sent back to the application via callback methods. The callback methods can be found in cectypes.h, ICECCallbacks.

property thisown

The membership flag

Open(strPort, iTimeoutMs=10000)[source]

Open a connection to the CEC adapter. :type strPort: string :param strPort: The path to the port. :type iTimeoutMs: int, optional :param iTimeoutMs: Connection timeout in ms. :rtype: boolean :return: True when connected, false otherwise.

Close()[source]

Close the connection to the CEC adapter.

PingAdapter()[source]

Sends a ping command to the adapter, to check if it’s responding. :rtype: boolean :return: True when the ping was successful, false otherwise.

StartBootloader()[source]

Start the bootloader of the CEC adapter. Closes the connection when successful. :rtype: boolean :return: True when the command was sent successfully, false otherwise.

Transmit(data)[source]

Transmit a raw CEC command over the CEC line. :type data: cec_command :param data: The command to send. :rtype: boolean :return: True when the data was sent and acked, false otherwise.

SetLogicalAddress(*args)[source]

Change the logical address on the CEC bus of the CEC adapter. libCEC automatically assigns a logical address, and this method is only available for debugging purposes. :type iLogicalAddress: int, optional :param iLogicalAddress: The CEC adapter’s new logical address. :rtype: boolean :return: True when the logical address was set successfully, false otherwise.

SetPhysicalAddress(iPhysicalAddress=4096)[source]

Change the physical address (HDMI port) of the CEC adapter. libCEC will try to autodetect the physical address when connecting. If it did, it’s set in libcec_configuration. :type iPhysicalAddress: int, optional :param iPhysicalAddress: The CEC adapter’s new physical address. True when the physical address was set successfully, false otherwise.

PowerOnDevices(*args)[source]

Power on the given CEC capable devices. If CECDEVICE_BROADCAST is used, then wakeDevice in libcec_configuration will be used. :type address: int, optional :param address: The logical address to power on. :rtype: boolean :return: True when the command was sent successfully, false otherwise.

StandbyDevices(*args)[source]

Put the given CEC capable devices in standby mode. If CECDEVICE_BROADCAST is used, then standbyDevices in libcec_configuration will be used. address The logical address of the device to put in standby. :rtype: boolean :return: True when the command was sent successfully, false otherwise.

SetActiveSource(*args)[source]

Change the active source to a device type handled by libCEC. Use CEC_DEVICE_TYPE_RESERVED to make the default type used by libCEC active. :type type: int, optional :param type: The new active source. Leave empty to use the primary type :rtype: boolean :return: True when the command was sent successfully, false otherwise.

SetDeckControlMode(mode, bSendUpdate=True)[source]

Change the deck control mode, if this adapter is registered as playback or recording device. :type mode: int :param mode: The new control mode. :type bSendUpdate: boolean, optional :param bSendUpdate: True to send the new status over the CEC line. :rtype: boolean :return: True if set, false otherwise.

SetDeckInfo(info, bSendUpdate=True)[source]

Change the deck info, if this adapter is a playback or recording device. :type info: int :param info: The new deck info. :type bSendUpdate: boolean, optional :param bSendUpdate: True to send the new status over the CEC line. :rtype: boolean :return: True if set, false otherwise.

SetInactiveView()[source]

Broadcast a message that notifies connected CEC capable devices that this device is no longer the active source. :rtype: boolean :return: True when the command was sent successfully, false otherwise.

SetMenuState(state, bSendUpdate=True)[source]

Change the menu state. This value is already changed by libCEC automatically if a device is (de)activated. :type state: int :param state: The new state. :type bSendUpdate: boolean, optional :param bSendUpdate: True to send the new status over the CEC line. :rtype: boolean :return: True if set, false otherwise.

SetOSDString(iLogicalAddress, duration, strMessage)[source]

Display a message on the device with the given logical address. Not supported by most TVs. :type iLogicalAddress: int :param iLogicalAddress: The logical address of the device to display the message on. :type duration: int :param duration: The duration of the message :type strMessage: string :param strMessage: The message to display. :rtype: boolean :return: True when the command was sent, false otherwise.

SwitchMonitoring(bEnable)[source]

Enable or disable monitoring mode, for debugging purposes. If monitoring mode is enabled, libCEC won’t respond to any command, but only log incoming data. :type bEnable: boolean :param bEnable: True to enable, false to disable. :rtype: boolean :return: True when switched successfully, false otherwise.

GetDeviceCecVersion(iLogicalAddress)[source]

Get the CEC version of the device with the given logical address :type iLogicalAddress: int :param iLogicalAddress: The logical address of the device to get the CEC version for. :rtype: int :return: The version or CEC_VERSION_UNKNOWN when the version couldn’t be fetched.

GetDeviceMenuLanguage(iLogicalAddress)[source]

Get the menu language of the device with the given logical address :type iLogicalAddress: int :param iLogicalAddress: The logical address of the device to get the menu language for. :rtype: string :return: The requested menu language, or ‘???’ if unknown

GetDeviceVendorId(iLogicalAddress)[source]

Get the vendor ID of the device with the given logical address. :type iLogicalAddress: int :param iLogicalAddress: The logical address of the device to get the vendor ID for. :rtype: int :return: The vendor ID or 0 if it wasn’t found.

GetDevicePowerStatus(iLogicalAddress)[source]

Get the power status of the device with the given logical address. :type iLogicalAddress: int :param iLogicalAddress: The logical address of the device to get the power status for. :rtype: int :return: The power status or CEC_POWER_STATUS_UNKNOWN if it wasn’t found.

PollDevice(iLogicalAddress)[source]

Sends a POLL message to a device, to check if it’s present and responding. :type iLogicalAddress: int :param iLogicalAddress: The device to send the message to. :rtype: boolean :return: True if the POLL was acked, false otherwise.

GetActiveDevices()[source]
Return type:

cec_logical_addresses

Returns:

The logical addresses of the devices that are active on the bus, including those handled by libCEC.

IsActiveDevice(iLogicalAddress)[source]

Check whether a device is active on the bus. :type iLogicalAddress: int :param iLogicalAddress: The address to check. :rtype: boolean :return: True when active, false otherwise.

IsActiveDeviceType(type)[source]

Check whether a device of the given type is active on the bus. :type type: int :param type: The type to check. :rtype: boolean :return: True when active, false otherwise.

VolumeUp(bSendRelease=True)[source]

Sends a volume up keypress to an audiosystem if it’s present. :type bSendRelease: boolean, optional :param bSendRelease: Send a key release after the keypress. :rtype: uint8_t :return: The new audio status.

VolumeDown(bSendRelease=True)[source]

Sends a volume down keypress to an audiosystem if it’s present. :type bSendRelease: boolean, optional :param bSendRelease: Send a key release after the keypress. :rtype: uint8_t :return: The new audio status.

MuteAudio()[source]

Toggles the mute status of an audiosystem, if it’s present :rtype: uint8_t :return: The new audio status.

SendKeypress(iDestination, key, bWait=False)[source]

Send a keypress to a device on the CEC bus. :type iDestination: int :param iDestination: The logical address of the device to send the message to. :type key: int :param key: The key to send. :type bWait: boolean, optional :param bWait: True to wait for a response, false otherwise. :rtype: boolean :return: True when the keypress was acked, false otherwise.

SendKeyRelease(iDestination, bWait=False)[source]

Send a key release to a device on the CEC bus. :type iDestination: int :param iDestination: The logical address of the device to send the message to. :type bWait: boolean, optional :param bWait: True to wait for a response, false otherwise. :rtype: boolean :return: True when the key release was acked, false otherwise.

GetDeviceOSDName(iAddress)[source]

Get the OSD name of a device on the CEC bus. :param iLogicalAddress: The device to get the OSD name for. :rtype: string :return: The requested OSD name, or an empty string if unknown

GetActiveSource()[source]

Get the logical address of the device that is currently the active source on the CEC bus. :rtype: int :return: The active source or CECDEVICE_UNKNOWN when unknown.

IsActiveSource(iLogicalAddress)[source]

Check whether a device is currently the active source on the CEC bus. :type iLogicalAddress: int :param iLogicalAddress: The logical address of the device to check. :rtype: boolean :return: True when it is the active source, false otherwise.

SetStreamPath(*args)[source]

Overload 1:

Sets the stream path to the device on the given logical address. :type iLogicalAddress: int :param iLogicalAddress: The address to activate. :rtype: boolean :return: True when the command was sent, false otherwise.


Overload 2:

Sets the stream path to the device on the given physical address. :type iPhysicalAddress: int :param iPhysicalAddress: The address to activate. :rtype: boolean :return: True when the command was sent, false otherwise.

GetLogicalAddresses()[source]
Return type:

cec_logical_addresses

Returns:

The list of logical addresses that libCEC is controlling

GetCurrentConfiguration(configuration)[source]

Get libCEC’s current configuration. :type configuration: libcec_configuration :param configuration: The configuration. :rtype: boolean :return: True when the configuration was updated, false otherwise.

SetConfiguration(configuration)[source]

Change libCEC’s configuration. Store it updated settings in the eeprom of the device (if supported) :type configuration: libcec_configuration :param configuration: The new configuration. :rtype: boolean :return: True when the configuration was changed successfully, false otherwise.

CanSaveConfiguration()[source]
Return type:

boolean

Returns:

True if this CEC adapter can save the user configuration, false otherwise.

RescanActiveDevices()[source]

Tell libCEC to poll for active devices on the bus.

IsLibCECActiveSource()[source]
Return type:

boolean

Returns:

true when libCEC is the active source on the bus, false otherwise.

GetDeviceInformation(strPort, config, iTimeoutMs=10000)[source]

Get information about the given CEC adapter. :type strPort: string :param strPort: The port to which the device is connected :type config: libcec_configuration :param config: The device configuration :type iTimeoutMs: int, optional :param iTimeoutMs: The timeout in milliseconds :rtype: boolean :return: True when the device was found, false otherwise

DisableCallbacks()[source]

Disable all callbacks :rtype: boolean :return: True if disabled, false otherwise.

SetHDMIPort(iBaseDevice, iPort)[source]

Changes the active HDMI port. :type iBaseDevice: int :param iBaseDevice: The device to which this libCEC is connected. :type iPort: uint8_t :param iPort: The new port number. :rtype: boolean :return: True when changed, false otherwise.

GetDevicePhysicalAddress(iLogicalAddress)[source]

Get the physical address of the device with the given logical address. :type iLogicalAddress: int :param iLogicalAddress: The logical address of the device to get the physical address for. :rtype: int :return: The physical address or 0 if it wasn’t found.

GetLibInfo()[source]
Return type:

string

Returns:

A string with information about how libCEC was compiled.

InitVideoStandalone()[source]

Calling this method will initialise the host on which libCEC is running. Calling this method will initialise the host on which libCEC is running. On the RPi, it calls bcm_host_init(), which may only be called once per process, and is called by any process using the video api on that system. So only call this method if libCEC is used in an application that does not already initialise the video api.

Should be called as first call to libCEC, directly after CECInitialise() and before using Open()

GetAdapterVendorId()[source]
Return type:

int

Returns:

The (virtual) USB vendor id

GetAdapterProductId()[source]
Return type:

int

Returns:

The (virtual) USB product id

MenuStateToString(state)[source]
CecVersionToString(version)[source]
PowerStatusToString(status)[source]
LogicalAddressToString(address)[source]
DeckControlModeToString(mode)[source]
DeckInfoToString(status)[source]
OpcodeToString(opcode)[source]
ToString(mode)[source]
AudioStatusToString(status)[source]
DeviceTypeToString(type)[source]
UserControlCodeToString(key)[source]
AdapterTypeToString(type)[source]
VersionToString(version)[source]
PrintVersion(version, buf, bufSize)[source]
VendorIdToString(vendor)[source]
AudioToggleMute()[source]

Toggle the mute status of the AVR (if present) :rtype: uint8_t :return: The new audio status.

AudioMute()[source]

Mute the AVR (if present) :rtype: uint8_t :return: The new audio status.

AudioUnmute()[source]

Mute the AVR (if connected) :rtype: uint8_t :return: The new audio status.

AudioStatus()[source]

Get the current audio status (if an AVR is connected) :rtype: uint8_t :return: The current audio status, or cec_audio_status if unknown.

CommandFromString(strCommand)[source]

Create a new cec_command from a string :type strCommand: string :param strCommand: The string with the command data :rtype: cec_command :return: The command

AudioEnable(enable)[source]

Enable or disable system audio mode :type enable: boolean :param enable: True to enable, false to disable :rtype: boolean :return: True if the command was sent, false otherwise

SystemAudioModeStatus()[source]

Get the current system audio mode status (if an AVR is connected) :rtype: uint8_t :return: The current system audio mode status, or -1 if unknown

GetStats(stats)[source]
static Create(configuration)[source]
DetectAdapters(*args)[source]
cec.CECStartBootloader()[source]

Try to connect to the adapter and send the “start bootloader” command, without initialising libCEC and going through all checks :rtype: boolean :return: True when the command was send, false otherwise.

Index