pyotgw 2.2.2__tar.gz → 2.3.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.
Files changed (26) hide show
  1. {pyotgw-2.2.2 → pyotgw-2.3.0}/PKG-INFO +33 -5
  2. {pyotgw-2.2.2 → pyotgw-2.3.0}/README.md +18 -2
  3. {pyotgw-2.2.2 → pyotgw-2.3.0}/pyotgw/__init__.py +1 -1
  4. {pyotgw-2.2.2 → pyotgw-2.3.0}/pyotgw/commandprocessor.py +19 -14
  5. {pyotgw-2.2.2 → pyotgw-2.3.0}/pyotgw/connection.py +16 -14
  6. {pyotgw-2.2.2 → pyotgw-2.3.0}/pyotgw/messageprocessor.py +7 -9
  7. {pyotgw-2.2.2 → pyotgw-2.3.0}/pyotgw/messages.py +48 -1
  8. {pyotgw-2.2.2 → pyotgw-2.3.0}/pyotgw/protocol.py +3 -3
  9. {pyotgw-2.2.2 → pyotgw-2.3.0}/pyotgw/pyotgw.py +50 -39
  10. {pyotgw-2.2.2 → pyotgw-2.3.0}/pyotgw/status.py +2 -1
  11. {pyotgw-2.2.2 → pyotgw-2.3.0}/pyotgw/vars.py +45 -20
  12. {pyotgw-2.2.2 → pyotgw-2.3.0}/pyotgw.egg-info/PKG-INFO +33 -5
  13. {pyotgw-2.2.2 → pyotgw-2.3.0}/setup.py +2 -2
  14. {pyotgw-2.2.2 → pyotgw-2.3.0}/tests/test_commandprocessor.py +160 -38
  15. {pyotgw-2.2.2 → pyotgw-2.3.0}/tests/test_messageprocessor.py +13 -19
  16. {pyotgw-2.2.2 → pyotgw-2.3.0}/tests/test_pyotgw.py +43 -6
  17. {pyotgw-2.2.2 → pyotgw-2.3.0}/tests/test_status.py +2 -0
  18. {pyotgw-2.2.2 → pyotgw-2.3.0}/LICENSE +0 -0
  19. {pyotgw-2.2.2 → pyotgw-2.3.0}/pyotgw.egg-info/SOURCES.txt +0 -0
  20. {pyotgw-2.2.2 → pyotgw-2.3.0}/pyotgw.egg-info/dependency_links.txt +0 -0
  21. {pyotgw-2.2.2 → pyotgw-2.3.0}/pyotgw.egg-info/requires.txt +0 -0
  22. {pyotgw-2.2.2 → pyotgw-2.3.0}/pyotgw.egg-info/top_level.txt +0 -0
  23. {pyotgw-2.2.2 → pyotgw-2.3.0}/setup.cfg +0 -0
  24. {pyotgw-2.2.2 → pyotgw-2.3.0}/tests/test_connection.py +0 -0
  25. {pyotgw-2.2.2 → pyotgw-2.3.0}/tests/test_messages.py +0 -0
  26. {pyotgw-2.2.2 → pyotgw-2.3.0}/tests/test_protocol.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: pyotgw
3
- Version: 2.2.2
3
+ Version: 2.3.0
4
4
  Summary: A library to interface with the opentherm gateway through serial or network connection.
5
5
  Home-page: https://github.com/mvn23/pyotgw
6
6
  Author: Milan van Nugteren
@@ -10,12 +10,22 @@ Keywords: opentherm gateway otgw
10
10
  Classifier: Development Status :: 5 - Production/Stable
11
11
  Classifier: Topic :: Software Development :: Libraries
12
12
  Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
13
- Requires-Python: >=3.8
13
+ Requires-Python: >=3.13
14
14
  Description-Content-Type: text/markdown
15
15
  License-File: LICENSE
16
16
  Requires-Dist: pyserial-asyncio-fast
17
-
18
- [![Build Status](https://travis-ci.org/mvn23/pyotgw.svg?branch=master)](https://travis-ci.org/mvn23/pyotgw)
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: home-page
23
+ Dynamic: keywords
24
+ Dynamic: license
25
+ Dynamic: license-file
26
+ Dynamic: requires-dist
27
+ Dynamic: requires-python
28
+ Dynamic: summary
19
29
 
20
30
  # pyotgw
21
31
 
@@ -248,6 +258,8 @@ This method supports the following arguments:
248
258
 
249
259
  Returns the accepted value, `A` if the override is disabled or `None` on failure.
250
260
 
261
+ On PIC16F1847, special state 'P' requests a DHW push. In this case, 'P' is returned on success and None on failure. This special state is never reflected in the status dict as we have no way to determine when this state is no longer active ('PR=W' never returns 'P').
262
+
251
263
  This method is a coroutine.
252
264
 
253
265
  ---
@@ -460,6 +472,8 @@ pre-commit install
460
472
  in the repository.
461
473
 
462
474
  ### Status Dict Structure
475
+ The status dict is split up in 3 parts. It contains a `boiler` (`vars.BOILER`) part, a `thermostat` (`vars.THERMOSTAT`) part and a `gateway` (`vars.OTGW`) part.
476
+ We use a device-based approach to determine where a value is stored: each part contains values as they are seen by the respective device. A value that is reported by the boiler but overridden by the gateway before it is sent to the thermostat will result in a status dict that contains the originally reported value in the `boiler` part and the override value in the `thermostat` part.
463
477
  The full possible status dict with some example values looks like below. Note that not all keys will always be present and that the presence of a key does not guarantee that it contains useful information.
464
478
 
465
479
  ```python
@@ -482,6 +496,13 @@ The full possible status dict with some example values looks like below. Note th
482
496
  vars.DATA_DHW_TEMP: 0.0,
483
497
  vars.DATA_DHW_TEMP_2: 0.0,
484
498
  vars.DATA_EXHAUST_TEMP: 0,
499
+ vars.DATA_HEATEXCH_TEMP: 0,
500
+ vars.DATA_BOILER_FANSPD_SETP: 100,
501
+ vars.DATA_BOILER_FANSPD: 99,
502
+ vars.DATA_BOILER_FLAME_CURRENT: 0,
503
+ vars.DATA_ROOM_TEMP_2: 21.5,
504
+ vars.DATA_REL_HUMIDITY: 42.3,
505
+ vars.DATA_ROOM_SETPOINT_OVRD_2: 20.0,
485
506
  vars.DATA_MASTER_CH2_ENABLED: 0,
486
507
  vars.DATA_MASTER_CH_ENABLED: 1,
487
508
  vars.DATA_MASTER_COOLING_ENABLED: 0,
@@ -584,6 +605,13 @@ The full possible status dict with some example values looks like below. Note th
584
605
  vars.DATA_DHW_TEMP: 0.0,
585
606
  vars.DATA_DHW_TEMP_2: 0.0,
586
607
  vars.DATA_EXHAUST_TEMP: 0,
608
+ vars.DATA_HEATEXCH_TEMP: 0,
609
+ vars.DATA_BOILER_FANSPD_SETP: 100,
610
+ vars.DATA_BOILER_FANSPD: 99,
611
+ vars.DATA_BOILER_FLAME_CURRENT: 0,
612
+ vars.DATA_ROOM_TEMP_2: 21.5,
613
+ vars.DATA_REL_HUMIDITY: 42.3,
614
+ vars.DATA_ROOM_SETPOINT_OVRD_2: 20.0,
587
615
  vars.DATA_MASTER_CH2_ENABLED: 0,
588
616
  vars.DATA_MASTER_CH_ENABLED: 1,
589
617
  vars.DATA_MASTER_COOLING_ENABLED: 0,
@@ -1,5 +1,3 @@
1
- [![Build Status](https://travis-ci.org/mvn23/pyotgw.svg?branch=master)](https://travis-ci.org/mvn23/pyotgw)
2
-
3
1
  # pyotgw
4
2
 
5
3
  A python library to interface with the OpenTherm Gateway
@@ -231,6 +229,8 @@ This method supports the following arguments:
231
229
 
232
230
  Returns the accepted value, `A` if the override is disabled or `None` on failure.
233
231
 
232
+ On PIC16F1847, special state 'P' requests a DHW push. In this case, 'P' is returned on success and None on failure. This special state is never reflected in the status dict as we have no way to determine when this state is no longer active ('PR=W' never returns 'P').
233
+
234
234
  This method is a coroutine.
235
235
 
236
236
  ---
@@ -443,6 +443,8 @@ pre-commit install
443
443
  in the repository.
444
444
 
445
445
  ### Status Dict Structure
446
+ The status dict is split up in 3 parts. It contains a `boiler` (`vars.BOILER`) part, a `thermostat` (`vars.THERMOSTAT`) part and a `gateway` (`vars.OTGW`) part.
447
+ We use a device-based approach to determine where a value is stored: each part contains values as they are seen by the respective device. A value that is reported by the boiler but overridden by the gateway before it is sent to the thermostat will result in a status dict that contains the originally reported value in the `boiler` part and the override value in the `thermostat` part.
446
448
  The full possible status dict with some example values looks like below. Note that not all keys will always be present and that the presence of a key does not guarantee that it contains useful information.
447
449
 
448
450
  ```python
@@ -465,6 +467,13 @@ The full possible status dict with some example values looks like below. Note th
465
467
  vars.DATA_DHW_TEMP: 0.0,
466
468
  vars.DATA_DHW_TEMP_2: 0.0,
467
469
  vars.DATA_EXHAUST_TEMP: 0,
470
+ vars.DATA_HEATEXCH_TEMP: 0,
471
+ vars.DATA_BOILER_FANSPD_SETP: 100,
472
+ vars.DATA_BOILER_FANSPD: 99,
473
+ vars.DATA_BOILER_FLAME_CURRENT: 0,
474
+ vars.DATA_ROOM_TEMP_2: 21.5,
475
+ vars.DATA_REL_HUMIDITY: 42.3,
476
+ vars.DATA_ROOM_SETPOINT_OVRD_2: 20.0,
468
477
  vars.DATA_MASTER_CH2_ENABLED: 0,
469
478
  vars.DATA_MASTER_CH_ENABLED: 1,
470
479
  vars.DATA_MASTER_COOLING_ENABLED: 0,
@@ -567,6 +576,13 @@ The full possible status dict with some example values looks like below. Note th
567
576
  vars.DATA_DHW_TEMP: 0.0,
568
577
  vars.DATA_DHW_TEMP_2: 0.0,
569
578
  vars.DATA_EXHAUST_TEMP: 0,
579
+ vars.DATA_HEATEXCH_TEMP: 0,
580
+ vars.DATA_BOILER_FANSPD_SETP: 100,
581
+ vars.DATA_BOILER_FANSPD: 99,
582
+ vars.DATA_BOILER_FLAME_CURRENT: 0,
583
+ vars.DATA_ROOM_TEMP_2: 21.5,
584
+ vars.DATA_REL_HUMIDITY: 42.3,
585
+ vars.DATA_ROOM_SETPOINT_OVRD_2: 20.0,
570
586
  vars.DATA_MASTER_CH2_ENABLED: 0,
571
587
  vars.DATA_MASTER_CH_ENABLED: 1,
572
588
  vars.DATA_MASTER_COOLING_ENABLED: 0,
@@ -1,5 +1,5 @@
1
1
  """The main pyotgw __init__ file"""
2
2
 
3
- from pyotgw.pyotgw import OpenThermGateway
3
+ from .pyotgw import OpenThermGateway
4
4
 
5
5
  __all__ = ["OpenThermGateway"]
@@ -5,7 +5,7 @@ import logging
5
5
  import re
6
6
  from asyncio.queues import QueueFull
7
7
 
8
- from pyotgw import vars as v
8
+ from . import vars as v
9
9
 
10
10
  _LOGGER = logging.getLogger(__name__)
11
11
 
@@ -44,8 +44,12 @@ class CommandProcessor:
44
44
  async def send_again(err):
45
45
  """Resend the command."""
46
46
  nonlocal retry
47
+ if retry <= 0:
48
+ raise err
47
49
  _LOGGER.warning("Command %s failed with %s, retrying...", cmd, err)
50
+ await asyncio.sleep(0.5)
48
51
  retry -= 1
52
+ self.clear_queue()
49
53
  self.protocol.transport.write(f"{cmd}={value}\r\n".encode("ascii"))
50
54
 
51
55
  async def process(msg):
@@ -53,9 +57,7 @@ class CommandProcessor:
53
57
  _LOGGER.debug("Got possible response for command %s: %s", cmd, msg)
54
58
  if msg in v.OTGW_ERRS:
55
59
  # Some errors appear by themselves on one line.
56
- if retry == 0:
57
- raise v.OTGW_ERRS[msg]
58
- await send_again(msg)
60
+ await send_again(v.OTGW_ERRS[msg])
59
61
  return
60
62
  if cmd == v.OTGW_CMD_MODE and value == "R":
61
63
  # Device was reset, msg contains build info
@@ -66,26 +68,29 @@ class CommandProcessor:
66
68
  if match:
67
69
  if match.group(1) in v.OTGW_ERRS:
68
70
  # Some errors are considered a response.
69
- if retry == 0:
70
- raise v.OTGW_ERRS[match.group(1)]
71
- await send_again(msg)
71
+ await send_again(v.OTGW_ERRS[match.group(1)])
72
72
  return
73
73
  ret = match.group(1)
74
74
  if cmd == v.OTGW_CMD_SUMMARY and ret == "1":
75
75
  # Expects a second line
76
+ # The second line should match the basic structure of a status
77
+ # report. If not, we discard the message.
76
78
  part2 = await self._cmdq.get()
79
+ while not re.match(r"^[01]{8}/[01]{8}(,[\d./]*)+$", part2):
80
+ part2 = await self._cmdq.get()
77
81
  ret = [ret, part2]
78
82
  return ret
79
83
  if re.match(r"Error 0[1-4]", msg):
80
- _LOGGER.warning(
81
- "Received %s. If this happens during a "
82
- "reset of the gateway it can be safely "
83
- "ignored.",
84
- msg,
84
+ if cmd == v.OTGW_CMD_MODE and value == "R":
85
+ return
86
+ error_message = (
87
+ f"Received {msg}. If this happens during a reset of the "
88
+ "gateway it can be safely ignored."
85
89
  )
86
90
  else:
87
- _LOGGER.warning("Unknown message in command queue: %s", msg)
88
- await send_again(msg)
91
+ error_message = f"Unknown message in command queue: {msg}"
92
+ _LOGGER.warning(error_message)
93
+ await send_again(RuntimeError(error_message))
89
94
 
90
95
  while True:
91
96
  msg = await self._cmdq.get()
@@ -11,7 +11,7 @@ from functools import partial
11
11
  import serial
12
12
  import serial_asyncio_fast
13
13
 
14
- from pyotgw.protocol import OpenThermProtocol
14
+ from .protocol import OpenThermProtocol
15
15
 
16
16
  CONNECTION_TIMEOUT = 5
17
17
 
@@ -112,18 +112,19 @@ class ConnectionManager: # pylint: disable=too-many-instance-attributes
112
112
  self._retry_timeout = MIN_RETRY_TIMEOUT
113
113
  while transport is None:
114
114
  try:
115
- transport, protocol = await (
116
- serial_asyncio_fast.create_serial_connection(
117
- loop,
118
- partial(
119
- OpenThermProtocol,
120
- self._otgw.status,
121
- self.watchdog.inform,
122
- ),
123
- self._port,
124
- write_timeout=0,
125
- **self._config,
126
- )
115
+ (
116
+ transport,
117
+ protocol,
118
+ ) = await serial_asyncio_fast.create_serial_connection(
119
+ loop,
120
+ partial(
121
+ OpenThermProtocol,
122
+ self._otgw.status,
123
+ self.watchdog.inform,
124
+ ),
125
+ self._port,
126
+ write_timeout=0,
127
+ **self._config,
127
128
  )
128
129
  await asyncio.wait_for(
129
130
  protocol.init_and_wait_for_activity(),
@@ -131,7 +132,7 @@ class ConnectionManager: # pylint: disable=too-many-instance-attributes
131
132
  )
132
133
  return transport, protocol
133
134
 
134
- except asyncio.TimeoutError as err:
135
+ except TimeoutError as err:
135
136
  if not isinstance(err, type(self._error)):
136
137
  _LOGGER.error(
137
138
  "The serial device on %s is not responding. "
@@ -169,6 +170,7 @@ class ConnectionManager: # pylint: disable=too-many-instance-attributes
169
170
  async def _cleanup(self):
170
171
  """Cleanup possible leftovers from old connections"""
171
172
  await self.watchdog.stop()
173
+ self._otgw.status.reset()
172
174
  if self.protocol:
173
175
  await self.protocol.cleanup()
174
176
  if self._connecting_task is not None:
@@ -1,11 +1,11 @@
1
1
  """OpenTherm Protocol message handler"""
2
+
2
3
  import asyncio
3
4
  import logging
4
5
  import re
5
- import struct
6
6
 
7
- import pyotgw.messages as m
8
- import pyotgw.vars as v
7
+ from . import messages as m
8
+ from . import vars as v
9
9
 
10
10
  _LOGGER = logging.getLogger(__name__)
11
11
 
@@ -205,14 +205,14 @@ class MessageProcessor:
205
205
  """
206
206
  Convert a byte into an unsigned int.
207
207
  """
208
- return struct.unpack(">B", byte)[0]
208
+ return int.from_bytes(byte, "big", signed=False)
209
209
 
210
210
  @staticmethod
211
211
  def _get_s8(byte):
212
212
  """
213
213
  Convert a byte into a signed int.
214
214
  """
215
- return struct.unpack(">b", byte)[0]
215
+ return int.from_bytes(byte, "big", signed=True)
216
216
 
217
217
  def _get_f8_8(self, msb, lsb):
218
218
  """
@@ -224,12 +224,10 @@ class MessageProcessor:
224
224
  """
225
225
  Convert 2 bytes into an unsigned int.
226
226
  """
227
- buf = struct.pack(">BB", self._get_u8(msb), self._get_u8(lsb))
228
- return int(struct.unpack(">H", buf)[0])
227
+ return int.from_bytes(msb + lsb, "big", signed=False)
229
228
 
230
229
  def _get_s16(self, msb, lsb):
231
230
  """
232
231
  Convert 2 bytes into a signed int.
233
232
  """
234
- buf = struct.pack(">bB", self._get_s8(msb), self._get_u8(lsb))
235
- return int(struct.unpack(">h", buf)[0])
233
+ return int.from_bytes(msb + lsb, "big", signed=True)
@@ -1,6 +1,6 @@
1
1
  """Data related to message processing"""
2
2
 
3
- from pyotgw import vars as v
3
+ from . import vars as v
4
4
 
5
5
  _GET_FLAG8 = "_get_flag8"
6
6
  _GET_FLOAT = "_get_f8_8"
@@ -412,6 +412,53 @@ REGISTRY = {
412
412
  }
413
413
  ],
414
414
  },
415
+ v.MSG_THEATEXCH: {
416
+ M2S: [],
417
+ S2M: [
418
+ {FUNC: _GET_FLOAT, ARGS: (_MSB, _LSB), RETURNS: (v.DATA_HEATEXCH_TEMP,)},
419
+ ],
420
+ },
421
+ v.MSG_BOILERFANSPD: {
422
+ M2S: [],
423
+ S2M: [
424
+ {FUNC: _GET_U8, ARGS: (_MSB,), RETURNS: (v.DATA_BOILER_FANSPD_SETP,)},
425
+ {FUNC: _GET_U8, ARGS: (_LSB,), RETURNS: (v.DATA_BOILER_FANSPD,)},
426
+ ],
427
+ },
428
+ v.MSG_FLAMECURRENT: {
429
+ M2S: [],
430
+ S2M: [
431
+ {
432
+ FUNC: _GET_FLOAT,
433
+ ARGS: (
434
+ _MSB,
435
+ _LSB,
436
+ ),
437
+ RETURNS: (v.DATA_BOILER_FLAME_CURRENT,),
438
+ },
439
+ ],
440
+ },
441
+ v.MSG_TROOMCH2: {
442
+ M2S: [{FUNC: _GET_FLOAT, ARGS: (_MSB, _LSB), RETURNS: (v.DATA_ROOM_TEMP_2,)}],
443
+ S2M: [],
444
+ },
445
+ v.MSG_RELHUMIDITY: {
446
+ M2S: [{FUNC: _GET_FLOAT, ARGS: (_MSB, _LSB), RETURNS: (v.DATA_REL_HUMIDITY,)}],
447
+ S2M: [],
448
+ },
449
+ v.MSG_TROVRD2: {
450
+ M2S: [],
451
+ S2M: [
452
+ {
453
+ FUNC: _GET_FLOAT,
454
+ ARGS: (
455
+ _MSB,
456
+ _LSB,
457
+ ),
458
+ RETURNS: (v.DATA_ROOM_SETPOINT_OVRD_2,),
459
+ },
460
+ ],
461
+ },
415
462
  v.MSG_TDHWSETUL: {
416
463
  M2S: [],
417
464
  S2M: [
@@ -4,9 +4,9 @@ import asyncio
4
4
  import logging
5
5
  import re
6
6
 
7
- from pyotgw import vars as v
8
- from pyotgw.commandprocessor import CommandProcessor
9
- from pyotgw.messageprocessor import MessageProcessor
7
+ from . import vars as v
8
+ from .commandprocessor import CommandProcessor
9
+ from .messageprocessor import MessageProcessor
10
10
 
11
11
  _LOGGER = logging.getLogger(__name__)
12
12
 
@@ -2,11 +2,12 @@
2
2
 
3
3
  import asyncio
4
4
  import logging
5
+ from contextlib import suppress
5
6
  from datetime import datetime
6
7
 
7
- from pyotgw import vars as v
8
- from pyotgw.connection import ConnectionManager
9
- from pyotgw.status import StatusManager
8
+ from . import vars as v
9
+ from .connection import ConnectionManager
10
+ from .status import StatusManager
10
11
 
11
12
  _LOGGER = logging.getLogger(__name__)
12
13
 
@@ -83,7 +84,7 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
83
84
  value = f"{temp:2.1f}"
84
85
  ret = await self._wait_for_cmd(cmd, value, timeout)
85
86
  if ret is None:
86
- return None
87
+ return
87
88
  ret = float(ret)
88
89
  if 0 <= ret <= 30:
89
90
  if ret == 0:
@@ -113,10 +114,10 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
113
114
  """
114
115
  cmd = v.OTGW_CMD_TEMP_SENSOR
115
116
  if func not in "OR":
116
- return None
117
+ return
117
118
  ret = await self._wait_for_cmd(cmd, func, timeout)
118
119
  if ret is None:
119
- return None
120
+ return
120
121
  status_otgw = {v.OTGW_TEMP_SENSOR: ret}
121
122
  self.status.submit_partial_update(v.OTGW, status_otgw)
122
123
  return ret
@@ -136,7 +137,7 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
136
137
  cmd = v.OTGW_CMD_OUTSIDE_TEMP
137
138
  status_thermostat = {}
138
139
  if temp < -40:
139
- return None
140
+ return
140
141
  value = f"{temp:2.1f}"
141
142
  ret = await self._wait_for_cmd(cmd, value, timeout)
142
143
  if ret is None:
@@ -149,7 +150,7 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
149
150
  self.status.submit_partial_update(v.THERMOSTAT, status_thermostat)
150
151
  return ret
151
152
 
152
- async def set_clock(self, date=datetime.now(), timeout=v.OTGW_DEFAULT_TIMEOUT):
153
+ async def set_clock(self, date=None, timeout=v.OTGW_DEFAULT_TIMEOUT):
153
154
  """
154
155
  Change the time and day of the week of the thermostat. The
155
156
  gateway will send the specified time and day of the week in
@@ -160,6 +161,8 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
160
161
 
161
162
  This method is a coroutine
162
163
  """
164
+ if date is None:
165
+ date = datetime.now()
163
166
  cmd = v.OTGW_CMD_SET_CLOCK
164
167
  value = f"{date.strftime('%H:%M')}/{date.isoweekday()}"
165
168
  return await self._wait_for_cmd(cmd, value, timeout)
@@ -252,26 +255,29 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
252
255
  async def get_status(self):
253
256
  """
254
257
  Update the OpenThermGateway object with the information from the
255
- PS command and return the updated status dict.
258
+ PS command and return the updated status dict or None on error.
256
259
 
257
260
  This method is a coroutine
258
261
  """
259
262
  cmd = v.OTGW_CMD_SUMMARY
260
263
  ret = await self._wait_for_cmd(cmd, 1)
261
264
  # Return to 'reporting' mode
265
+ asyncio.get_running_loop().create_task(self._wait_for_cmd(cmd, 0))
262
266
  if ret is None:
263
267
  return
264
- asyncio.get_running_loop().create_task(self._wait_for_cmd(cmd, 0))
265
268
  fields = ret[1].split(",")
266
269
  if len(fields) == 34:
267
- # OpenTherm Gateway 5.0
270
+ # OpenTherm Gateway >=5.0
268
271
  boiler_status, thermostat_status = process_statusfields_v5(fields)
269
- else:
272
+ elif len(fields) == 25:
273
+ # OpenTherm Gateway <5.0
270
274
  boiler_status, thermostat_status = process_statusfields_v4(fields)
271
- self.status.submit_full_update({
272
- v.BOILER: boiler_status,
273
- v.THERMOSTAT: thermostat_status
274
- })
275
+ else:
276
+ _LOGGER.error("Received malformed status line: %s", ret[1])
277
+ return
278
+ self.status.submit_full_update(
279
+ {v.BOILER: boiler_status, v.THERMOSTAT: thermostat_status}
280
+ )
275
281
  return self.status.status
276
282
 
277
283
  async def set_hot_water_ovrd(self, state, timeout=v.OTGW_DEFAULT_TIMEOUT):
@@ -284,6 +290,11 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
284
290
  state, or any other single character to disable the override.
285
291
  Return the accepted value, 'A' if the override is disabled
286
292
  or None on failure.
293
+ On PIC16F1847, special state 'P' requests a DHW push. In this
294
+ case, 'P' is returned on success and None on failure.
295
+ This special state is never reflected in the status dict as we
296
+ have no way to determine when this state is no longer active.
297
+ ('PR=W' never returns 'P')
287
298
 
288
299
  This method is a coroutine
289
300
  """
@@ -291,13 +302,12 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
291
302
  status_otgw = {}
292
303
  ret = await self._wait_for_cmd(cmd, state, timeout)
293
304
  if ret is None:
294
- return None
295
- if ret == "A":
296
- status_otgw[v.OTGW_DHW_OVRD] = None
297
- elif ret in ["0", "1"]:
305
+ return
306
+ if ret in ["0", "1"]:
298
307
  ret = int(ret)
308
+ if ret != "P":
299
309
  status_otgw[v.OTGW_DHW_OVRD] = ret
300
- self.status.submit_partial_update(v.OTGW, status_otgw)
310
+ self.status.submit_partial_update(v.OTGW, status_otgw)
301
311
  return ret
302
312
 
303
313
  async def set_mode(self, mode, timeout=v.OTGW_DEFAULT_TIMEOUT):
@@ -315,7 +325,7 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
315
325
  status_otgw = {}
316
326
  ret = await self._wait_for_cmd(cmd, mode, timeout)
317
327
  if ret is None:
318
- return None
328
+ return
319
329
  if mode is v.OTGW_MODE_RESET:
320
330
  self.status.reset()
321
331
  await self.get_reports()
@@ -354,7 +364,7 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
354
364
  status_otgw = {}
355
365
  ret = await self._wait_for_cmd(cmd, mode, timeout)
356
366
  if ret is None:
357
- return None
367
+ return
358
368
  var = getattr(v, f"OTGW_LED_{led_id}")
359
369
  status_otgw[var] = ret
360
370
  self.status.submit_partial_update(v.OTGW, status_otgw)
@@ -389,7 +399,7 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
389
399
  """
390
400
  if gpio_id in "AB" and mode in range(8):
391
401
  if mode == 7 and gpio_id != "B":
392
- return None
402
+ return
393
403
  cmd = getattr(v, f"OTGW_CMD_GPIO_{gpio_id}")
394
404
  status_otgw = {}
395
405
  ret = await self._wait_for_cmd(cmd, mode, timeout)
@@ -437,7 +447,7 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
437
447
  cmd = v.OTGW_CMD_ADD_ALT
438
448
  alt = int(alt)
439
449
  if alt < 1 or alt > 255:
440
- return None
450
+ return
441
451
  ret = await self._wait_for_cmd(cmd, alt, timeout)
442
452
  if ret is not None:
443
453
  return int(ret)
@@ -459,7 +469,7 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
459
469
  cmd = v.OTGW_CMD_DEL_ALT
460
470
  alt = int(alt)
461
471
  if alt < 1 or alt > 255:
462
- return None
472
+ return
463
473
  ret = await self._wait_for_cmd(cmd, alt, timeout)
464
474
  if ret is not None:
465
475
  return int(ret)
@@ -478,7 +488,7 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
478
488
  cmd = v.OTGW_CMD_UNKNOWN_ID
479
489
  unknown_id = int(unknown_id)
480
490
  if unknown_id < 1 or unknown_id > 255:
481
- return None
491
+ return
482
492
  ret = await self._wait_for_cmd(cmd, unknown_id, timeout)
483
493
  if ret is not None:
484
494
  return int(ret)
@@ -495,7 +505,7 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
495
505
  cmd = v.OTGW_CMD_KNOWN_ID
496
506
  unknown_id = int(unknown_id)
497
507
  if unknown_id < 1 or unknown_id > 255:
498
- return None
508
+ return
499
509
  ret = await self._wait_for_cmd(cmd, unknown_id, timeout)
500
510
  if ret is not None:
501
511
  return int(ret)
@@ -546,8 +556,10 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
546
556
 
547
557
  This method is a coroutine
548
558
  """
549
- if isinstance(max_mod, int) and not 0 <= max_mod <= 100:
550
- return None
559
+ with suppress(ValueError):
560
+ max_mod = int(max_mod)
561
+ if not 0 <= max_mod <= 100:
562
+ return
551
563
  cmd = v.OTGW_CMD_MAX_MOD
552
564
  status_boiler = {}
553
565
  ret = await self._wait_for_cmd(cmd, max_mod, timeout)
@@ -609,7 +621,7 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
609
621
  This method is a coroutine
610
622
  """
611
623
  if ch_bit not in [0, 1]:
612
- return None
624
+ return
613
625
  cmd = v.OTGW_CMD_CONTROL_HEATING
614
626
  status_boiler = {}
615
627
  ret = await self._wait_for_cmd(cmd, ch_bit, timeout)
@@ -632,7 +644,7 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
632
644
  This method is a coroutine
633
645
  """
634
646
  if ch_bit not in [0, 1]:
635
- return None
647
+ return
636
648
  cmd = v.OTGW_CMD_CONTROL_HEATING_2
637
649
  status_boiler = {}
638
650
  ret = await self._wait_for_cmd(cmd, ch_bit, timeout)
@@ -652,7 +664,7 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
652
664
  This method is a coroutine
653
665
  """
654
666
  if not 0 <= pct <= 100:
655
- return None
667
+ return
656
668
  cmd = v.OTGW_CMD_VENT
657
669
  status_boiler = {}
658
670
  ret = await self._wait_for_cmd(cmd, pct, timeout)
@@ -677,8 +689,7 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
677
689
 
678
690
  This method is a coroutine
679
691
  """
680
- ret = await self._wait_for_cmd(cmd, state, timeout)
681
- return ret
692
+ return await self._wait_for_cmd(cmd, state, timeout)
682
693
 
683
694
  def subscribe(self, coro):
684
695
  """
@@ -708,13 +719,13 @@ class OpenThermGateway: # pylint: disable=too-many-public-methods
708
719
  This method is a coroutine.
709
720
  """
710
721
  if not self.connection.connected:
711
- return None
722
+ return
712
723
  try:
713
724
  return await asyncio.wait_for(
714
725
  self._protocol.command_processor.issue_cmd(cmd, value),
715
726
  timeout,
716
727
  )
717
- except asyncio.TimeoutError:
728
+ except TimeoutError:
718
729
  _LOGGER.error("Timed out waiting for command: %s, value: %s.", cmd, value)
719
730
  return
720
731
  except (RuntimeError, SyntaxError, ValueError) as exc:
@@ -770,7 +781,7 @@ def process_statusfields_v4(status_fields):
770
781
  """
771
782
  Process the fields of a split status line for OpenTherm Gateway firmware
772
783
  version <5.0.
773
-
784
+
774
785
  Return a tuple of (boiler_status, thermostat_status).
775
786
  """
776
787
  device_status = status_fields[0].split("/")
@@ -833,7 +844,7 @@ def process_statusfields_v5(status_fields):
833
844
  """
834
845
  Process the fields of a split status line for OpenTherm Gateway firmware
835
846
  version >=5.0.
836
-
847
+
837
848
  Return a tuple of (boiler_status, thermostat_status).
838
849
  """
839
850
  device_status = status_fields[0].split("/")