aiocomfoconnect 0.4.2__tar.gz → 0.4.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aiocomfoconnect
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: aiocomfoconnect is an asyncio Python 3 library for communicating with a Zehnder ComfoAir Q350/450/600 ventilation system
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -63,11 +63,12 @@ $ python -m aiocomfoconnect set-property --host 192.168.1.213 30 1 4 6 120 # Se
63
63
 
64
64
  ## Available methods
65
65
 
66
- - `async connect()`: Connect to the bridge. The connection is kept: when it is lost, it reconnects, and when nothing was received for `heartbeat_interval` seconds (30 by default, `None` disables it), it checks that the bridge still answers.
66
+ - `async connect()`: Connect to the bridge. The connection is kept: when it is lost, it reconnects, and when nothing was sent or received for `heartbeat_interval` seconds (30 by default, `None` disables it), it asks the bridge for its time. That keeps the bridge from closing the connection (it does so after about 90 seconds in which the client sent nothing, even while it pushes sensor values), and detects a bridge that stopped answering.
67
67
  - `connection_state_callback`: Pass it to `ComfoConnect()` to be called with a `ConnectionState` when the state of the session changes.
68
68
  - `async disconnect()`: Disconnect from the bridge.
69
69
  - `async register_sensor(sensor)`: Register a sensor.
70
70
  - `async deregister_sensor(sensor)`: Deregister a sensor.
71
+ - `sensor_values`: The latest value of every registered sensor, by sensor id, converted like for the sensor callback (`None` until the bridge sent one).
71
72
  - `async get_mode()`: Get the ventilation mode.
72
73
  - `async set_mode(mode)`: Set the ventilation mode. (auto / manual) Selecting `auto` also cancels the temporary fan-speed override and returns control to the unit's schedule.
73
74
  - `async get_comfocool_mode()`: Get Comfocool mode
@@ -85,6 +86,8 @@ $ python -m aiocomfoconnect set-property --host 192.168.1.213 30 1 4 6 120 # Se
85
86
  - `async get_temperature_profile()`: Get the temperature profile, or `None` when no profile is set and the unit follows its schedule.
86
87
  - `async set_temperature_profile(profile)`: Set the temperature profile. (warm / normal / cool)
87
88
  - `async get_property(prop, node_id=None)`: Get the value of a property, e.g. `PROPERTY_RMOT_HEATING_THRESHOLD`. It is read from the node the property lives on: the ventilation unit, or the ComfoClime for the `PROPERTY_CLIME_*` properties. Pass `node_id` to read it from another node. A `NodeNotFoundException` is raised when the node isn't on the bus.
89
+ - `async get_properties(props, node_id=None)`: Get several properties of one node in one request, converted like `get_property`, e.g. `await comfoconnect.get_properties([PROPERTY_MODEL, PROPERTY_SERIAL_NUMBER])`.
90
+ - `async get_node_info(node_id=None)`: Get the `NodeInfo` (name, model, article number, serial number, firmware version and hardware version) of a node, the ventilation unit by default, in one request. A property that the node doesn't have, like the model of the bridge, is `None`.
88
91
  - `async set_property(prop, value, node_id=None)`: Set a property, on the same node as `get_property`.
89
92
  - The airflow in m³/h of each fan speed is a property: `PROPERTY_FLOW_AWAY`, `PROPERTY_FLOW_LOW`, `PROPERTY_FLOW_MEDIUM` and `PROPERTY_FLOW_HIGH`, e.g. `await comfoconnect.set_property(PROPERTY_FLOW_LOW, 120)`.
90
93
  - Properties that are an enum, like `PROPERTY_SENSOR_VENTILATION_TEMP_PASSIVE`, `PROPERTY_SENSOR_VENTILATION_HUMIDITY_COMFORT` and `PROPERTY_SENSOR_VENTILATION_HUMIDITY_PROTECTION` (off / auto / on), `PROPERTY_TEMPERATURE_PROFILE_MODE` (adaptive / fixed), `PROPERTY_CLIME_SEASON` and `PROPERTY_CLIME_TEMPERATURE_PROFILE`, have `options`: `get_property` returns the option and `set_property` takes it. `get_property_constraints` still uses the raw values.
@@ -45,11 +45,12 @@ $ python -m aiocomfoconnect set-property --host 192.168.1.213 30 1 4 6 120 # Se
45
45
 
46
46
  ## Available methods
47
47
 
48
- - `async connect()`: Connect to the bridge. The connection is kept: when it is lost, it reconnects, and when nothing was received for `heartbeat_interval` seconds (30 by default, `None` disables it), it checks that the bridge still answers.
48
+ - `async connect()`: Connect to the bridge. The connection is kept: when it is lost, it reconnects, and when nothing was sent or received for `heartbeat_interval` seconds (30 by default, `None` disables it), it asks the bridge for its time. That keeps the bridge from closing the connection (it does so after about 90 seconds in which the client sent nothing, even while it pushes sensor values), and detects a bridge that stopped answering.
49
49
  - `connection_state_callback`: Pass it to `ComfoConnect()` to be called with a `ConnectionState` when the state of the session changes.
50
50
  - `async disconnect()`: Disconnect from the bridge.
51
51
  - `async register_sensor(sensor)`: Register a sensor.
52
52
  - `async deregister_sensor(sensor)`: Deregister a sensor.
53
+ - `sensor_values`: The latest value of every registered sensor, by sensor id, converted like for the sensor callback (`None` until the bridge sent one).
53
54
  - `async get_mode()`: Get the ventilation mode.
54
55
  - `async set_mode(mode)`: Set the ventilation mode. (auto / manual) Selecting `auto` also cancels the temporary fan-speed override and returns control to the unit's schedule.
55
56
  - `async get_comfocool_mode()`: Get Comfocool mode
@@ -67,6 +68,8 @@ $ python -m aiocomfoconnect set-property --host 192.168.1.213 30 1 4 6 120 # Se
67
68
  - `async get_temperature_profile()`: Get the temperature profile, or `None` when no profile is set and the unit follows its schedule.
68
69
  - `async set_temperature_profile(profile)`: Set the temperature profile. (warm / normal / cool)
69
70
  - `async get_property(prop, node_id=None)`: Get the value of a property, e.g. `PROPERTY_RMOT_HEATING_THRESHOLD`. It is read from the node the property lives on: the ventilation unit, or the ComfoClime for the `PROPERTY_CLIME_*` properties. Pass `node_id` to read it from another node. A `NodeNotFoundException` is raised when the node isn't on the bus.
71
+ - `async get_properties(props, node_id=None)`: Get several properties of one node in one request, converted like `get_property`, e.g. `await comfoconnect.get_properties([PROPERTY_MODEL, PROPERTY_SERIAL_NUMBER])`.
72
+ - `async get_node_info(node_id=None)`: Get the `NodeInfo` (name, model, article number, serial number, firmware version and hardware version) of a node, the ventilation unit by default, in one request. A property that the node doesn't have, like the model of the bridge, is `None`.
70
73
  - `async set_property(prop, value, node_id=None)`: Set a property, on the same node as `get_property`.
71
74
  - The airflow in m³/h of each fan speed is a property: `PROPERTY_FLOW_AWAY`, `PROPERTY_FLOW_LOW`, `PROPERTY_FLOW_MEDIUM` and `PROPERTY_FLOW_HIGH`, e.g. `await comfoconnect.set_property(PROPERTY_FLOW_LOW, 120)`.
72
75
  - Properties that are an enum, like `PROPERTY_SENSOR_VENTILATION_TEMP_PASSIVE`, `PROPERTY_SENSOR_VENTILATION_HUMIDITY_COMFORT` and `PROPERTY_SENSOR_VENTILATION_HUMIDITY_PROTECTION` (off / auto / on), `PROPERTY_TEMPERATURE_PROFILE_MODE` (adaptive / fixed), `PROPERTY_CLIME_SEASON` and `PROPERTY_CLIME_TEMPERATURE_PROFILE`, have `options`: `get_property` returns the option and `set_property` takes it. `get_property_constraints` still uses the raw values.
@@ -13,7 +13,7 @@ from aiocomfoconnect import DEFAULT_NAME, DEFAULT_PIN, DEFAULT_UUID
13
13
  from aiocomfoconnect.comfoconnect import ComfoConnect
14
14
  from aiocomfoconnect.const import ProductId
15
15
  from aiocomfoconnect.discovery import discover_bridges
16
- from aiocomfoconnect.exceptions import BridgeNotFoundException, ComfoConnectNotAllowed
16
+ from aiocomfoconnect.exceptions import AioComfoConnectError, BridgeNotFoundException, ComfoConnectNotAllowed
17
17
  from aiocomfoconnect.properties import Property
18
18
  from aiocomfoconnect.sensors import SENSORS
19
19
 
@@ -24,6 +24,9 @@ PRODUCT_NAMES = {value: name.lower() for name, value in vars(ProductId).items()
24
24
  # How long show-sensor waits for the first value. The bridge only reports a sensor after the sensor hold (5 seconds by default).
25
25
  SENSOR_VALUE_TIMEOUT = 30
26
26
 
27
+ # How long list-nodes waits for the nodes to be announced. The bridge announces its own node a bit after connecting.
28
+ NODE_REQUEST_WAIT = 2
29
+
27
30
 
28
31
  class CliError(Exception):
29
32
  """An error that is shown to the user without a traceback."""
@@ -191,12 +194,25 @@ async def run_list_nodes(args):
191
194
  async with connected(args) as comfoconnect:
192
195
  await comfoconnect.cmd_node_request()
193
196
  # Nodes arrive as unsolicited notifications, so give the bridge a moment to report them all.
194
- await asyncio.sleep(2)
197
+ await asyncio.sleep(NODE_REQUEST_WAIT)
195
198
 
196
199
  print("Nodes on the ComfoNet bus:")
197
200
  for node in sorted(comfoconnect.nodes.values(), key=lambda n: n.node_id):
198
201
  product = PRODUCT_NAMES.get(node.product_id, "unknown")
199
202
  print(f"* node {node.node_id}: product {node.product_id} ({product}), zone {node.zone_id}, mode {node.mode}")
203
+ try:
204
+ info = await comfoconnect.get_node_info(node.node_id)
205
+ except AioComfoConnectError as exc:
206
+ print(f" could not read the node info: {exc}")
207
+ continue
208
+ fields = {
209
+ "name": info.name,
210
+ "model": info.model,
211
+ "firmware": info.firmware,
212
+ "hardware version": info.hardware_version,
213
+ "serial number": info.serial_number,
214
+ }
215
+ print(" " + ", ".join(f"{label}: {value}" for label, value in fields.items() if value is not None))
200
216
 
201
217
 
202
218
  def build_parser() -> argparse.ArgumentParser:
@@ -119,8 +119,9 @@ class Bridge:
119
119
  self.__alarm_callback_fn: Optional[Callable[[int, ProtobufMessage], None]] = None
120
120
 
121
121
  self._read_task = None
122
- # The time.monotonic() of the last message we received from the bridge.
122
+ # The time.monotonic() of the last message we received from the bridge, and of the last one we sent.
123
123
  self._last_received: float = 0
124
+ self._last_sent: float = 0
124
125
 
125
126
  def __repr__(self):
126
127
  return f"<Bridge {self.host}, UID={self.uuid}>"
@@ -182,7 +183,7 @@ class Bridge:
182
183
 
183
184
  self._reference = itertools.count(1)
184
185
  self._local_uuid = uuid
185
- self._last_received = time.monotonic()
186
+ self._last_received = self._last_sent = time.monotonic()
186
187
  self._pending = {}
187
188
 
188
189
  # The bridge announces its nodes at the start of every session, so forget what we knew.
@@ -407,6 +408,7 @@ class Bridge:
407
408
  try:
408
409
  self._writer.write(message.encode())
409
410
  await self._writer.drain()
411
+ self._last_sent = time.monotonic()
410
412
  except (ConnectionError, OSError) as exc:
411
413
  _LOGGER.warning("Failed to send message: %s", exc)
412
414
  raise AioComfoConnectNotConnected("Connection lost while sending") from exc
@@ -45,11 +45,21 @@ from aiocomfoconnect.exceptions import (
45
45
  ComfoConnectError,
46
46
  ComfoConnectNotAllowed,
47
47
  ComfoConnectOtherSession,
48
+ ComfoConnectRmiError,
48
49
  NodeNotFoundException,
49
50
  )
50
- from aiocomfoconnect.properties import Property, PropertyConstraints
51
+ from aiocomfoconnect.properties import (
52
+ PROPERTY_ARTICLE,
53
+ PROPERTY_FIRMWARE_VERSION,
54
+ PROPERTY_HARDWARE_VERSION,
55
+ PROPERTY_MODEL,
56
+ PROPERTY_NAME,
57
+ PROPERTY_SERIAL_NUMBER,
58
+ Property,
59
+ PropertyConstraints,
60
+ )
51
61
  from aiocomfoconnect.sensors import Sensor
52
- from aiocomfoconnect.util import bytearray_to_bits, bytestring, encode_pdo_value, version_decode
62
+ from aiocomfoconnect.util import bytearray_to_bits, encode_pdo_value, version_decode
53
63
 
54
64
  _LOGGER = logging.getLogger(__name__)
55
65
 
@@ -68,6 +78,50 @@ BYPASS_MODES = (VentilationSetting.AUTO, VentilationSetting.ON, VentilationSetti
68
78
  TEMPERATURE_PROFILES = (VentilationTemperatureProfile.NORMAL, VentilationTemperatureProfile.COOL, VentilationTemperatureProfile.WARM)
69
79
 
70
80
 
81
+ # The size in bytes of the value of the property types that aren't a string.
82
+ VALUE_SIZES = {PdoType.TYPE_CN_BOOL: 1, PdoType.TYPE_CN_VERSION: 4} | {pdo_type: size for pdo_type, (size, _) in NUMERIC_PROPERTY_TYPES.items()}
83
+
84
+
85
+ def _decode_value(property_type: Optional[int], raw: bytes) -> Any:
86
+ """Decode the raw value of a property of the given type. A type we don't know is returned as bytes."""
87
+ if property_type == PdoType.TYPE_CN_STRING:
88
+ return raw.decode("utf-8").rstrip("\x00")
89
+ if property_type in NUMERIC_PROPERTY_TYPES:
90
+ _, signed = NUMERIC_PROPERTY_TYPES[property_type]
91
+ return int.from_bytes(raw, byteorder="little", signed=signed)
92
+ if property_type == PdoType.TYPE_CN_BOOL:
93
+ return bool(raw[0])
94
+ if property_type == PdoType.TYPE_CN_VERSION:
95
+ return version_decode(int.from_bytes(raw, byteorder="little"))
96
+ return raw
97
+
98
+
99
+ def _sensor_value(sensor: Sensor, raw: int) -> Any:
100
+ """Convert the raw value of a sensor."""
101
+ return sensor.value_fn(raw) if sensor.value_fn else round(raw, 2)
102
+
103
+
104
+ def _property_value(prop: Property, value: Any) -> Any:
105
+ """Return the option or the scaled value of a decoded property value."""
106
+ if prop.options is None:
107
+ return prop.scaled(value)
108
+ if value not in prop.options:
109
+ raise ValueError(f"Invalid value: {value}")
110
+ return prop.options[value]
111
+
112
+
113
+ @dataclass
114
+ class NodeInfo:
115
+ """What a node tells about itself. A property that the node doesn't have is None, e.g. the model of the bridge."""
116
+
117
+ name: Optional[str]
118
+ model: Optional[str]
119
+ article_number: Optional[str]
120
+ serial_number: Optional[str]
121
+ firmware: Optional[str]
122
+ hardware_version: Optional[int]
123
+
124
+
71
125
  @dataclass
72
126
  class TimerEntry:
73
127
  """A timer of the SCHEDULE unit, that overrides a setting with a value for a while."""
@@ -96,8 +150,9 @@ class ComfoConnect(Bridge):
96
150
  ):
97
151
  """Initialize the ComfoConnect class.
98
152
 
99
- When we received nothing for heartbeat_interval seconds, we ask the bridge for its time, and reconnect when it
100
- doesn't answer. This detects a bridge that stopped answering without closing the connection. None disables it.
153
+ When we sent or received nothing for heartbeat_interval seconds, we ask the bridge for its time, and reconnect when
154
+ it doesn't answer. This keeps the bridge from closing a connection on which we send nothing, and detects a bridge
155
+ that stopped answering without closing the connection. None disables it.
101
156
 
102
157
  The connection_state_callback is called with a ConnectionState when the state of the session changes.
103
158
  """
@@ -236,10 +291,15 @@ class ComfoConnect(Bridge):
236
291
  _LOGGER.info("Reconnect loop stopped")
237
292
 
238
293
  async def _wait_for_disconnect(self):
239
- """Wait until the connection is lost, or until the bridge doesn't answer the heartbeat."""
294
+ """Wait until the connection is lost, or until the bridge doesn't answer the heartbeat.
295
+
296
+ The heartbeat asks the bridge for its time when we sent or received nothing for heartbeat_interval seconds. The
297
+ bridge closes a connection on which we sent nothing for about 90 seconds, also while it pushes sensor values, and a
298
+ bridge that stopped answering doesn't send anything.
299
+ """
240
300
  # The read task ends when the connection is lost. It has already logged why.
241
301
  while not self._read_task.done():
242
- idle = time.monotonic() - self._last_received
302
+ idle = time.monotonic() - min(self._last_sent, self._last_received)
243
303
  if self.heartbeat_interval is None or idle < self.heartbeat_interval:
244
304
  timeout = None if self.heartbeat_interval is None else self.heartbeat_interval - idle
245
305
  await asyncio.wait([self._read_task], timeout=timeout)
@@ -253,6 +313,18 @@ class ComfoConnect(Bridge):
253
313
  _LOGGER.warning("The bridge did not answer the heartbeat")
254
314
  return
255
315
 
316
+ @property
317
+ def sensor_values(self) -> Dict[int, Any]:
318
+ """The latest value of every subscribed sensor, by sensor id, converted like for the sensor callback.
319
+
320
+ A value is None until the bridge sent one. Right after subscribing, it can be the invalid value that the bridge
321
+ sends first, which the sensor callback holds back (see sensor_delay).
322
+ """
323
+ return {
324
+ sensor_id: None if self._sensors_values.get(sensor_id) is None else _sensor_value(sensor, self._sensors_values[sensor_id])
325
+ for sensor_id, sensor in self._sensors.items()
326
+ }
327
+
256
328
  @property
257
329
  def connection_state(self) -> str:
258
330
  """The state of the session, one of ConnectionState. Unlike is_connected(), this is only CONNECTED once the session is up."""
@@ -365,27 +437,76 @@ class ComfoConnect(Bridge):
365
437
  async def get_property(self, prop: Property, node_id: Optional[int] = None) -> Any:
366
438
  """Get a property from the node it lives on (or node_id), and convert it to the right type, its option or its scaled value."""
367
439
  value = await self.get_single_property(prop.unit, prop.subunit, prop.property_id, prop.property_type, node_id=self._node_id_for(prop, node_id))
368
- if prop.options is None:
369
- return prop.scaled(value)
370
- if value not in prop.options:
371
- raise ValueError(f"Invalid value: {value}")
372
- return prop.options[value]
440
+ return _property_value(prop, value)
441
+
442
+ async def get_properties(self, props: List[Property], node_id: Optional[int] = None) -> List[Any]:
443
+ """Get several properties of one node in one request, converted like get_property.
444
+
445
+ The properties are read in groups of consecutive properties of the same unit and subunit, of at most 7 like the
446
+ official app. A ValueError is raised for properties on different nodes, or of a type whose size we don't know.
447
+ """
448
+ node_ids = {self._node_id_for(prop, node_id) for prop in props}
449
+ if len(node_ids) > 1:
450
+ raise ValueError("The properties live on different nodes")
451
+ for prop in props:
452
+ if prop.property_type != PdoType.TYPE_CN_STRING and prop.property_type not in VALUE_SIZES:
453
+ raise ValueError(f"Property type {prop.property_type} can't be read with other properties")
454
+
455
+ groups: List[List[Property]] = []
456
+ for prop in props:
457
+ if groups and len(groups[-1]) < 7 and (groups[-1][0].unit, groups[-1][0].subunit) == (prop.unit, prop.subunit):
458
+ groups[-1].append(prop)
459
+ else:
460
+ groups.append([prop])
461
+
462
+ request = [0x02, len(groups)]
463
+ for group in groups:
464
+ request += [group[0].unit, group[0].subunit, 0x10 | len(group)] + [prop.property_id for prop in group]
465
+ result = await self.cmd_rmi_request(bytes(request), node_id=node_ids.pop() if node_ids else None)
466
+
467
+ # The values follow each other: a string ends with a NUL, the other types have a fixed size.
468
+ message = bytes(result.message)
469
+ values = []
470
+ for prop in props:
471
+ if prop.property_type == PdoType.TYPE_CN_STRING:
472
+ size = message.find(b"\x00") + 1 or len(message)
473
+ else:
474
+ size = VALUE_SIZES[prop.property_type]
475
+ if len(message) < size:
476
+ raise ValueError(f"The response is too short for the value of property {prop.property_id}")
477
+ values.append(_property_value(prop, _decode_value(prop.property_type, message[:size])))
478
+ message = message[size:]
479
+ if message:
480
+ raise ValueError(f"Unexpected {len(message)} bytes at the end of the response")
481
+ return values
482
+
483
+ async def get_node_info(self, node_id: Optional[int] = None) -> NodeInfo:
484
+ """Get the NodeInfo of a node (the ventilation unit by default), in one request when the node has all its properties.
485
+
486
+ Raises ComfoConnectRmiError when none of the properties can be read, e.g. for a node that doesn't exist.
487
+ """
488
+ props = [PROPERTY_NAME, PROPERTY_MODEL, PROPERTY_ARTICLE, PROPERTY_SERIAL_NUMBER, PROPERTY_FIRMWARE_VERSION, PROPERTY_HARDWARE_VERSION]
489
+ try:
490
+ return NodeInfo(*await self.get_properties(props, node_id))
491
+ except ComfoConnectRmiError as exc:
492
+ error = exc
493
+
494
+ # A request fails as a whole when the node lacks one of the properties, so read them one by one.
495
+ async def get_or_none(prop: Property) -> Any:
496
+ try:
497
+ return await self.get_property(prop, node_id)
498
+ except ComfoConnectRmiError:
499
+ return None
500
+
501
+ values = [await get_or_none(prop) for prop in props]
502
+ if all(value is None for value in values):
503
+ raise error # Nothing could be read, e.g. the node doesn't exist.
504
+ return NodeInfo(*values)
373
505
 
374
506
  async def get_single_property(self, unit: int, subunit: int, property_id: int, property_type: int = None, node_id: Optional[int] = None) -> Any:
375
507
  """Get a property and convert to the right type."""
376
508
  result = await self.cmd_rmi_request(bytes([0x01, unit, subunit, 0x10, property_id]), node_id=node_id)
377
-
378
- if property_type == PdoType.TYPE_CN_STRING:
379
- return result.message.decode("utf-8").rstrip("\x00")
380
- if property_type in NUMERIC_PROPERTY_TYPES:
381
- _, signed = NUMERIC_PROPERTY_TYPES[property_type]
382
- return int.from_bytes(result.message, byteorder="little", signed=signed)
383
- if property_type == PdoType.TYPE_CN_BOOL:
384
- return bool(result.message[0])
385
- if property_type == PdoType.TYPE_CN_VERSION:
386
- return version_decode(int.from_bytes(result.message, byteorder="little"))
387
-
388
- return result.message
509
+ return _decode_value(property_type, result.message)
389
510
 
390
511
  async def get_property_constraints(self, prop: Property, node_id: Optional[int] = None) -> PropertyConstraints:
391
512
  """Get the (scaled) value of a numeric property, together with the range and step size the unit accepts, in one request."""
@@ -402,12 +523,6 @@ class ComfoConnect(Bridge):
402
523
  value, minimum, maximum, step = (int.from_bytes(message[i : i + size], byteorder="little", signed=signed) for i in range(0, 4 * size, size))
403
524
  return PropertyConstraints(value=prop.scaled(value), minimum=prop.scaled(minimum), maximum=prop.scaled(maximum), step=prop.scaled(step))
404
525
 
405
- async def get_multiple_properties(self, unit: int, subunit: int, property_ids: List[int], node_id: Optional[int] = None) -> Any:
406
- """Get multiple properties."""
407
- result = await self.cmd_rmi_request(bytestring([0x02, unit, subunit, 0x01, 0x10 | len(property_ids), bytes(property_ids)]), node_id=node_id)
408
-
409
- return result.message
410
-
411
526
  async def set_property(self, prop: Property, value: int | float | str, node_id: Optional[int] = None) -> Any:
412
527
  """Set a property on the node it lives on (or node_id), encoded for its type.
413
528
 
@@ -428,9 +543,6 @@ class ComfoConnect(Bridge):
428
543
 
429
544
  def _sensor_callback(self, sensor_id, sensor_value):
430
545
  """Callback function for sensor updates."""
431
- if self._sensor_callback_fn is None:
432
- return
433
-
434
546
  sensor = self._sensors.get(sensor_id)
435
547
  if sensor is None:
436
548
  # After a quick reconnect, the bridge can still push the sensors of our previous session before we subscribe again.
@@ -448,11 +560,8 @@ class ComfoConnect(Bridge):
448
560
  _LOGGER.debug("Got a valid value for sensor %s, releasing the hold", sensor_id)
449
561
  self._sensor_holds.pop(sensor_id).cancel()
450
562
 
451
- if sensor.value_fn:
452
- val = sensor.value_fn(sensor_value)
453
- else:
454
- val = round(sensor_value, 2)
455
- self._sensor_callback_fn(sensor, val)
563
+ if self._sensor_callback_fn is not None:
564
+ self._sensor_callback_fn(sensor, _sensor_value(sensor, sensor_value))
456
565
 
457
566
  def _alarm_callback(self, node_id, alarm):
458
567
  """Callback function for alarm updates."""
@@ -50,6 +50,7 @@ class PropertyConstraints:
50
50
 
51
51
 
52
52
  PROPERTY_SERIAL_NUMBER = Property(UNIT_NODE, 0x01, 0x04, PdoType.TYPE_CN_STRING)
53
+ PROPERTY_HARDWARE_VERSION = Property(UNIT_NODE, 0x01, 0x05, PdoType.TYPE_CN_UINT8)
53
54
  PROPERTY_FIRMWARE_VERSION = Property(UNIT_NODE, 0x01, 0x06, PdoType.TYPE_CN_VERSION) # A UINT32, decoded with version_decode().
54
55
  PROPERTY_MODEL = Property(UNIT_NODE, 0x01, 0x08, PdoType.TYPE_CN_STRING)
55
56
  PROPERTY_ARTICLE = Property(UNIT_NODE, 0x01, 0x0B, PdoType.TYPE_CN_STRING)
@@ -5,11 +5,6 @@ from __future__ import annotations
5
5
  from aiocomfoconnect.const import NUMERIC_PROPERTY_TYPES, PdoType
6
6
 
7
7
 
8
- def bytestring(arr):
9
- """Join an array of bytes into a bytestring. Unlike `bytes()`, this method supports a mixed array with integers and bytes."""
10
- return b"".join([i if isinstance(i, bytes) else bytes([i]) for i in arr])
11
-
12
-
13
8
  def bytearray_to_bits(arr):
14
9
  """Convert a bytearray to a list of set bits."""
15
10
  bits = []
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "aiocomfoconnect"
3
- version = "0.4.2"
3
+ version = "0.4.4"
4
4
  description = "aiocomfoconnect is an asyncio Python 3 library for communicating with a Zehnder ComfoAir Q350/450/600 ventilation system"
5
5
  authors = ["Michaël Arnauts <michael.arnauts@gmail.com>"]
6
6
  license = "MIT"
File without changes