From: Bartosz Golaszewski Date: Sat, 14 Sep 2019 13:29:48 +0000 (+0200) Subject: bindings: python: provide Line.update() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=4029c34f5c90b47653fa518fec8e54d0ef47b03d;p=qemu-gpiodev%2Flibgpiod.git bindings: python: provide Line.update() Python bindings are missing the functionality provided by the core C library's gpiod_line_update(). Extend the Line class with the update() method that allows to re-read the line information from the kernel. Signed-off-by: Bartosz Golaszewski --- diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c index deeba10..69edbbc 100644 --- a/bindings/python/gpiodmodule.c +++ b/bindings/python/gpiodmodule.c @@ -582,6 +582,25 @@ static PyObject *gpiod_Line_release(gpiod_LineObject *self, return ret; } +PyDoc_STRVAR(gpiod_Line_update_doc, +"update() -> None\n" +"\n" +"Re-read the line information from the kernel."); + +static PyObject *gpiod_Line_update(gpiod_LineObject *self, + PyObject *Py_UNUSED(ignored)) +{ + int ret; + + ret = gpiod_line_update(self->line); + if (ret) { + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + + Py_RETURN_NONE; +} + PyDoc_STRVAR(gpiod_Line_event_wait_doc, "event_wait([sec[ ,nsec]]) -> boolean\n" "\n" @@ -783,6 +802,12 @@ static PyMethodDef gpiod_Line_methods[] = { .ml_flags = METH_NOARGS, .ml_doc = gpiod_Line_release_doc, }, + { + .ml_name = "update", + .ml_meth = (PyCFunction)gpiod_Line_update, + .ml_flags = METH_NOARGS, + .ml_doc = gpiod_Line_update_doc, + }, { .ml_name = "event_wait", .ml_meth = (PyCFunction)(void (*)(void))gpiod_Line_event_wait, diff --git a/bindings/python/tests/gpiod_py_test.py b/bindings/python/tests/gpiod_py_test.py index 8533bae..ed31c8e 100755 --- a/bindings/python/tests/gpiod_py_test.py +++ b/bindings/python/tests/gpiod_py_test.py @@ -307,6 +307,11 @@ class LineInfo(MockupTestCase): self.assertTrue(line.is_open_drain()) self.assertFalse(line.is_open_source()) + def test_update_line_info(self): + with gpiod.Chip(mockup.chip_name(0)) as chip: + line = chip.get_line(3) + line.update() + class LineValues(MockupTestCase): chip_sizes = ( 8, )