Skip to content

Commit e6373be

Browse files
authored
Merge pull request #47 from yozik04/fetch_constants_from_unit
Read constants from the unit directly or fallback to local file.
2 parents b56dd0d + f81c2f1 commit e6373be

File tree

16 files changed

+3631
-1828
lines changed

16 files changed

+3631
-1828
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: ["3.8", "3.9", "3.10", "3.11"]
19+
python-version: ["3.9", "3.10", "3.11"]
2020

2121
steps:
2222
- uses: actions/checkout@v4

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Old sync version is available [1.5.x](https://pypi.org/project/vallox-websocket-
1414
Release notes for the new versions are [here](https://github.com/yozik04/vallox_websocket_api/releases)
1515

1616
## Requirements
17-
Python 3.8.0+
17+
Python 3.9.0+
1818

1919
If you want to use Python 2.7, then use old sync version [1.5.x](https://pypi.org/project/vallox-websocket-api/1.5.2/)
2020

mypy.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[mypy]
22
ignore_missing_imports = true
3+
exclude = build

setup.cfg

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ classifiers =
1717
Operating System :: OS Independent
1818
Programming Language :: Python
1919
Programming Language :: Python :: 3 :: Only
20-
Programming Language :: Python :: 3.8
2120
Programming Language :: Python :: 3.9
2221
Programming Language :: Python :: 3.10
2322
Programming Language :: Python :: 3.11
@@ -26,16 +25,24 @@ license = LGPL 3
2625
[options]
2726
zip_safe = True
2827
include_package_data = True
29-
packages =
30-
vallox_websocket_api
31-
python_requires = >=3.6.0, <4
28+
packages = find:
29+
python_requires = >=3.9.0, <4
3230
install_requires =
3331
websockets >= 9.1, < 12.0
3432
construct >= 2.9.0, < 3.0.0
33+
aiohttp >= 3.7.0, < 4.0.0
3534
tests_require =
3635
pytest
3736
pytest-asyncio
3837

38+
[options.package_data]
39+
* = *.json, *.md
40+
vallox_websocket_api = py.typed
41+
42+
[options.packages.find]
43+
exclude =
44+
tests*
45+
3946
[flake8]
4047
exclude = .venv,.git,.tox,docs,venv,bin,lib,deps,build
4148
max-complexity = 25

tests/conftest.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
from unittest.mock import AsyncMock, patch
22

33
import pytest
4-
import websockets
4+
from websockets.legacy.protocol import WebSocketCommonProtocol
55

66
from vallox_websocket_api.client import Client
77
from vallox_websocket_api.vallox import Vallox
88

99

1010
@pytest.fixture
11-
def client():
12-
return Client("127.0.0.1")
11+
async def client():
12+
client = Client("127.0.0.1")
13+
await client.load_local_data_model("2.0.16")
14+
15+
return client
1316

1417

1518
@pytest.fixture
16-
def vallox():
17-
return Vallox("127.0.0.1")
19+
async def vallox():
20+
vallox = Vallox("127.0.0.1")
21+
await vallox.load_local_data_model("2.0.16")
22+
23+
return vallox
1824

1925

2026
@pytest.fixture
2127
def ws():
2228
with patch("websockets.client.connect") as connect:
23-
protocol_mock = AsyncMock(spec=websockets.WebSocketCommonProtocol)
29+
protocol_mock = AsyncMock(spec=WebSocketCommonProtocol)
2430
connect.return_value.__aenter__.side_effect = protocol_mock
2531

2632
yield protocol_mock.return_value

tests/test_messages.py

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,46 @@
11
import binascii
22
import struct
33

4-
from vallox_websocket_api.client import calculate_offset, to_celsius
5-
from vallox_websocket_api.constants import vlxDevConstants
6-
from vallox_websocket_api.messages import (
7-
LogReadRequest,
8-
LogReadResponse1,
9-
ReadTableRequest,
10-
ReadTableResponse,
11-
WriteMessageRequest,
12-
)
13-
14-
15-
def test_read_table_message_request():
4+
import pytest
5+
6+
from vallox_websocket_api.client import to_celsius
7+
from vallox_websocket_api.data.model import DataModel
8+
from vallox_websocket_api.messages import Messages
9+
10+
11+
@pytest.fixture
12+
async def data_model():
13+
data_model = DataModel()
14+
await data_model.read_bundled("2.0.16")
15+
16+
return data_model
17+
18+
19+
@pytest.fixture
20+
def messages(data_model):
21+
return Messages(data_model)
22+
23+
24+
def test_read_table_message_request(messages: Messages):
1625
expected = struct.pack("HHHH", 3, 246, 0, 249)
1726

18-
res = ReadTableRequest.build({})
27+
res = messages.read_table_request.build({})
1928

2029
assert expected == res
2130

2231

23-
def test_write_message_request():
32+
def test_write_message_request(messages: Messages, data_model: DataModel):
2433
expected = struct.pack("HHHHH", 4, 249, 20508, 29215, 49976)
2534

26-
res = WriteMessageRequest.build(
35+
res = messages.write_request.build(
2736
{
2837
"fields": {
2938
"value": {
3039
"items": [
3140
{
32-
"address": vlxDevConstants.A_CYC_HOME_AIR_TEMP_TARGET,
41+
"address": data_model.addresses[
42+
"A_CYC_HOME_AIR_TEMP_TARGET"
43+
],
3344
"value": 29215,
3445
}
3546
]
@@ -41,29 +52,33 @@ def test_write_message_request():
4152
assert expected == res
4253

4354

44-
def test_log_read_message():
55+
def test_log_read_message(messages: Messages):
4556
expected = struct.pack("HHH", 2, 243, 245)
4657

47-
res = LogReadRequest.build({})
58+
res = messages.log_read_request.build({})
4859

4960
assert expected == res
5061

5162

52-
def test_read_table_message_response():
53-
data = ReadTableResponse.parse(
63+
def test_read_table_message_response(messages: Messages, data_model: DataModel):
64+
data = messages.read_table_response.parse(
5465
binascii.unhexlify(
5566
"0024000000000000000000000000000001000800030000000000000061df98b100030003203fb9500331000000000000000000560000000000000000000000000000000000000000001b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002b000f732a6ca969a171d1730800010000022700000028000000000000000001a6029e000100000028ffffffffffffffffffffffffffffffffffffffffffffffff000000000000000057c503e8ffffffffffff000000190000000000010000000000000000000300001b98012000a50000000000000000001e00010000000100000000000000000007001b000f001700010012000200070044000000010000000000000007003200320001000000000000001e0000c0a80501ffffff0000000000000000000000000000000000000000000000000000000000c0a8050c86076097f78844b7ac4db61e502fe4f2004c004c000100c00101001c001e000a00320000003703840000708f00320032000a0000000000010000000a721f0000000000010000000f728300000000000000000064715700000000000000000000000000000000000000010037001e000000000000000068bf71bb000083910000002600b4000000010001000000010001001e000f00080001001200000003000000000000000000000017000003e90000000000000001000100010000000a003200010000000000000000000000000000000000000000001000000000000000000000000000540048000000000000000000000000000000c80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
5667
)
5768
)
5869

5970
assert 20.0 == to_celsius(
60-
data[calculate_offset(vlxDevConstants.A_CYC_HOME_AIR_TEMP_TARGET)]
71+
data[
72+
data_model.calculate_offset(
73+
data_model.addresses["A_CYC_HOME_AIR_TEMP_TARGET"]
74+
)
75+
]
6176
)
6277

6378

64-
def test_log_read_response():
79+
def test_log_read_response(messages: Messages):
6580
response = struct.pack("HHHH", 3, 243, 6, 252)
6681

67-
result = LogReadResponse1.parse(response)
82+
result = messages.log_read_response1.parse(response)
6883

6984
assert 6 == result.fields.value.pages

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py38, py39, py310, py311
2+
envlist = py39, py310, py311
33
isolated_build = True
44
skip_missing_interpreters = True
55

vallox_websocket_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
"ValloxWebsocketException",
2525
]
2626

27-
__version__ = "3.3.0"
27+
__version__ = "4.0.0"

0 commit comments

Comments
 (0)