cecconfig = cec.libcec_configuration()
cecconfig.strDeviceName = "libcec"
cecconfig.bActivateSource = 0
cecconfig.deviceTypes.Add(cec.CEC_DEVICE_TYPE_RECORDING_DEVICE)
cecconfig.clientVersion = cec.LIBCEC_VERSION_CURRENT
cecconfig.SetKeyPressCallback(keypress_callback)
lib = cec.ICECAdapter.Create(cecconfig)
# Wait till we get a CEC device
print("Detecting CEC adapters...")
returned_adapter = None
while returned_adapter is None:
adapters = lib.DetectAdapters()
for adapter in adapters:
print("Found a CEC adapter:")
print("Port: " + adapter.strComName)
print("Vendor: " + hex(adapter.iVendorId))
print("Product: " + hex(adapter.iProductId))
returned_adapter = adapter.strComName
try:
lib.Open(returned_adapter)
print("Connection opened")
main_loop()
except Exception as ex:
print(f"Failure while connecting to the adapter. {type(ex)}")
Most of the time calling lib.Open(returned_adapter) succeeds but sometimes it fails and I get a UnboundLocalError exception. A quick internet search tells me this means a local variable is referenced before it has been assigned. This seems to be a libcec bug?
Using libcec 6.0.2.
Relevant code:
Most of the time calling
lib.Open(returned_adapter)
succeeds but sometimes it fails and I get aUnboundLocalError
exception. A quick internet search tells me this means a local variable is referenced before it has been assigned. This seems to be a libcec bug?