PyBLNET 0.10.0__tar.gz → 0.12.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyblnet-0.10.0 → pyblnet-0.12.0}/PKG-INFO +10 -8
- {pyblnet-0.10.0 → pyblnet-0.12.0}/README.md +3 -1
- {pyblnet-0.10.0 → pyblnet-0.12.0}/pyblnet/__init__.py +1 -1
- {pyblnet-0.10.0 → pyblnet-0.12.0}/pyblnet/blnet.py +30 -5
- {pyblnet-0.10.0 → pyblnet-0.12.0}/pyblnet/blnet_conn.py +113 -35
- {pyblnet-0.10.0 → pyblnet-0.12.0}/pyblnet/blnet_parser.py +34 -6
- {pyblnet-0.10.0 → pyblnet-0.12.0}/pyblnet/blnet_web.py +122 -41
- {pyblnet-0.10.0 → pyblnet-0.12.0}/pyproject.toml +6 -9
- pyblnet-0.10.0/.github/workflows/build.yml +0 -50
- pyblnet-0.10.0/.github/workflows/release.yml +0 -22
- pyblnet-0.10.0/.gitignore +0 -206
- pyblnet-0.10.0/Pipfile +0 -13
- pyblnet-0.10.0/tests/__init__.py +0 -0
- pyblnet-0.10.0/tests/test_parser.py +0 -28
- pyblnet-0.10.0/tests/test_structure/.error.html +0 -10
- pyblnet-0.10.0/tests/test_structure/580500.alternative.htm +0 -0
- pyblnet-0.10.0/tests/test_structure/580500.htm +0 -1
- pyblnet-0.10.0/tests/test_structure/580600.htm +0 -0
- pyblnet-0.10.0/tests/test_structure/__init__.py +0 -0
- pyblnet-0.10.0/tests/test_structure/blnet_mock_server.py +0 -279
- pyblnet-0.10.0/tests/test_structure/main.htm +0 -63
- pyblnet-0.10.0/tests/test_structure/main.html +0 -63
- pyblnet-0.10.0/tests/test_structure/par.htm +0 -0
- pyblnet-0.10.0/tests/test_structure/server_control.py +0 -59
- pyblnet-0.10.0/tests/test_web.py +0 -204
- pyblnet-0.10.0/tests/web_raw/__init__.py +0 -0
- pyblnet-0.10.0/tests/web_raw/analog_values +0 -0
- pyblnet-0.10.0/tests/web_raw/digital_values +0 -0
- pyblnet-0.10.0/tests/web_raw/logged_in +0 -0
- pyblnet-0.10.0/tests/web_raw/main_alt_one +0 -0
- pyblnet-0.10.0/tests/web_raw/web_state.py +0 -151
- {pyblnet-0.10.0 → pyblnet-0.12.0}/LICENSE.txt +0 -0
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: PyBLNET
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.12.0
|
|
4
4
|
Summary: Automate wireless communication to UVR1611 via BL-NET
|
|
5
5
|
Keywords: python,uvr1611,blnet,technische alternative,home automation,iot
|
|
6
6
|
Author-email: nielstron <n.muendler@posteo.de>
|
|
7
|
-
Requires-Python: >=3
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
8
|
Description-Content-Type: text/markdown
|
|
9
9
|
Classifier: Development Status :: 4 - Beta
|
|
10
10
|
Classifier: Intended Audience :: Developers
|
|
11
11
|
Classifier: Topic :: Software Development :: Object Brokering
|
|
12
12
|
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
15
13
|
Classifier: Programming Language :: Python :: 3.10
|
|
16
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
16
|
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
19
19
|
License-File: LICENSE.txt
|
|
20
|
-
Requires-Dist: htmldom
|
|
21
20
|
Requires-Dist: requests
|
|
22
21
|
Requires-Dist: pytest ; extra == "test"
|
|
23
|
-
Project-URL: Homepage, https://github.com/
|
|
22
|
+
Project-URL: Homepage, https://github.com/PyBLNET/pyblnet/
|
|
24
23
|
Provides-Extra: test
|
|
24
|
+
Import-Name: pyblnet
|
|
25
25
|
|
|
26
26
|
# PyBLNET - a very basic python BL-NET bridge
|
|
27
|
+
[](https://pypi.org/project/PyBLNET/)
|
|
28
|
+
[](https://pypi.org/project/PyBLNET/)
|
|
27
29
|
[](https://github.com/nielstron/pyblnet/actions/workflows/build.yml)
|
|
28
30
|
[](https://coveralls.io/github/nielstron/pyblnet?branch=master)
|
|
29
31
|
|
|
@@ -90,5 +92,5 @@ print(blnet._get_data(1))
|
|
|
90
92
|
```
|
|
91
93
|
|
|
92
94
|
|
|
93
|
-
[1]
|
|
95
|
+
[1] Technische Alternative, "Schnittstelle Winsol <> Bootloader" (2006), archived copy: http://web.archive.org/web/20160122124754/http://www.haus-terra.at:80/heizung/download/Schnittstelle/Schnittstelle_PC_Bootloader.pdf
|
|
94
96
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
# PyBLNET - a very basic python BL-NET bridge
|
|
2
|
+
[](https://pypi.org/project/PyBLNET/)
|
|
3
|
+
[](https://pypi.org/project/PyBLNET/)
|
|
2
4
|
[](https://github.com/nielstron/pyblnet/actions/workflows/build.yml)
|
|
3
5
|
[](https://coveralls.io/github/nielstron/pyblnet?branch=master)
|
|
4
6
|
|
|
@@ -65,4 +67,4 @@ print(blnet._get_data(1))
|
|
|
65
67
|
```
|
|
66
68
|
|
|
67
69
|
|
|
68
|
-
[1]
|
|
70
|
+
[1] Technische Alternative, "Schnittstelle Winsol <> Bootloader" (2006), archived copy: http://web.archive.org/web/20160122124754/http://www.haus-terra.at:80/heizung/download/Schnittstelle/Schnittstelle_PC_Bootloader.pdf
|
|
@@ -12,10 +12,17 @@ as possible.
|
|
|
12
12
|
"""
|
|
13
13
|
from .blnet_web import BLNETWeb
|
|
14
14
|
from .blnet_conn import BLNETDirect
|
|
15
|
+
from .blnet_parser import ANALOG_UNITS
|
|
15
16
|
|
|
16
17
|
from urllib.parse import urlparse
|
|
17
18
|
|
|
18
19
|
|
|
20
|
+
# Units of the values only available via BLNETDirect, speed is a level 0-30
|
|
21
|
+
UNITS = {"speed": None, "energy": "kWh", "power": "kW"}
|
|
22
|
+
# Analog input type for the units shown by the web interface
|
|
23
|
+
WEB_UNIT_TYPES = {unit: input_type for input_type, unit in ANALOG_UNITS.items() if unit is not None}
|
|
24
|
+
|
|
25
|
+
|
|
19
26
|
class BLNET(object):
|
|
20
27
|
"""
|
|
21
28
|
General high-level BLNET interface.
|
|
@@ -68,7 +75,7 @@ class BLNET(object):
|
|
|
68
75
|
# especially not if not prefixed with http://
|
|
69
76
|
# see https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlparse
|
|
70
77
|
host = urlparse(address).hostname or address
|
|
71
|
-
self.blnet_direct = BLNETDirect(host, ta_port)
|
|
78
|
+
self.blnet_direct = BLNETDirect(host, ta_port, timeout=timeout)
|
|
72
79
|
|
|
73
80
|
def fetch(self, node=None):
|
|
74
81
|
"""
|
|
@@ -88,6 +95,9 @@ class BLNET(object):
|
|
|
88
95
|
blnet_session.set_node(node)
|
|
89
96
|
data["analog"] = self._convert_web(blnet_session.read_analog_values())
|
|
90
97
|
data["digital"] = self._convert_web(blnet_session.read_digital_values())
|
|
98
|
+
for entry in data["analog"].values():
|
|
99
|
+
# digital inputs come with their type, others by their unit
|
|
100
|
+
entry.setdefault("type", WEB_UNIT_TYPES.get(entry.get("unit_of_measurement")))
|
|
91
101
|
if self.blnet_direct:
|
|
92
102
|
direct = self.blnet_direct.get_latest(self.max_retries)[0]
|
|
93
103
|
# Override values for analog and digital as values are
|
|
@@ -95,12 +105,24 @@ class BLNET(object):
|
|
|
95
105
|
for domain in ["analog", "digital"]:
|
|
96
106
|
for id, value in direct[domain].items():
|
|
97
107
|
if data[domain].get(id) is not None:
|
|
98
|
-
|
|
108
|
+
# Keep the web value if the direct one is missing: a
|
|
109
|
+
# UVR1611 on CAN sends digital inputs as unused inputs
|
|
110
|
+
if value is not None:
|
|
111
|
+
data[domain][id]["value"] = value
|
|
112
|
+
elif not self.blnet_web:
|
|
113
|
+
if value is None:
|
|
114
|
+
continue
|
|
115
|
+
data[domain][id] = {"value": value}
|
|
116
|
+
if domain == "analog":
|
|
117
|
+
input_type = direct["analog_types"][id]
|
|
118
|
+
data[domain][id]["type"] = input_type
|
|
119
|
+
data[domain][id]["unit_of_measurement"] = ANALOG_UNITS.get(input_type)
|
|
120
|
+
|
|
99
121
|
for domain in ["speed", "energy", "power"]:
|
|
100
122
|
for id, value in direct[domain].items():
|
|
101
123
|
if value is None:
|
|
102
124
|
continue
|
|
103
|
-
data[domain][id] = {"value": value}
|
|
125
|
+
data[domain][id] = {"value": value, "unit_of_measurement": UNITS[domain]}
|
|
104
126
|
return data
|
|
105
127
|
|
|
106
128
|
def turn_on(self, digital_id, can_node=None):
|
|
@@ -162,8 +184,11 @@ class BLNET(object):
|
|
|
162
184
|
if cached is None:
|
|
163
185
|
cached = self.fetch()
|
|
164
186
|
for key, v in cached[type].items():
|
|
165
|
-
|
|
166
|
-
|
|
187
|
+
# values fetched only via blnet_direct have no name
|
|
188
|
+
if (name is not None and str(v.get("name")) == str(name)) or (
|
|
189
|
+
id is not None and str(key) == str(id)
|
|
190
|
+
):
|
|
191
|
+
val = v.get(ret)
|
|
167
192
|
dic = v
|
|
168
193
|
|
|
169
194
|
return val, dic, cached
|
|
@@ -9,7 +9,8 @@ https://github.com/berwinter/uvr1611/blob/master/lib/backend/blnet-connection.in
|
|
|
9
9
|
@author: Niels
|
|
10
10
|
"""
|
|
11
11
|
from builtins import str, int
|
|
12
|
-
from socket import socket, getaddrinfo, SOCK_STREAM, IPPROTO_TCP
|
|
12
|
+
from socket import socket, getaddrinfo, SOCK_STREAM, IPPROTO_TCP
|
|
13
|
+
import functools
|
|
13
14
|
import struct
|
|
14
15
|
from time import sleep
|
|
15
16
|
from datetime import datetime
|
|
@@ -27,11 +28,37 @@ READ_DATA = 0xAC
|
|
|
27
28
|
END_READ = b"\xAD"
|
|
28
29
|
RESET_DATA = b"\xAF"
|
|
29
30
|
WAIT_TIME = 0xBA
|
|
31
|
+
# Seconds to wait when the BL-Net has no new data yet. Real devices answer
|
|
32
|
+
# GET_LATEST with "no data" for up to about 5 seconds after a read.
|
|
33
|
+
NO_DATA_WAIT = 2
|
|
30
34
|
MAX_RETRYS = 10
|
|
35
|
+
# Length of a WAIT_TIME reply: 0xBA, seconds to wait, checksum
|
|
36
|
+
WAIT_SIZE = 3
|
|
31
37
|
DATASET_SIZE = 61
|
|
32
38
|
LATEST_SIZE = 56
|
|
33
39
|
|
|
34
40
|
|
|
41
|
+
def _reset_on_error(method):
|
|
42
|
+
"""
|
|
43
|
+
Close the connection and forget the read state if a read fails,
|
|
44
|
+
so that the next call starts with a fresh connection.
|
|
45
|
+
Malformed replies are raised as ConnectionError.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
@functools.wraps(method)
|
|
49
|
+
def wrapper(self, *args, **kwargs):
|
|
50
|
+
try:
|
|
51
|
+
return method(self, *args, **kwargs)
|
|
52
|
+
except (struct.error, IndexError, ValueError) as ex:
|
|
53
|
+
self._reset()
|
|
54
|
+
raise ConnectionError(f"Invalid reply from BL-Net: {ex}") from ex
|
|
55
|
+
except BaseException:
|
|
56
|
+
self._reset()
|
|
57
|
+
raise
|
|
58
|
+
|
|
59
|
+
return wrapper
|
|
60
|
+
|
|
61
|
+
|
|
35
62
|
class BLNETDirect(object):
|
|
36
63
|
"""
|
|
37
64
|
A class for establishing a direct connection to the BLNET (rather than
|
|
@@ -55,13 +82,14 @@ class BLNETDirect(object):
|
|
|
55
82
|
self.address = address
|
|
56
83
|
self.port = port
|
|
57
84
|
self.reset = reset
|
|
85
|
+
# 0 would make the socket non-blocking, treat it like None (no timeout)
|
|
86
|
+
self._timeout = timeout or None
|
|
58
87
|
self._mode = None
|
|
59
88
|
self._socket = None
|
|
60
89
|
self._count = None
|
|
61
90
|
self._check_mode()
|
|
62
|
-
if timeout:
|
|
63
|
-
setdefaulttimeout(timeout)
|
|
64
91
|
|
|
92
|
+
@_reset_on_error
|
|
65
93
|
def get_count(self):
|
|
66
94
|
"""
|
|
67
95
|
Get the number of datasets in the bootloader memory
|
|
@@ -90,7 +118,7 @@ class BLNETDirect(object):
|
|
|
90
118
|
self._fetch_size = 4 + 61 * frame_count
|
|
91
119
|
elif self._mode == DL_MODE:
|
|
92
120
|
(_, device, start_address, end_address, checksum) = struct.unpack(
|
|
93
|
-
"<5sB3s3sB"
|
|
121
|
+
"<5sB3s3sB", data
|
|
94
122
|
)
|
|
95
123
|
self._address_inc = 64
|
|
96
124
|
self._can_frames = 1
|
|
@@ -98,7 +126,7 @@ class BLNETDirect(object):
|
|
|
98
126
|
self._fetch_size = 65
|
|
99
127
|
elif self._mode == DL2_MODE:
|
|
100
128
|
(_, device, start_address, end_address, checksum) = struct.unpack(
|
|
101
|
-
"<5s2s3s3sB"
|
|
129
|
+
"<5s2s3s3sB", data
|
|
102
130
|
)
|
|
103
131
|
self._address_inc = 128
|
|
104
132
|
self._can_frames = 1
|
|
@@ -128,20 +156,18 @@ class BLNETDirect(object):
|
|
|
128
156
|
else:
|
|
129
157
|
raise ConnectionError("Could not retreive count")
|
|
130
158
|
|
|
159
|
+
@_reset_on_error
|
|
131
160
|
def _get_data(self, max_count=None):
|
|
132
161
|
data = []
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return data
|
|
141
|
-
finally:
|
|
142
|
-
self._end_read(False)
|
|
143
|
-
return data
|
|
162
|
+
count = self._start_read()
|
|
163
|
+
if isinstance(max_count, int):
|
|
164
|
+
count = min(max_count, count)
|
|
165
|
+
for _ in range(0, count):
|
|
166
|
+
data.append(self._fetch_data())
|
|
167
|
+
self._end_read(True)
|
|
168
|
+
return data
|
|
144
169
|
|
|
170
|
+
@_reset_on_error
|
|
145
171
|
def _check_mode(self):
|
|
146
172
|
"""
|
|
147
173
|
Check if Bootloader Mode is supported
|
|
@@ -167,9 +193,11 @@ class BLNETDirect(object):
|
|
|
167
193
|
for (family, socktype, proto, _, sockaddr) in available:
|
|
168
194
|
try:
|
|
169
195
|
self._socket = socket(family, socktype, proto)
|
|
196
|
+
self._socket.settimeout(self._timeout)
|
|
170
197
|
self._socket.connect(sockaddr)
|
|
171
198
|
break
|
|
172
|
-
except:
|
|
199
|
+
except OSError:
|
|
200
|
+
self._socket.close()
|
|
173
201
|
self._socket = None
|
|
174
202
|
if self._socket is None:
|
|
175
203
|
raise ConnectionError("Could not connect to BLNET")
|
|
@@ -181,26 +209,67 @@ class BLNETDirect(object):
|
|
|
181
209
|
self._socket.close()
|
|
182
210
|
self._socket = None
|
|
183
211
|
|
|
212
|
+
def _reset(self):
|
|
213
|
+
"""
|
|
214
|
+
Close the connection if open and forget the read state
|
|
215
|
+
"""
|
|
216
|
+
if self._socket is not None:
|
|
217
|
+
self._disconnect()
|
|
218
|
+
self._count = None
|
|
219
|
+
self._address = None
|
|
220
|
+
|
|
184
221
|
def _query(self, command, length):
|
|
185
222
|
"""
|
|
186
223
|
Send a command to the bootloader and wait for the response
|
|
187
224
|
if response is less then 32 bytes long return immediately
|
|
188
225
|
@param commmand: string only ascii (needs byte length == string length)
|
|
189
226
|
@param length: int length of response
|
|
190
|
-
@throws ConnectionError
|
|
227
|
+
@throws ConnectionError BL-Net closed the connection
|
|
191
228
|
@return Binary: byte string
|
|
192
229
|
"""
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
230
|
+
self._socket.sendall(command)
|
|
231
|
+
data = b""
|
|
232
|
+
# get response until length or less than 32 bytes
|
|
233
|
+
while True:
|
|
234
|
+
received = self._socket.recv(length)
|
|
235
|
+
if not received:
|
|
236
|
+
raise ConnectionError("BL-Net closed the connection")
|
|
237
|
+
data += received
|
|
238
|
+
if len(data) <= 32 or len(data) >= length:
|
|
239
|
+
break
|
|
240
|
+
return data
|
|
241
|
+
|
|
242
|
+
def _recv_exact(self, length):
|
|
243
|
+
"""
|
|
244
|
+
Receive exactly length bytes
|
|
245
|
+
@throws ConnectionError BL-Net closed the connection
|
|
246
|
+
@return Binary: byte string
|
|
247
|
+
"""
|
|
248
|
+
data = b""
|
|
249
|
+
while len(data) < length:
|
|
250
|
+
received = self._socket.recv(length - len(data))
|
|
251
|
+
if not received:
|
|
252
|
+
raise ConnectionError("BL-Net closed the connection")
|
|
253
|
+
data += received
|
|
254
|
+
return data
|
|
255
|
+
|
|
256
|
+
def _query_latest(self, command):
|
|
257
|
+
"""
|
|
258
|
+
Send a GET_LATEST command and receive the complete reply.
|
|
259
|
+
The BL-Net may send a reply in several TCP segments, so the length
|
|
260
|
+
is derived from its first byte and the reply is read completely.
|
|
261
|
+
Reading only part of it would leave the rest in the socket and
|
|
262
|
+
shift every following reply by some bytes.
|
|
263
|
+
@return Binary: byte string, a "no data", "wait" or data reply
|
|
264
|
+
"""
|
|
265
|
+
self._socket.sendall(command)
|
|
266
|
+
first = self._recv_exact(1)
|
|
267
|
+
if first[0] == GET_LATEST:
|
|
268
|
+
# no new data available yet
|
|
269
|
+
return first
|
|
270
|
+
if first[0] == WAIT_TIME:
|
|
271
|
+
return first + self._recv_exact(WAIT_SIZE - 1)
|
|
272
|
+
return first + self._recv_exact(self._actual_size - 1)
|
|
204
273
|
|
|
205
274
|
def _start_read(self):
|
|
206
275
|
"""
|
|
@@ -308,6 +377,7 @@ class BLNETDirect(object):
|
|
|
308
377
|
self._address = None
|
|
309
378
|
self._disconnect()
|
|
310
379
|
|
|
380
|
+
@_reset_on_error
|
|
311
381
|
def get_latest(self, max_retries=MAX_RETRYS):
|
|
312
382
|
"""
|
|
313
383
|
Fetch latest (current) data from the BLNet
|
|
@@ -318,7 +388,7 @@ class BLNETDirect(object):
|
|
|
318
388
|
self._connect()
|
|
319
389
|
self.get_count()
|
|
320
390
|
frames = {}
|
|
321
|
-
info = {"sleep": {}, "got": {}}
|
|
391
|
+
info = {"sleep": {}, "got": {}, "timeout": []}
|
|
322
392
|
|
|
323
393
|
# for all frames
|
|
324
394
|
for frame in range(0, self._can_frames):
|
|
@@ -327,9 +397,12 @@ class BLNETDirect(object):
|
|
|
327
397
|
# try 4 times
|
|
328
398
|
sleeps = []
|
|
329
399
|
for n in range(0, max_retries):
|
|
330
|
-
data = self.
|
|
400
|
+
data = self._query_latest(command)
|
|
331
401
|
|
|
332
|
-
if
|
|
402
|
+
if data == bytes([GET_LATEST]):
|
|
403
|
+
# no new data available yet ("Synchronisation" in TA's spec)
|
|
404
|
+
sleep(NO_DATA_WAIT)
|
|
405
|
+
elif self._checksum(data):
|
|
333
406
|
binary = struct.unpack("<{}".format("B" * len(data)), data)
|
|
334
407
|
|
|
335
408
|
if binary[0] == WAIT_TIME:
|
|
@@ -342,9 +415,14 @@ class BLNETDirect(object):
|
|
|
342
415
|
info["got"][frame] = n
|
|
343
416
|
frames.update(self._split_latest(data, frame))
|
|
344
417
|
break
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
418
|
+
else:
|
|
419
|
+
# Unexpected bytes may still be on their way, reconnect
|
|
420
|
+
# so that they can't end up in the next reply
|
|
421
|
+
self._disconnect()
|
|
422
|
+
self._connect()
|
|
423
|
+
else:
|
|
424
|
+
# BL-Net did not send data for this frame within max_retries
|
|
425
|
+
info["timeout"].append(frame)
|
|
348
426
|
info["sleep"][frame] = sleeps
|
|
349
427
|
self._end_read(True)
|
|
350
428
|
if len(frames) > 0:
|
|
@@ -27,13 +27,32 @@ TYPE_NONE = 0x0000
|
|
|
27
27
|
TYPE_DIGITAL = 0x1000
|
|
28
28
|
TYPE_TEMP = 0x2000
|
|
29
29
|
TYPE_VOLUME = 0x3000
|
|
30
|
-
|
|
30
|
+
# V110 TTTT TTTT TTTT in TA's interface spec, in W/m²
|
|
31
|
+
TYPE_RADIATION = 0x6000
|
|
31
32
|
TYPE_RAS = 0x7000
|
|
32
33
|
RAS_POSITIVE_MASK = 0x01FF
|
|
34
|
+
# Temperature input without sensor (or with a broken wire): all value bits set, 409.5 °C
|
|
35
|
+
TEMP_NO_SENSOR = TYPE_TEMP | POSITIVE_VALUE_MASK
|
|
33
36
|
# 32 bit
|
|
34
37
|
INT32_MASK = 0xFFFFFFFF
|
|
35
38
|
INT32_SIGN = 0x80000000
|
|
36
39
|
|
|
40
|
+
# Names of the analog input types, unused and undocumented types have none
|
|
41
|
+
ANALOG_TYPES = {
|
|
42
|
+
TYPE_DIGITAL: "digital",
|
|
43
|
+
TYPE_TEMP: "temperature",
|
|
44
|
+
TYPE_VOLUME: "volume_flow",
|
|
45
|
+
TYPE_RADIATION: "radiation",
|
|
46
|
+
TYPE_RAS: "temperature",
|
|
47
|
+
}
|
|
48
|
+
# Units of the analog input types, as the web interface shows them
|
|
49
|
+
ANALOG_UNITS = {
|
|
50
|
+
"digital": None,
|
|
51
|
+
"temperature": "°C",
|
|
52
|
+
"volume_flow": "l/h",
|
|
53
|
+
"radiation": "W/m²",
|
|
54
|
+
}
|
|
55
|
+
|
|
37
56
|
|
|
38
57
|
class BLNETParser:
|
|
39
58
|
def __init__(self, data):
|
|
@@ -71,8 +90,11 @@ class BLNETParser:
|
|
|
71
90
|
analog = struct.unpack("<{}{}".format("H" * 16, "x" * (len(data) - 32)), data)
|
|
72
91
|
|
|
73
92
|
self.analog = {}
|
|
93
|
+
self.analog_types = {}
|
|
74
94
|
for channel in range(0, 16):
|
|
75
|
-
self.
|
|
95
|
+
self.analog_types[channel + 1] = ANALOG_TYPES.get(analog[channel] & TYPE_MASK)
|
|
96
|
+
value = self._convert_analog(analog[channel])
|
|
97
|
+
self.analog[channel + 1] = None if value is None else round(value, 3)
|
|
76
98
|
|
|
77
99
|
self.digital = {}
|
|
78
100
|
for channel in range(0, 16):
|
|
@@ -107,7 +129,12 @@ class BLNETParser:
|
|
|
107
129
|
"""
|
|
108
130
|
|
|
109
131
|
mask = value & TYPE_MASK
|
|
110
|
-
if mask ==
|
|
132
|
+
if mask == TYPE_NONE:
|
|
133
|
+
# input is unused
|
|
134
|
+
return None
|
|
135
|
+
elif value == TEMP_NO_SENSOR:
|
|
136
|
+
return None
|
|
137
|
+
elif mask == TYPE_TEMP:
|
|
111
138
|
return self._calculate_value(value, 0.1)
|
|
112
139
|
elif mask == TYPE_VOLUME:
|
|
113
140
|
return self._calculate_value(value, 4)
|
|
@@ -118,7 +145,8 @@ class BLNETParser:
|
|
|
118
145
|
return 0
|
|
119
146
|
elif mask == TYPE_RAS:
|
|
120
147
|
return self._calculate_value(value, 0.1, RAS_POSITIVE_MASK)
|
|
121
|
-
|
|
148
|
+
else:
|
|
149
|
+
# TYPE_RADIATION and types not covered by the interface spec
|
|
122
150
|
return self._calculate_value(value)
|
|
123
151
|
|
|
124
152
|
def _convert_digital(self, value, position):
|
|
@@ -144,7 +172,7 @@ class BLNETParser:
|
|
|
144
172
|
Check if heat meter is activated on a given position
|
|
145
173
|
@return its energy
|
|
146
174
|
"""
|
|
147
|
-
if active & position:
|
|
175
|
+
if active & (1 << position):
|
|
148
176
|
kwh = self._calculate_value(kwh, 0.1, INT16_POSITIVE_MASK)
|
|
149
177
|
return round(mwh * 1000 + kwh, 3)
|
|
150
178
|
else:
|
|
@@ -155,7 +183,7 @@ class BLNETParser:
|
|
|
155
183
|
checks if heat meter is activated at given position
|
|
156
184
|
@return its power
|
|
157
185
|
"""
|
|
158
|
-
if active & position:
|
|
186
|
+
if active & (1 << position):
|
|
159
187
|
value = self._calculate_value(value, 1 / 2560, INT32_MASK, INT32_SIGN)
|
|
160
188
|
value = round(value, 3)
|
|
161
189
|
return value
|