PyBLNET 0.10.0__py3-none-any.whl → 0.12.0__py3-none-any.whl

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/__init__.py CHANGED
@@ -10,5 +10,5 @@ try:
10
10
  except ImportError as e:
11
11
  warnings.warn(ImportWarning(e))
12
12
 
13
- VERSION = (0, 10, 0)
13
+ VERSION = (0, 12, 0)
14
14
 
pyblnet/blnet.py CHANGED
@@ -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
- data[domain][id]["value"] = value
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
- if str(v["name"]) == str(name) or str(v["id"]) == str(id):
166
- val = v[ret]
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
pyblnet/blnet_conn.py CHANGED
@@ -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, setdefaulttimeout
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
- try:
134
- count = self._start_read()
135
- if isinstance(max_count, int):
136
- count = min(max_count, count)
137
- for _ in range(0, count):
138
- data.append(self._fetch_data())
139
- self._end_read(True)
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 error when querying
227
+ @throws ConnectionError BL-Net closed the connection
191
228
  @return Binary: byte string
192
229
  """
193
- if len(command) == self._socket.send(command):
194
- data = b""
195
- # get response until length or less than 32 bytes
196
- while True:
197
- data += self._socket.recv(length)
198
- if len(data) <= 32 or len(data) >= length:
199
- break
200
- return data
201
-
202
- self._disconnect()
203
- raise ConnectionError("Error while querying command {}".format(command))
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._query(command, self._actual_size)
400
+ data = self._query_latest(command)
331
401
 
332
- if self._checksum(data):
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
- # TODO this looks suspicious
346
- if n == max_retries - 1:
347
- frames[frame] = "timeout"
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:
pyblnet/blnet_parser.py CHANGED
@@ -27,13 +27,32 @@ TYPE_NONE = 0x0000
27
27
  TYPE_DIGITAL = 0x1000
28
28
  TYPE_TEMP = 0x2000
29
29
  TYPE_VOLUME = 0x3000
30
- TYPE_RADIATION = 0x4000
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.analog[channel + 1] = round(self._convert_analog(analog[channel]), 3)
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 == TYPE_TEMP:
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
- elif mask in [TYPE_RADIATION, TYPE_NONE] or True:
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
pyblnet/blnet_web.py CHANGED
@@ -10,10 +10,92 @@ via it's HTTP-interface
10
10
  """
11
11
 
12
12
  import requests
13
- from htmldom import htmldom
14
13
  import html
15
14
  import re
16
15
  from builtins import int
16
+ from html.parser import HTMLParser
17
+
18
+ # An input on the inputs page: a measured value with unit, or the state of a
19
+ # digital input. The value of a digital input is "1" (on) or "0" (off), like
20
+ # the direct connection reports it.
21
+ INPUT_PATTERN = re.compile(
22
+ r"(?P<id>\d+):&nbsp;(?P<name>.+)\n(&nbsp;){3,6}"
23
+ r"(?:(?P<value>(-&nbsp;)?\d+,\d+) (?P<unit_of_measurement>.+?) &nbsp;&nbsp;"
24
+ r"|(?P<state>AUS|EIN|OFF|ON)(&nbsp;)+)PAR?"
25
+ )
26
+ DIGITAL_INPUT_STATES = {"AUS": "0", "OFF": "0", "EIN": "1", "ON": "1"}
27
+
28
+ # A mixer on the outputs page: its mode, then the state of the opening output
29
+ # and of the closing output, which has the next id
30
+ MIXER_OUTPUT_PATTERN = re.compile(
31
+ r"(?P<id>\d+):&nbsp;(?P<name>.+)\n(&nbsp;)+(?P<mode>AUTO|HAND) .*PAR\?.*\n"
32
+ r"(&nbsp;)+auf:(&nbsp;)+(?P<open>AUS|EIN)\n"
33
+ r"(&nbsp;)*(?P<id_close>\d+):&nbsp;zu:(&nbsp;)+(?P<close>AUS|EIN)"
34
+ )
35
+
36
+
37
+ class _ElementTextParser(HTMLParser):
38
+ """
39
+ Collects the text of all elements with the given tag and class or id.
40
+ Entities like &nbsp; are kept as written and <br> becomes a newline,
41
+ which is what the regular expressions below expect.
42
+ """
43
+
44
+ def __init__(self, tag, cls=None, id=None):
45
+ super().__init__(convert_charrefs=False)
46
+ self.tag = tag
47
+ self.cls = cls
48
+ self.id = id
49
+ # text of each matching element, in document order
50
+ self.texts = []
51
+ # for each open element with self.tag: its index in self.texts,
52
+ # or None if it doesn't match. Matching elements can be nested.
53
+ self._open = []
54
+
55
+ def _matches(self, attrs):
56
+ attrs = dict(attrs)
57
+ return (self.cls is None or self.cls in (attrs.get("class") or "").split()) and (
58
+ self.id is None or attrs.get("id") == self.id
59
+ )
60
+
61
+ def handle_starttag(self, tag, attrs):
62
+ if tag == self.tag:
63
+ if self._matches(attrs):
64
+ self.texts.append("")
65
+ self._open.append(len(self.texts) - 1)
66
+ else:
67
+ self._open.append(None)
68
+ elif tag == "br":
69
+ self.handle_data("\n")
70
+
71
+ def handle_endtag(self, tag):
72
+ if tag == self.tag and self._open:
73
+ self._open.pop()
74
+
75
+ def handle_data(self, data):
76
+ for index in self._open:
77
+ if index is not None:
78
+ self.texts[index] += data
79
+
80
+ def handle_entityref(self, name):
81
+ self.handle_data(f"&{name};")
82
+
83
+ def handle_charref(self, name):
84
+ self.handle_data(f"&#{name};")
85
+
86
+
87
+ def _element_texts(page, tag, cls=None, id=None):
88
+ """Texts of all elements in page with the given tag and class or id"""
89
+ parser = _ElementTextParser(tag, cls, id)
90
+ parser.feed(page)
91
+ parser.close()
92
+ return parser.texts
93
+
94
+
95
+ def _element_text(page, tag, cls=None, id=None):
96
+ """Text of the first such element, empty if there is none"""
97
+ texts = _element_texts(page, tag, cls, id)
98
+ return texts[0] if texts else ""
17
99
 
18
100
 
19
101
  def blnet_test(ip, timeout=5, id=0):
@@ -28,13 +110,11 @@ def blnet_test(ip, timeout=5, id=0):
28
110
  r = requests.get(ip, timeout=timeout)
29
111
  except requests.exceptions.RequestException:
30
112
  return False
31
- # Parse DOM object from HTMLCode
32
- dom = htmldom.HtmlDom().createDom(r.text)
33
113
  # either a 'Zugriff verweigert' message is shown
34
- if "BL-Net".lower() in dom.find("title").text().lower():
114
+ if "BL-Net".lower() in _element_text(r.text, "title").lower():
35
115
  return True
36
116
  # or (more often) the BL-NET Menü
37
- if "BL-NET" in dom.find("div#head").text():
117
+ if "BL-NET" in _element_text(r.text, "div", id="head"):
38
118
  return True
39
119
  return False
40
120
 
@@ -183,41 +263,35 @@ class BLNETWeb(object):
183
263
  )
184
264
  except requests.exceptions.RequestException:
185
265
  return None
186
- # Parse DOM object from HTMLCode
187
- dom = htmldom.HtmlDom().createDom(r.text)
188
- # Check if we didn't fail in access
189
- # if 'BL-Net Zugang verweigert' in dom.find('title').text():
190
- # return None
191
266
  # get the element containing the interesting information
192
- dom = dom.find("div.c")[1]
267
+ texts = _element_texts(r.text, "div", cls="c")
193
268
  # in case of access denied or other errors, return None
194
- if dom is None:
195
- return dom
196
- # filter out the text
197
- data_raw = dom.text()
269
+ if len(texts) < 2:
270
+ return None
271
+ data_raw = texts[1]
198
272
 
199
273
  # collect data in an array
200
274
  data = list()
201
275
 
202
276
  # search for data by regular expression
203
- match_iter = re.finditer(
204
- r"(?P<id>\d+):&nbsp;(?P<name>.+)\n(&nbsp;){3,6}(?P<value>(-&nbsp;)?\d+,\d+) (?P<unit_of_measurement>.+?) &nbsp;&nbsp;PAR?",
205
- data_raw,
206
- )
207
- # parse a dict of the match and save them all in a list
208
- for match in match_iter:
209
- match_dict = match.groupdict()
210
- # convert html entities to unicode characters
211
- for key, value in match_dict.items():
212
- # replace &nbsp; by " " since it is not unescaped as expected
213
- value = value.replace("&nbsp;", " ")
214
- if key == "value":
215
- # for values
216
- # also replace decimal "," by "." and remove "&nbsp;" completely
217
- value = value.replace(",", ".").replace(" ", "")
218
- match_dict[key] = html.unescape(value)
219
- # and append formatted dict
220
- data.append(match_dict)
277
+ for match in INPUT_PATTERN.finditer(data_raw):
278
+ # convert html entities to unicode characters,
279
+ # replace &nbsp; by " " since it is not unescaped as expected
280
+ entry = {
281
+ "id": match["id"],
282
+ "name": html.unescape(match["name"].replace("&nbsp;", " ")),
283
+ }
284
+ if match["state"] is not None:
285
+ entry["value"] = DIGITAL_INPUT_STATES[match["state"]]
286
+ entry["unit_of_measurement"] = None
287
+ entry["type"] = "digital"
288
+ else:
289
+ # replace decimal "," by "." and remove "&nbsp;" completely
290
+ entry["value"] = match["value"].replace("&nbsp;", "").replace(",", ".")
291
+ entry["unit_of_measurement"] = html.unescape(
292
+ match["unit_of_measurement"].replace("&nbsp;", " ")
293
+ )
294
+ data.append(entry)
221
295
  return data
222
296
 
223
297
  def read_digital_values(self):
@@ -234,18 +308,14 @@ class BLNETWeb(object):
234
308
  )
235
309
  except requests.exceptions.RequestException:
236
310
  return None
237
- # Parse DOM object from HTMLCode
238
- dom = htmldom.HtmlDom().createDom(r.text)
239
311
  # Check if we didn't fail in access
240
- if "BL-Net Zugang verweigert" in dom.find("title").text():
312
+ if "BL-Net Zugang verweigert" in _element_text(r.text, "title"):
241
313
  return None
242
314
  # get the element containing the interesting information
243
- dom = dom.find("div.c")[1]
244
- if dom is None:
315
+ texts = _element_texts(r.text, "div", cls="c")
316
+ if len(texts) < 2:
245
317
  return None
246
-
247
- # filter out the text
248
- data_raw = dom.text()
318
+ data_raw = texts[1]
249
319
 
250
320
  # collect data in an array
251
321
  data = list()
@@ -264,6 +334,17 @@ class BLNETWeb(object):
264
334
  match_dict[key] = html.unescape(value)
265
335
  # and append formatted dict
266
336
  data.append(match_dict)
337
+ # a mixer uses two outputs (open, close) with a common mode
338
+ for match in MIXER_OUTPUT_PATTERN.finditer(data_raw):
339
+ name = html.unescape(match["name"].replace("&nbsp;", " "))
340
+ for id, direction, value in [
341
+ (match["id"], "auf", match["open"]),
342
+ (match["id_close"], "zu", match["close"]),
343
+ ]:
344
+ data.append(
345
+ {"id": id, "name": f"{name} {direction}", "mode": match["mode"], "value": value}
346
+ )
347
+ data.sort(key=lambda entry: int(entry["id"]))
267
348
  return data
268
349
 
269
350
  def set_digital_value(self, digital_id, value):
@@ -1,29 +1,31 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: PyBLNET
3
- Version: 0.10.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/nielstron/pyblnet/
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
+ [![PyPI - Version](https://img.shields.io/pypi/v/pyblnet)](https://pypi.org/project/PyBLNET/)
28
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyblnet)](https://pypi.org/project/PyBLNET/)
27
29
  [![Build status](https://github.com/nielstron/pyblnet/actions/workflows/build.yml/badge.svg)](https://github.com/nielstron/pyblnet/actions/workflows/build.yml)
28
30
  [![Coverage Status](https://coveralls.io/repos/github/nielstron/pyblnet/badge.svg?branch=master)](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] https://www.haus-terra.at/heizung/download/Schnittstelle/Schnittstelle_PC_Bootloader.pdf
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
 
@@ -0,0 +1,9 @@
1
+ pyblnet/__init__.py,sha256=XtfpQ0RcQfjTKETItIrH6cZzGFlNhRK3eapXQNbfGxA,270
2
+ pyblnet/blnet.py,sha256=Nthg9z5vwR5dlZUBVrO7wd-COwLXQD6hy_8qZBpV7UA,8994
3
+ pyblnet/blnet_conn.py,sha256=kuS6EkxTNx3lT390ZZzOg4zB7TNfeMO_b_d4nKuhEiY,15706
4
+ pyblnet/blnet_parser.py,sha256=YBJrhL2t88bCWgrBw1k7EO2FfIocDdUfIGAWH4CKPj4,5915
5
+ pyblnet/blnet_web.py,sha256=OR1SFPpen2qR5UlIxFx3g0vOIL-uHbgnYu-FksdMXvE,14825
6
+ pyblnet-0.12.0.dist-info/licenses/LICENSE.txt,sha256=qLriK0Yi_eGmEwdftMY0hOmBLuYbPHMXDqzc7GZCAps,1077
7
+ pyblnet-0.12.0.dist-info/WHEEL,sha256=rLJE8OLPBZbz7tqxs1yD-wA-ADa1Ec5PuYU-Y_PNWDI,81
8
+ pyblnet-0.12.0.dist-info/METADATA,sha256=Jkrp-NRqmw1AsMfbPHl3oP50DamPFHXa729FDiewALc,4170
9
+ pyblnet-0.12.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: flit 3.12.0
2
+ Generator: flit 4.2.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,9 +0,0 @@
1
- pyblnet/__init__.py,sha256=7m5_JVwdmIuHck6GTDQl8I0sg2Dp_rL_oZRzwx-f7QQ,270
2
- pyblnet/blnet.py,sha256=t4NKLZib_kV-S8ZEnNim8ML52gE99nrWzlt_GZCjxC4,7570
3
- pyblnet/blnet_conn.py,sha256=d02182Zc_K4WVLqchlRL2n4yvzei3p4ig-SdS_RIxuI,12795
4
- pyblnet/blnet_parser.py,sha256=B5C-unY9kaw3S661r0IPjnZ_XIOP38Ux0rN5kI9eZhI,4922
5
- pyblnet/blnet_web.py,sha256=yuC6uef_DaLyVNrar-_0bnj-VIk_AIoFnsABueXmqaY,11776
6
- pyblnet-0.10.0.dist-info/licenses/LICENSE.txt,sha256=qLriK0Yi_eGmEwdftMY0hOmBLuYbPHMXDqzc7GZCAps,1077
7
- pyblnet-0.10.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
8
- pyblnet-0.10.0.dist-info/METADATA,sha256=GYjbdS9NrNWrvWRP8WPmR-gtqkIfy2sfjIo7o0tUhUk,3837
9
- pyblnet-0.10.0.dist-info/RECORD,,