Skip to content

Commit

Permalink
Merge pull request #47 from yozik04/fetch_constants_from_unit
Browse files Browse the repository at this point in the history
Read constants from the unit directly or fallback to local file.
  • Loading branch information
yozik04 authored Nov 2, 2023
2 parents b56dd0d + f81c2f1 commit e6373be
Show file tree
Hide file tree
Showing 16 changed files with 3,631 additions and 1,828 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Old sync version is available [1.5.x](https://pypi.org/project/vallox-websocket-
Release notes for the new versions are [here](https://github.com/yozik04/vallox_websocket_api/releases)

## Requirements
Python 3.8.0+
Python 3.9.0+

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/)

Expand Down
1 change: 1 addition & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[mypy]
ignore_missing_imports = true
exclude = build
15 changes: 11 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ classifiers =
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Expand All @@ -26,16 +25,24 @@ license = LGPL 3
[options]
zip_safe = True
include_package_data = True
packages =
vallox_websocket_api
python_requires = >=3.6.0, <4
packages = find:
python_requires = >=3.9.0, <4
install_requires =
websockets >= 9.1, < 12.0
construct >= 2.9.0, < 3.0.0
aiohttp >= 3.7.0, < 4.0.0
tests_require =
pytest
pytest-asyncio

[options.package_data]
* = *.json, *.md
vallox_websocket_api = py.typed

[options.packages.find]
exclude =
tests*

[flake8]
exclude = .venv,.git,.tox,docs,venv,bin,lib,deps,build
max-complexity = 25
Expand Down
18 changes: 12 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
from unittest.mock import AsyncMock, patch

import pytest
import websockets
from websockets.legacy.protocol import WebSocketCommonProtocol

from vallox_websocket_api.client import Client
from vallox_websocket_api.vallox import Vallox


@pytest.fixture
def client():
return Client("127.0.0.1")
async def client():
client = Client("127.0.0.1")
await client.load_local_data_model("2.0.16")

return client


@pytest.fixture
def vallox():
return Vallox("127.0.0.1")
async def vallox():
vallox = Vallox("127.0.0.1")
await vallox.load_local_data_model("2.0.16")

return vallox


@pytest.fixture
def ws():
with patch("websockets.client.connect") as connect:
protocol_mock = AsyncMock(spec=websockets.WebSocketCommonProtocol)
protocol_mock = AsyncMock(spec=WebSocketCommonProtocol)
connect.return_value.__aenter__.side_effect = protocol_mock

yield protocol_mock.return_value
61 changes: 38 additions & 23 deletions tests/test_messages.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
import binascii
import struct

from vallox_websocket_api.client import calculate_offset, to_celsius
from vallox_websocket_api.constants import vlxDevConstants
from vallox_websocket_api.messages import (
LogReadRequest,
LogReadResponse1,
ReadTableRequest,
ReadTableResponse,
WriteMessageRequest,
)


def test_read_table_message_request():
import pytest

from vallox_websocket_api.client import to_celsius
from vallox_websocket_api.data.model import DataModel
from vallox_websocket_api.messages import Messages


@pytest.fixture
async def data_model():
data_model = DataModel()
await data_model.read_bundled("2.0.16")

return data_model


@pytest.fixture
def messages(data_model):
return Messages(data_model)


def test_read_table_message_request(messages: Messages):
expected = struct.pack("HHHH", 3, 246, 0, 249)

res = ReadTableRequest.build({})
res = messages.read_table_request.build({})

assert expected == res


def test_write_message_request():
def test_write_message_request(messages: Messages, data_model: DataModel):
expected = struct.pack("HHHHH", 4, 249, 20508, 29215, 49976)

res = WriteMessageRequest.build(
res = messages.write_request.build(
{
"fields": {
"value": {
"items": [
{
"address": vlxDevConstants.A_CYC_HOME_AIR_TEMP_TARGET,
"address": data_model.addresses[
"A_CYC_HOME_AIR_TEMP_TARGET"
],
"value": 29215,
}
]
Expand All @@ -41,29 +52,33 @@ def test_write_message_request():
assert expected == res


def test_log_read_message():
def test_log_read_message(messages: Messages):
expected = struct.pack("HHH", 2, 243, 245)

res = LogReadRequest.build({})
res = messages.log_read_request.build({})

assert expected == res


def test_read_table_message_response():
data = ReadTableResponse.parse(
def test_read_table_message_response(messages: Messages, data_model: DataModel):
data = messages.read_table_response.parse(
binascii.unhexlify(
"0024000000000000000000000000000001000800030000000000000061df98b100030003203fb9500331000000000000000000560000000000000000000000000000000000000000001b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002b000f732a6ca969a171d1730800010000022700000028000000000000000001a6029e000100000028ffffffffffffffffffffffffffffffffffffffffffffffff000000000000000057c503e8ffffffffffff000000190000000000010000000000000000000300001b98012000a50000000000000000001e00010000000100000000000000000007001b000f001700010012000200070044000000010000000000000007003200320001000000000000001e0000c0a80501ffffff0000000000000000000000000000000000000000000000000000000000c0a8050c86076097f78844b7ac4db61e502fe4f2004c004c000100c00101001c001e000a00320000003703840000708f00320032000a0000000000010000000a721f0000000000010000000f728300000000000000000064715700000000000000000000000000000000000000010037001e000000000000000068bf71bb000083910000002600b4000000010001000000010001001e000f00080001001200000003000000000000000000000017000003e90000000000000001000100010000000a003200010000000000000000000000000000000000000000001000000000000000000000000000540048000000000000000000000000000000c80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
)
)

assert 20.0 == to_celsius(
data[calculate_offset(vlxDevConstants.A_CYC_HOME_AIR_TEMP_TARGET)]
data[
data_model.calculate_offset(
data_model.addresses["A_CYC_HOME_AIR_TEMP_TARGET"]
)
]
)


def test_log_read_response():
def test_log_read_response(messages: Messages):
response = struct.pack("HHHH", 3, 243, 6, 252)

result = LogReadResponse1.parse(response)
result = messages.log_read_response1.parse(response)

assert 6 == result.fields.value.pages
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py38, py39, py310, py311
envlist = py39, py310, py311
isolated_build = True
skip_missing_interpreters = True

Expand Down
2 changes: 1 addition & 1 deletion vallox_websocket_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"ValloxWebsocketException",
]

__version__ = "3.3.0"
__version__ = "4.0.0"
Loading

0 comments on commit e6373be

Please sign in to comment.