Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 30, 2023
1 parent f5e41f7 commit 76aec5f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 41 deletions.
30 changes: 16 additions & 14 deletions uoshardware/abstractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,13 @@ class UOSInterface(metaclass=ABCMeta):
def execute_instruction(self, packet: NPCPacket) -> ComResult: # dead: disable
"""Abstract method for executing instructions on UOSInterfaces.
:param packet: A tuple containing the uint8 npc packet for the UOS instruction.
:param packet: A tuple containing the uint8 npc packet for the
UOS instruction.
:returns: ComResult object.
:raises: UOSUnsupportedError if the interface hasn't been built
correctly.
correctly.
:raises: UOSCommunicationError if there is a problem completing
the action.
the action.
"""
raise UOSUnsupportedError(
"UOSInterfaces must over-ride "
Expand All @@ -201,12 +202,13 @@ def read_response(
"""Read ACK and Data packets from a UOSInterface.
:param expect_packets: How many packets including ACK to expect
:param timeout_s: The maximum time this function will wait for data.
:param timeout_s: The maximum time this function will wait for
data.
:return: COM Result object.
:raises: UOSUnsupportedError if the interface hasn't been built
correctly.
correctly.
:raises: UOSCommunicationError if there is a problem completing
the action.
the action.
"""
raise UOSUnsupportedError(
"UOSInterfaces must over-ride "
Expand All @@ -219,9 +221,9 @@ def hard_reset(self) -> ComResult:
:return: COM Result object.
:raises: UOSUnsupportedError if the interface hasn't been built
correctly.
correctly.
:raises: UOSCommunicationError if there is a problem completing
the action.
the action.
"""
raise UOSUnsupportedError(
"UOSInterfaces must over-ride "
Expand All @@ -233,9 +235,9 @@ def open(self):
"""Abstract method for opening a connection to a UOSInterface.
:raises: UOSUnsupportedError if the interface hasn't been built
correctly.
correctly.
:raises: UOSCommunicationError if there is a problem completing
the action.
the action.
"""
raise UOSUnsupportedError(
"UOSInterfaces must over-ride " f"{UOSInterface.open.__name__} prototype."
Expand All @@ -246,9 +248,9 @@ def close(self):
"""Abstract method for closing a connection to a UOSInterface.
:raises: UOSUnsupportedError if the interface hasn't been built
correctly.
correctly.
:raises: UOSCommunicationError if there is a problem completing
the action.
the action.
"""
raise UOSUnsupportedError(
"UOSInterfaces must over-ride " f"{UOSInterface.close.__name__} prototype."
Expand All @@ -260,7 +262,7 @@ def is_active(self) -> bool:
:return: Success boolean.
:raises: UOSUnsupportedError if the interface hasn't been built
correctly.
correctly.
"""
raise UOSUnsupportedError(
"UOSInterfaces must over-ride " f"{UOSInterface.close.__name__} prototype."
Expand All @@ -273,7 +275,7 @@ def enumerate_devices() -> list:
:return: A list of possible UOSInterfaces on the server.
:raises: UOSUnsupportedError if the interface hasn't been built
correctly.
correctly.
"""
raise UOSUnsupportedError(
"UOSInterfaces must over-ride "
Expand Down
34 changes: 20 additions & 14 deletions uoshardware/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def enumerate_system_devices( # dead: disable
"""Iterate through all interfaces and locates available devices.
:param interface_filter: Interface enum to limit the search to a
single interface type.
single interface type.
:return: A list of uosinterface objects.
"""
system_devices = []
Expand All @@ -44,7 +44,8 @@ def enumerate_system_devices( # dead: disable
def get_device_definition(identity: str) -> Device | None:
"""Look up the system config dictionary for the defined device mappings.
:param identity: String containing the lookup key of the device in the dictionary.
:param identity: String containing the lookup key of the device in
the dictionary.
:return: Device Object or None if not found
"""
if identity is not None and hasattr(Devices, identity):
Expand All @@ -58,9 +59,9 @@ def get_device_definition(identity: str) -> Device | None:
class UOSDevice: # dead: disable
"""Class for high level object-orientated control of UOS devices.
:ivar identity: The type of device, this is must have a valid device in the config.
:ivar address: Compliant connection string for identifying the
device and interface.
:ivar identity: The type of device, this is must have a valid device
in the config. :ivar address: Compliant connection string for
identifying the device and interface.
"""

__device: Device # Device definitions as parsed from a compatible ini.
Expand Down Expand Up @@ -165,10 +166,11 @@ def get_gpio_input(
"""Read a GPIO pins level from device and returns the value.
:param pin: The numeric number of the pin as defined in the
dictionary for that device.
:param pull_up: Enable the internal pull-up resistor. Default is false.
dictionary for that device.
:param pull_up: Enable the internal pull-up resistor. Default is
false.
:param volatility: How volatile should the command be, use
constants from uoshardware.
constants from uoshardware.
:return: ComResult object.
"""
result = self.__execute_instruction(
Expand Down Expand Up @@ -219,8 +221,9 @@ def reset_all_io(self, volatility=Persistence.RAM) -> ComResult:
"""Execute the reset IO at the defined volatility level.
:param volatility: Where should the pins reset from, use
constants from uoshardware.
:return: ComResult object containing the result of the reset operation..
constants from uoshardware.
:return: ComResult object containing the result of the reset
operation..
"""
return self.__execute_instruction(
UOSFunctions.reset_all_io,
Expand Down Expand Up @@ -258,11 +261,13 @@ def __execute_instruction(
"""Execute a generic UOS function and get the result.
:param function: The name of the function in the OOL.
:param instruction_data: device_functions from the LUT, payload ect.
:param retry: Allows the instruction to retry execution when fails.
:param instruction_data: device_functions from the LUT, payload
ect.
:param retry: Allows the instruction to retry execution when
fails.
:return: ComResult object
:raises: UOSUnsupportedError if function is not possible on the
loaded device.
loaded device.
"""
if (
function.name not in self.__device.functions_enabled
Expand Down Expand Up @@ -373,7 +378,8 @@ def get_compatible_pins(self, function: UOSFunction) -> set:
def get_functions_enabled(self) -> dict: # dead: disable
"""Return functions enabled for the device.
:return: Dictionary of function names to list of Persistence levels.
:return: Dictionary of function names to list of Persistence
levels.
"""
return self.__device.functions_enabled

Expand Down
5 changes: 2 additions & 3 deletions uoshardware/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
class Devices:
"""Names for supported hardware linking to the Device object used.
:cvar hwid_0: device: _ARDUINO_NANO_3
:cvar arduino_nano: device: _ARDUINO_NANO_3
:cvar arduino_uno: device: _ARDUINO_NANO_3
:cvar hwid_0: device: _ARDUINO_NANO_3 :cvar arduino_nano: device:
_ARDUINO_NANO_3 :cvar arduino_uno: device: _ARDUINO_NANO_3
"""

# Lookup constants linking devices to importable names
Expand Down
23 changes: 13 additions & 10 deletions uoshardware/interface/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
class Serial(UOSInterface):
"""Pyserial class that handles reading / writing to ports.
:ivar _device: Holds the pyserial device once opened. None if not opened.
:ivar _connection: Holds the standard connection string
'Interface'|'OS Connection String.
:ivar _port: Holds the port class, none type if device not instantiated.
:ivar _kwargs: Additional keyword arguments as defined in the documentation.
:ivar _device: Holds the pyserial device once opened. None if not
opened. :ivar _connection: Holds the standard connection string
'Interface'|'OS Connection String. :ivar _port: Holds the port
class, none type if device not instantiated. :ivar _kwargs:
Additional keyword arguments as defined in the documentation.
"""

_device = None
Expand Down Expand Up @@ -100,9 +100,10 @@ def close(self):
def execute_instruction(self, packet: NPCPacket):
"""Build and execute a new instruction packet.
:param packet: A tuple containing the uint8 npc packet for the UOS instruction.
:param packet: A tuple containing the uint8 npc packet for the
UOS instruction.
:return: Tuple containing a status boolean and index 0 and a
result-set dict at index 1.
result-set dict at index 1.
"""
if self._device is None:
raise UOSCommunicationError(
Expand All @@ -124,7 +125,8 @@ def read_response(self, expect_packets: int, timeout_s: float):
"""Read ACK and response packets from the serial device.
:param expect_packets: How many packets including ACK to expect.
:param timeout_s: The maximum time this function will wait for data.
:param timeout_s: The maximum time this function will wait for
data.
:return: ComResult object.
"""
if self._device is None:
Expand Down Expand Up @@ -173,7 +175,7 @@ def hard_reset(self):
"""Manually drive the DTR line low to reset the device.
:return: Tuple containing a status boolean and index 0 and a
result-set dict at index 1.
result-set dict at index 1.
"""
if self._device is None:
raise UOSCommunicationError("Connection must be open to hard reset device.")
Expand Down Expand Up @@ -206,7 +208,8 @@ def decode_and_capture(
:param byte_index: The index of the last 'valid' byte found.
:param byte_in: The current byte for inspection.
:param packet: The current packet of validated bytes.
:return: Tuple containing the updated byte index and updated packet.
:return: Tuple containing the updated byte index and updated
packet.
"""
if byte_index == -1: # start symbol
if byte_in == b">":
Expand Down

0 comments on commit 76aec5f

Please sign in to comment.