satisfy pycodestyle checker

This commit is contained in:
Wolfgang Hottgenroth
2022-02-22 14:58:11 +01:00
parent 9e28ffacde
commit 4b8a15b454
8 changed files with 27 additions and 27 deletions

View File

@ -1,12 +1,14 @@
import re
import json
class InvalidDataObjectException(Exception):
def __init__(self, message):
super().__init__(message)
class AbstractDataObject(object):
invalidChars = re.compile("[#+\s]")
invalidChars = re.compile(r'[#+\s]')
def __init__(self, topicPart):
self.topicPart = topicPart

View File

@ -4,7 +4,6 @@ from AbstractDataObject import AbstractDataObject
class FlatDataObject(AbstractDataObject):
def __init__(self, serverName, nameSpaceIndex, variableName, value):
super().__init__(serverName + '/' + str(nameSpaceIndex) + '/' + variableName)
self.serverName = serverName

View File

@ -4,13 +4,14 @@ import threading
import ssl
def mqttOnConnectCallback(client, userdata, flags, rc):
userdata.onConnect()
def mqttOnMessageCallback(client, userdata, message):
userdata.onMessage(message.topic, message.payload)
def mqttOnDisconnectCallback(client, userdata, rc):
userdata.onDisconnect(rc)
@ -42,17 +43,16 @@ class AbstractMqttPublisher(threading.Thread):
keyfile=self.config["key"],
cert_reqs=ssl.CERT_REQUIRED,
tls_version=ssl.PROTOCOL_TLSv1_2,
ciphers=None # this does not mean "no cipher" but it means "default ciphers"
ciphers=None # this does not mean "no cipher" but it means "default ciphers"
)
elif ("ca" in self.config):
self.client.tls_set(
ca_certs=self.config["ca"],
cert_reqs=ssl.CERT_REQUIRED,
tls_version=ssl.PROTOCOL_TLSv1_2,
ciphers=None # this does not mean "no cipher" but it means "default ciphers"
ciphers=None # this does not mean "no cipher" but it means "default ciphers"
)
self.client.connect(self.config["broker"], int(self.config["port"]))
self.client.loop_start()
logger.info("mqtt loop started")
@ -80,4 +80,3 @@ class AbstractMqttPublisher(threading.Thread):
def onMessage(self, topic, payload):
logger.warning("mqtt unexpected message received: {} -> {}".format(topic, str(payload)))

View File

@ -7,6 +7,7 @@ import json
LOOP_SLICE = 0.1 # seconds
class MqttPublish(AbstractMqttPublisher):
def __init__(self, config, stats, queue):
super().__init__(config)
@ -32,4 +33,3 @@ class MqttPublish(AbstractMqttPublisher):
except Exception as e:
self.stats.incMqttErrors()
logger.error(f"Exception {type(e)} received in MQTT local loop: {e}")

View File

@ -5,6 +5,7 @@ from loguru import logger
from FlatDataObject import FlatDataObject
from StructuredDataObject import StructuredDataObject
class OpcUaRequester(threading.Thread):
def __init__(self, config, stats, queue):
super().__init__()
@ -25,7 +26,6 @@ class OpcUaRequester(threading.Thread):
self.killBill = False
self.killEvent = threading.Event()
async def opcUaRequesterInnerLoop(self):
while not self.killBill:
try:
@ -69,4 +69,3 @@ class OpcUaRequester(threading.Thread):
self.killEvent.set()
logger.info("kill events triggered")

View File

@ -4,6 +4,7 @@ from AbstractDataObject import AbstractDataObject
import json
import datetime
class StatisticsDataObject(AbstractDataObject):
def __init__(self, topic, payload):
super().__init__(topic)
@ -27,7 +28,7 @@ class StatisticsCollector(threading.Thread):
self.stats = {
'opcUaRequests': 0,
'opcUaErrors' : 0,
'opcUaErrors': 0,
'opcUaTimeouts': 0,
'mqttRequests': 0,
'mqttErrors': 0,
@ -63,4 +64,3 @@ class StatisticsCollector(threading.Thread):
self.stats['uptime'] = int((currentTime - startTime).total_seconds())
self.queue.put(StatisticsDataObject(self.topic, self.stats))
self.killEvent.wait(timeout=float(self.period))

View File

@ -4,7 +4,6 @@ from AbstractDataObject import AbstractDataObject
class StructuredDataObject(AbstractDataObject):
def __init__(self, topicPart):
super().__init__(topicPart)
self.keyValuePairs = []

View File

@ -12,12 +12,14 @@ import signal
deathBell = threading.Event()
def exceptHook(args):
global deathBell
logger.error("Exception in thread caught: {}".format(args))
deathBell.set()
logger.error("rang the death bell")
def terminateHook(sig, frame):
global deathBell
logger.error("SIGINT received")