Skip to content

ValueError with GTK client. #91

@jhcole

Description

@jhcole

This error occurs with the current git version, Python 3.12, and an AnkerWork C310 Webcam.

/tmp/cameractrls$ ./cameractrlsgtk.py 
WARNING:root:Control ankerwork_fov: Can't find ? in ['65', '78', '95', 'auto']
Traceback (most recent call last):
  File "/tmp/cameractrls/./cameractrlsgtk.py", line 517, in update_ctrl
    self.camera.setup_ctrls({ctrl.text_id: value}, errs)
  File "/tmp/cameractrls/cameractrls.py", line 3178, in setup_ctrls
    c.setup_ctrls(params, errs)
  File "/tmp/cameractrls/cameractrls.py", line 2068, in setup_ctrls
    desired = to_buf(self._bytes_from_int(int(menu.value), ctrl.length))
                                          ^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: b'\x00\x01_\x00\x00\x00\x00'

Interestingly, after implementing the workaround below, the initial warning still occurred. But after changing the FOV setting once, that warning went away on subsequent runs. I think the factory setting didn't match any of the menu options, but I don't know what it was set to. After implementing the workaround, all FOV menu settings work and no errors or warnings are emitted.

$ git diff cameractrls.py
diff --git a/cameractrls.py b/cameractrls.py
index ed3e8b7..e69fc51 100755
--- a/cameractrls.py
+++ b/cameractrls.py
@@ -2065,7 +2065,11 @@ class AnkerWorkCtrls:
                     desired = current_config
                     desired[0] = menu.value
                 else:
-                    desired = to_buf(self._bytes_from_int(int(menu.value), ctrl.length))
+                    # menu.value can be either bytes or a string representation of an int
+                    if isinstance(menu.value, bytes):
+                        desired = to_buf(menu.value)
+                    else:
+                        desired = to_buf(self._bytes_from_int(int(menu.value), ctrl.length))
             elif ctrl.type == 'integer':
                 if ctrl.text_id == 'ankerwork_face_compensation_value':
                     cur_enable = self._int_from_bytes(current_config) & 0xff

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions