5. Miscelleanous

5.1. Exceptions

Exceptions used by hamas

exception hamas.exceptions.AgentError(*args, **kwargs)

Bases: hamas.exceptions.HamasError

Raised if an agent fails

exception hamas.exceptions.ConnectorError

Bases: FileNotFoundError, hamas.exceptions.HamasError

Raised when a connector is not responding.

exception hamas.exceptions.DeviceHandlerError(*args, **kwargs)

Bases: hamas.exceptions.HamasError

Raised on device handler specific errors

exception hamas.exceptions.HamasError(*args, **kwargs)

Bases: Exception

Base Class for all exceptions defined by hamas

exception hamas.exceptions.MarketError(*args, **kwargs)

Bases: hamas.exceptions.HamasError

Raised on market specific errors

exception hamas.exceptions.PortError(*args, **kwargs)

Bases: hamas.exceptions.HamasError

Raised, when a port is not ready to communicate.

exception hamas.exceptions.TransmissionError(*args, **kwargs)

Bases: hamas.exceptions.HamasError

Raised if a transmission over the air or cable fails

5.2. Logging

Implement the HAMAS Logger.

class hamas.logger.CSVFilter(context)

Bases: object

filter(record)
class hamas.logger.PatternFilter(patterns)

Bases: object

filter(record)
hamas.logger.config_logger(logger_config_file=None)

Call this function to enable a fully configurable logger for this package.

Kwargs:
logger_config_file (str): Path of logging configuration file.

5.3. Helper Functions

Useful functions

hamas.utils.bytes2hexstr(bytestr)

Convert bytes, e.g. a parameter, to a human readable string.

For example, normally b’w’ will be printed as b’w’, which is not wanted for hexadecimal addresses. To avoid this, this method transforms the bytes object b’w’ to the string ‘77’

Parameters:bytestr (bytes) – A bytestring with hexadecimal values.
Returns:A string containing the hexdecimal numbers as string, e.g. b’J’ will become ‘4A’
Return type:hexstring(str)
hamas.utils.bytes2uint(bytestring)
hamas.utils.hexstr2bytes(hexstring)

Convert a hexstring like ‘04’ to b’’

hamas.utils.int2bytes(i)

Convert an int to a byte, like 255 to b’ÿ’