docs: add missing docstrings to classes and methods

Added docstrings to:
- Error classes (RevPiModIOError, DeviceNotFoundError)
- ProductType constants class
- GatewayMixin class for piGate module detection
- IO __call__ methods (IOBase, IntIO, StructIO)
- MemIO.get_variantvalue method
- RevPiModIO context manager methods (__enter__, __exit__)
This commit is contained in:
Nicolai Buchwitz
2026-02-03 16:13:07 +01:00
committed by Sven Sager
parent 2eac69b7bd
commit bf631ea176
5 changed files with 47 additions and 0 deletions

View File

@@ -572,6 +572,8 @@ class Base(Device):
class GatewayMixin: class GatewayMixin:
"""Mixin class providing piGate module detection functionality."""
@property @property
def leftgate(self) -> bool: def leftgate(self) -> bool:
""" """

View File

@@ -6,8 +6,12 @@ __license__ = "LGPLv2"
class RevPiModIOError(Exception): class RevPiModIOError(Exception):
"""Base exception class for RevPiModIO errors."""
pass pass
class DeviceNotFoundError(RevPiModIOError): class DeviceNotFoundError(RevPiModIOError):
"""Raised when a requested device cannot be found in the configuration."""
pass pass

View File

@@ -493,6 +493,12 @@ class IOBase(object):
return any(self._parentdevice._ba_devdata[self._slc_address]) return any(self._parentdevice._ba_devdata[self._slc_address])
def __call__(self, value=None): def __call__(self, value=None):
"""
Get or set the IO value using function call syntax.
:param value: If None, returns current value; otherwise sets the value
:return: Current IO value when called without arguments
"""
if value is None: if value is None:
# Inline get_value() # Inline get_value()
if self._bitshift: if self._bitshift:
@@ -978,6 +984,13 @@ class IntIO(IOBase):
) )
def __call__(self, value=None): def __call__(self, value=None):
"""
Get or set the integer IO value using function call syntax.
:param value: If None, returns current integer value; otherwise sets the integer value
:return: Current IO value as integer when called without arguments
:raises TypeError: If value is not an integer
"""
if value is None: if value is None:
# Inline get_intvalue() # Inline get_intvalue()
return int.from_bytes( return int.from_bytes(
@@ -1447,6 +1460,14 @@ class StructIO(IOBase):
raise BufferError("registered value does not fit process image scope") raise BufferError("registered value does not fit process image scope")
def __call__(self, value=None): def __call__(self, value=None):
"""
Get or set the structured IO value using function call syntax.
Handles byte and word order conversion based on configuration.
:param value: If None, returns current value unpacked using struct format; otherwise packs and sets the value
:return: Current IO value unpacked according to struct format when called without arguments
"""
if value is None: if value is None:
# Inline get_structdefaultvalue() # Inline get_structdefaultvalue()
if self._bitshift: if self._bitshift:
@@ -1567,6 +1588,13 @@ class MemIO(IOBase):
""" """
def get_variantvalue(self): def get_variantvalue(self):
"""
Get the default value as either string or integer based on bit length.
For values > 64 bits, returns as decoded string. Otherwise returns as integer.
:return: Default value as string (if > 64 bits) or integer
"""
val = bytes(self._defaultvalue) val = bytes(self._defaultvalue)
if self._bitlength > 64: if self._bitlength > 64:

View File

@@ -208,6 +208,12 @@ class RevPiModIO(object):
self._myfh.close() self._myfh.close()
def __enter__(self): def __enter__(self):
"""
Context manager entry (deprecated).
.. deprecated::
Use ``with revpi.io:`` or ``with revpi.device.my_device:`` instead.
"""
# todo: Remove this context manager in future # todo: Remove this context manager in future
warnings.warn( warnings.warn(
"This context manager is deprecated and will be removed!\n\n" "This context manager is deprecated and will be removed!\n\n"
@@ -231,6 +237,11 @@ class RevPiModIO(object):
return self return self
def __exit__(self, exc_type, exc_val, exc_tb): def __exit__(self, exc_type, exc_val, exc_tb):
"""
Context manager exit (deprecated).
Writes process image and performs cleanup.
"""
if not self._monitoring: if not self._monitoring:
self.writeprocimg() self.writeprocimg()
self.exit(full=True) self.exit(full=True)

View File

@@ -15,6 +15,8 @@ __license__ = "LGPLv2"
class ProductType: class ProductType:
"""Product type constants for Revolution Pi devices and modules."""
CON_BT = 111 CON_BT = 111
CON_CAN = 109 CON_CAN = 109
CON_MBUS = 110 CON_MBUS = 110