Compare commits
3 commits
140acba1f5
...
3c8942b485
Author | SHA1 | Date | |
---|---|---|---|
3c8942b485 | |||
7977d89abf | |||
b6a62d123d |
12 changed files with 32 additions and 15 deletions
|
@ -16,3 +16,6 @@ indent_style = space
|
||||||
|
|
||||||
[*.{yaml,yml,md}]
|
[*.{yaml,yml,md}]
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
|
||||||
|
[.vscode/*.json]
|
||||||
|
insert_final_newline = false
|
||||||
|
|
8
.vscode/settings.json
vendored
8
.vscode/settings.json
vendored
|
@ -1,6 +1,8 @@
|
||||||
{
|
{
|
||||||
"python.linting.mypyEnabled": true,
|
|
||||||
"python.formatting.provider": "black",
|
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
"python.linting.flake8Enabled": true
|
"pylint.args": [
|
||||||
|
"--disable=missing-function-docstring,missing-class-docstring,missing-module-docstring"
|
||||||
|
],
|
||||||
|
"python.testing.unittestEnabled": false,
|
||||||
|
"python.testing.pytestEnabled": true
|
||||||
}
|
}
|
|
@ -5,7 +5,7 @@ from ast import literal_eval
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
|
|
||||||
import rrdtool
|
import rrdtool # type: ignore
|
||||||
|
|
||||||
from srnemqtt.solar_types import DataName
|
from srnemqtt.solar_types import DataName
|
||||||
|
|
||||||
|
@ -147,7 +147,6 @@ def rrdupdate(file: str, timestamp: int, data: dict):
|
||||||
|
|
||||||
|
|
||||||
def re_read():
|
def re_read():
|
||||||
|
|
||||||
rrdtool.create(
|
rrdtool.create(
|
||||||
RRDFILE,
|
RRDFILE,
|
||||||
# "--no-overwrite",
|
# "--no-overwrite",
|
||||||
|
|
|
@ -4,7 +4,6 @@ from srnemqtt.lib.feasycom_ble import BTLEUart
|
||||||
from srnemqtt.protocol import construct_request, write
|
from srnemqtt.protocol import construct_request, write
|
||||||
|
|
||||||
with BTLEUart(MAC, timeout=1) as x:
|
with BTLEUart(MAC, timeout=1) as x:
|
||||||
|
|
||||||
print(x)
|
print(x)
|
||||||
|
|
||||||
write(x, construct_request(0x0E, words=3))
|
write(x, construct_request(0x0E, words=3))
|
||||||
|
|
|
@ -3,7 +3,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from serial import Serial
|
from serial import Serial # type: ignore
|
||||||
|
|
||||||
print(sys.path)
|
print(sys.path)
|
||||||
sys.path.insert(1, os.path.dirname(os.path.dirname(sys.argv[0])))
|
sys.path.insert(1, os.path.dirname(os.path.dirname(sys.argv[0])))
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from serial import Serial
|
from serial import Serial # type: ignore
|
||||||
|
|
||||||
with Serial("/dev/ttyUSB0", baudrate=9600, timeout=2) as x:
|
with Serial("/dev/ttyUSB0", baudrate=9600, timeout=2) as x:
|
||||||
x.write(b"Hello, World!")
|
x.write(b"Hello, World!")
|
||||||
|
|
|
@ -5,8 +5,8 @@ import time
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
from bluepy.btle import BTLEDisconnectError
|
from bluepy.btle import BTLEDisconnectError # type: ignore
|
||||||
from serial import SerialException
|
from serial import SerialException # type: ignore
|
||||||
|
|
||||||
from .config import get_config, get_consumers, get_interface
|
from .config import get_config, get_consumers, get_interface
|
||||||
from .protocol import parse_battery_state, parse_historical_entry, try_read_parse
|
from .protocol import parse_battery_state, parse_historical_entry, try_read_parse
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import serial
|
import serial # type: ignore
|
||||||
|
|
||||||
from . import BaseInterface
|
from . import BaseInterface
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import queue
|
||||||
import time
|
import time
|
||||||
from typing import TYPE_CHECKING, Optional, cast
|
from typing import TYPE_CHECKING, Optional, cast
|
||||||
|
|
||||||
from bluepy import btle
|
from bluepy import btle # type: ignore
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from _typeshed import ReadableBuffer, WriteableBuffer
|
from _typeshed import ReadableBuffer, WriteableBuffer
|
||||||
|
|
|
@ -5,7 +5,7 @@ import time
|
||||||
from io import RawIOBase
|
from io import RawIOBase
|
||||||
from typing import Callable, Collection, Optional
|
from typing import Callable, Collection, Optional
|
||||||
|
|
||||||
from libscrc import modbus
|
from libscrc import modbus # type: ignore
|
||||||
|
|
||||||
from .constants import ACTION_READ, POSSIBLE_MARKER
|
from .constants import ACTION_READ, POSSIBLE_MARKER
|
||||||
from .lib.feasycom_ble import BTLEUart
|
from .lib.feasycom_ble import BTLEUart
|
||||||
|
@ -84,7 +84,6 @@ def discardUntil(fh: RawIOBase, byte: int, timeout=10) -> Optional[int]:
|
||||||
discarded = 0
|
discarded = 0
|
||||||
read_byte = expand(fh.read(1))
|
read_byte = expand(fh.read(1))
|
||||||
while read_byte != byte:
|
while read_byte != byte:
|
||||||
|
|
||||||
if read_byte is not None:
|
if read_byte is not None:
|
||||||
if not discarded:
|
if not discarded:
|
||||||
log("Discarding", end="")
|
log("Discarding", end="")
|
||||||
|
|
11
tests/test_protocol.py
Normal file
11
tests/test_protocol.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
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"
|
4
tox.ini
4
tox.ini
|
@ -1,3 +1,7 @@
|
||||||
[flake8]
|
[flake8]
|
||||||
max-line-length = 88
|
max-line-length = 88
|
||||||
extend-ignore = E203, I201, I101
|
extend-ignore = E203, I201, I101
|
||||||
|
|
||||||
|
[pytest]
|
||||||
|
pythonpath = .
|
||||||
|
testpaths = tests
|
||||||
|
|
Loading…
Reference in a new issue