diff --git a/.editorconfig b/.editorconfig index d9c54e2..dc806e6 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,6 +16,3 @@ indent_style = space [*.{yaml,yml,md}] indent_size = 2 - -[.vscode/*.json] -insert_final_newline = false diff --git a/.vscode/settings.json b/.vscode/settings.json index 2148ad5..f9808e9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,6 @@ { + "python.linting.mypyEnabled": true, + "python.formatting.provider": "black", "editor.formatOnSave": true, - "pylint.args": [ - "--disable=missing-function-docstring,missing-class-docstring,missing-module-docstring" - ], - "python.testing.unittestEnabled": false, - "python.testing.pytestEnabled": true -} \ No newline at end of file + "python.linting.flake8Enabled": true +} diff --git a/misc/render_rrd.py b/misc/render_rrd.py index 20d3553..2ca196e 100644 --- a/misc/render_rrd.py +++ b/misc/render_rrd.py @@ -5,7 +5,7 @@ from ast import literal_eval from collections import namedtuple from typing import Any, Dict -import rrdtool # type: ignore +import rrdtool from srnemqtt.solar_types import DataName @@ -147,6 +147,7 @@ def rrdupdate(file: str, timestamp: int, data: dict): def re_read(): + rrdtool.create( RRDFILE, # "--no-overwrite", diff --git a/misc/test_bleuart.py b/misc/test_bleuart.py index 0d074d6..1f28414 100644 --- a/misc/test_bleuart.py +++ b/misc/test_bleuart.py @@ -4,6 +4,7 @@ from srnemqtt.lib.feasycom_ble import BTLEUart from srnemqtt.protocol import construct_request, write with BTLEUart(MAC, timeout=1) as x: + print(x) write(x, construct_request(0x0E, words=3)) diff --git a/misc/test_serial.py b/misc/test_serial.py index 49c6f11..7ea6505 100644 --- a/misc/test_serial.py +++ b/misc/test_serial.py @@ -3,7 +3,7 @@ import os import sys from time import sleep -from serial import Serial # type: ignore +from serial import Serial print(sys.path) sys.path.insert(1, os.path.dirname(os.path.dirname(sys.argv[0]))) diff --git a/misc/test_serial_loopback.py b/misc/test_serial_loopback.py index 590a14f..3351171 100644 --- a/misc/test_serial_loopback.py +++ b/misc/test_serial_loopback.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from serial import Serial # type: ignore +from serial import Serial with Serial("/dev/ttyUSB0", baudrate=9600, timeout=2) as x: x.write(b"Hello, World!") diff --git a/srnemqtt/__main__.py b/srnemqtt/__main__.py index 339bd0e..38d8058 100755 --- a/srnemqtt/__main__.py +++ b/srnemqtt/__main__.py @@ -5,8 +5,8 @@ import time from decimal import Decimal from typing import cast -from bluepy.btle import BTLEDisconnectError # type: ignore -from serial import SerialException # type: ignore +from bluepy.btle import BTLEDisconnectError +from serial import SerialException from .config import get_config, get_consumers, get_interface from .protocol import parse_battery_state, parse_historical_entry, try_read_parse diff --git a/srnemqtt/interfaces/serial.py b/srnemqtt/interfaces/serial.py index 82af005..bee3ff6 100644 --- a/srnemqtt/interfaces/serial.py +++ b/srnemqtt/interfaces/serial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -import serial # type: ignore +import serial from . import BaseInterface diff --git a/srnemqtt/lib/feasycom_ble.py b/srnemqtt/lib/feasycom_ble.py index 63317c2..2f7f262 100644 --- a/srnemqtt/lib/feasycom_ble.py +++ b/srnemqtt/lib/feasycom_ble.py @@ -4,7 +4,7 @@ import queue import time from typing import TYPE_CHECKING, Optional, cast -from bluepy import btle # type: ignore +from bluepy import btle if TYPE_CHECKING: from _typeshed import ReadableBuffer, WriteableBuffer diff --git a/srnemqtt/protocol.py b/srnemqtt/protocol.py index c8c2241..160da0b 100644 --- a/srnemqtt/protocol.py +++ b/srnemqtt/protocol.py @@ -5,7 +5,7 @@ import time from io import RawIOBase from typing import Callable, Collection, Optional -from libscrc import modbus # type: ignore +from libscrc import modbus from .constants import ACTION_READ, POSSIBLE_MARKER from .lib.feasycom_ble import BTLEUart @@ -84,6 +84,7 @@ def discardUntil(fh: RawIOBase, byte: int, timeout=10) -> Optional[int]: discarded = 0 read_byte = expand(fh.read(1)) while read_byte != byte: + if read_byte is not None: if not discarded: log("Discarding", end="") diff --git a/tests/test_protocol.py b/tests/test_protocol.py deleted file mode 100644 index f375394..0000000 --- a/tests/test_protocol.py +++ /dev/null @@ -1,11 +0,0 @@ -from io import BytesIO - -from srnemqtt.protocol import write as protocol_write - - -def test_write(): - fh = BytesIO() - protocol_write(fh, b"Hello, World!") - fh.seek(0) - - assert fh.read() == b"Hello, World!\x4E\x11" diff --git a/tox.ini b/tox.ini index 8a5a3ef..edfab12 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,3 @@ [flake8] max-line-length = 88 extend-ignore = E203, I201, I101 - -[pytest] -pythonpath = . -testpaths = tests