aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>2023-07-20 16:47:46 +0200
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>2023-07-21 20:33:39 +0200
commiteb9816ebe0e0961379a6d271ed7f5203048c7bdf (patch)
tree7fd42008a2128c953fb5c0b5c7b119f55d20c8da
parent1787cee1b32930157eed22bd9bdff4be5be7aa01 (diff)
downloadlibgpiod-eb9816ebe0e0961379a6d271ed7f5203048c7bdf.tar.gz
bindings: python: provide the chip_name property in line_request
Provide a wrapper around gpiod_line_request_get_chip_name() for Python bindings and update the tests. Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
-rw-r--r--bindings/python/gpiod/chip.py1
-rw-r--r--bindings/python/gpiod/ext/request.c11
-rw-r--r--bindings/python/gpiod/line_request.py12
-rw-r--r--bindings/python/tests/tests_line_request.py13
4 files changed, 30 insertions, 7 deletions
diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py
index da93370e..b3d8e614 100644
--- a/bindings/python/gpiod/chip.py
+++ b/bindings/python/gpiod/chip.py
@@ -315,6 +315,7 @@ class Chip:
req_internal = self._chip.request_lines(line_cfg, consumer, event_buffer_size)
request = LineRequest(req_internal)
+ request._chip_name = req_internal.chip_name
request._offsets = req_internal.offsets
request._name_map = name_map
request._offset_map = offset_map
diff --git a/bindings/python/gpiod/ext/request.c b/bindings/python/gpiod/ext/request.c
index a32ff8ff..5db69fe8 100644
--- a/bindings/python/gpiod/ext/request.c
+++ b/bindings/python/gpiod/ext/request.c
@@ -38,6 +38,13 @@ static void request_finalize(request_object *self)
}
static PyObject *
+request_chip_name(request_object *self, void *Py_UNUSED(ignored))
+{
+ return PyUnicode_FromString(
+ gpiod_line_request_get_chip_name(self->request));
+}
+
+static PyObject *
request_num_lines(request_object *self, void *Py_UNUSED(ignored))
{
return PyLong_FromUnsignedLong(
@@ -93,6 +100,10 @@ static PyObject *request_fd(request_object *self, void *Py_UNUSED(ignored))
static PyGetSetDef request_getset[] = {
{
+ .name = "chip_name",
+ .get = (getter)request_chip_name,
+ },
+ {
.name = "num_lines",
.get = (getter)request_num_lines,
},
diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py
index 096bf189..cde298f5 100644
--- a/bindings/python/gpiod/line_request.py
+++ b/bindings/python/gpiod/line_request.py
@@ -212,11 +212,19 @@ class LineRequest:
if not self._req:
return "<LineRequest RELEASED>"
- return "<LineRequest num_lines={} offsets={} fd={}>".format(
- self.num_lines, self.offsets, self.fd
+ return '<LineRequest chip="{}" num_lines={} offsets={} fd={}>'.format(
+ self.chip_name, self.num_lines, self.offsets, self.fd
)
@property
+ def chip_name(self) -> str:
+ """
+ Name of the chip this request was made on.
+ """
+ self._check_released()
+ return self._chip_name
+
+ @property
def num_lines(self) -> int:
"""
Number of requested lines.
diff --git a/bindings/python/tests/tests_line_request.py b/bindings/python/tests/tests_line_request.py
index aa84b9ac..f99b93df 100644
--- a/bindings/python/tests/tests_line_request.py
+++ b/bindings/python/tests/tests_line_request.py
@@ -529,11 +529,14 @@ class LineRequestStringRepresentation(TestCase):
del self.sim
def test_str(self):
- with gpiod.request_lines(self.sim.dev_path, config={(2, 6, 4, 1): None}) as req:
- self.assertEqual(
- str(req),
- "<LineRequest num_lines=4 offsets=[2, 6, 4, 1] fd={}>".format(req.fd),
- )
+ with gpiod.Chip(self.sim.dev_path) as chip:
+ with chip.request_lines(config={(2, 6, 4, 1): None}) as req:
+ self.assertEqual(
+ str(req),
+ '<LineRequest chip="{}" num_lines=4 offsets=[2, 6, 4, 1] fd={}>'.format(
+ self.sim.name, req.fd
+ ),
+ )
def test_str_released(self):
req = gpiod.request_lines(self.sim.dev_path, config={(2, 6, 4, 1): None})