Skip to content

Commit

Permalink
flake 8 compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
favalex committed Nov 23, 2021
1 parent 8041d29 commit 0cfe88e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
9 changes: 6 additions & 3 deletions modbus_cli/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def write_registers_send(self, modbus):
if self.modbus_type == 'c':
if len(self.values_to_write) == 1:
# TODO validate value, should be boolean
message = modbus.protocol.write_single_coil(modbus.slave_id, self.address(), int(self.values_to_write[0]))
message = modbus.protocol.write_single_coil(
modbus.slave_id, self.address(), int(self.values_to_write[0]))
else:
message = modbus.protocol.write_multiple_coils(modbus.slave_id, self.address(),
[int(v) for v in self.values_to_write])
Expand Down Expand Up @@ -217,7 +218,8 @@ def __str__(self):
'={}'.format(self.values_to_write) if self.write else '')

def __repr__(self):
return 'Access({!r}, {!r}, {!r}, {!r}, {!r})'.format(self.modbus_type, self.addresses, self.pack_types, self.values_to_write, self.names)
return 'Access({!r}, {!r}, {!r}, {!r}, {!r})'.format(
self.modbus_type, self.addresses, self.pack_types, self.values_to_write, self.names)


def by_type(access):
Expand Down Expand Up @@ -281,7 +283,8 @@ def parse_access(register, name, write, value, byte_order):
if write and modbus_type not in 'ch':
raise ValueError("Invalid Modbus type '{}'. Only coils and holding registers are writable".format(modbus_type))

return Access(modbus_type, [address], [pack_type], [value], names=[name], presenters=[presenter], byte_order=byte_order)
return Access(modbus_type, [address], [pack_type], [value],
names=[name], presenters=[presenter], byte_order=byte_order)


def parse_accesses(s, definitions, byte_order='be'):
Expand Down
2 changes: 1 addition & 1 deletion modbus_cli/definitions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import logging

REGISTER_RE = re.compile('([cdhi]@)?(\d+)(/[^:|]*)?([:|].*)?')
REGISTER_RE = re.compile(r'([cdhi]@)?(\d+)(/[^:|]*)?([:|].*)?')


class Definitions:
Expand Down
14 changes: 7 additions & 7 deletions modbus_cli/modbus_rtu.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class ModbusRtu:
def __init__(self, device, baud, parity, stop_bits, slave_id, timeout):
from serial import PARITY_EVEN, PARITY_ODD, PARITY_NONE
parity_opts = { 'e': PARITY_EVEN, 'o': PARITY_ODD, 'n': PARITY_NONE }
parity_opts = {'e': PARITY_EVEN, 'o': PARITY_ODD, 'n': PARITY_NONE}
self.device = device
self.timeout = timeout
self.baud = baud
Expand All @@ -23,12 +23,12 @@ def connect(self):
from serial import Serial

logging.debug("Serial port %s. Parameters: %s baud, %s stop bit(s), parity: %s, timeout %ss.",
self.device,
self.baud,
self.stop_bits,
self.parity,
self.timeout,
)
self.device,
self.baud,
self.stop_bits,
self.parity,
self.timeout,
)

self.connection = Serial(port=self.device, baudrate=self.baud, parity=self.parity,
stopbits=self.stop_bits, bytesize=8, timeout=self.timeout)
Expand Down

0 comments on commit 0cfe88e

Please sign in to comment.