Skip to content

Commit b1c7933

Browse files
committed
viessmann: use callbacks and pass them through
1 parent 59c1912 commit b1c7933

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

viessmann/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ def _set_device_defaults(self):
6464

6565
self._parameters[PLUGIN_ATTR_PROTOCOL] = SDPProtocolViessmann
6666

67+
# use callbacks to enable schedulers
68+
self._use_callbacks = True
69+
6770
#
6871
# methods for standalone mode
6972
#

viessmann/protocol.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def __init__(self, data_received_callback, name=None, **kwargs):
121121
# select controlset for viess_proto
122122
self._controlset = self._controlsets[self._viess_proto]
123123

124-
# make sure we have a basic set of parameters for the TCP connection
124+
# make sure we have a basic set of parameters for the serial connection
125125
self._params = {PLUGIN_ATTR_SERIAL_PORT: '',
126126
PLUGIN_ATTR_SERIAL_BAUD: self._controlset[PLUGIN_ATTR_SERIAL_BAUD],
127127
PLUGIN_ATTR_SERIAL_BSIZE: self._controlset[PLUGIN_ATTR_SERIAL_BSIZE],
@@ -136,12 +136,16 @@ def __init__(self, data_received_callback, name=None, **kwargs):
136136
PLUGIN_ATTR_CB_ON_DISCONNECT: None,
137137
PLUGIN_ATTR_CONNECTION: CONN_SER_DIR}
138138
self._params.update(kwargs)
139-
140139
# check if some of the arguments are usable
141140
self._set_connection_params()
142141

142+
if self._params[PLUGIN_ATTR_CB_ON_CONNECT] or self._params[PLUGIN_ATTR_CB_ON_DISCONNECT]:
143+
use_callbacks = True
144+
else:
145+
use_callbacks = False
146+
143147
# initialize connection
144-
self._get_connection(name=name)
148+
self._get_connection(use_callbacks=use_callbacks, name=name)
145149

146150
# set "method pointers"
147151
self._send_bytes = self._connection._send_bytes
@@ -251,7 +255,7 @@ def _send_init_on_send(self):
251255

252256
return True
253257

254-
def _send(self, data_dict):
258+
def _send(self, data_dict, **kwargs):
255259
"""
256260
send data. data_dict needs to contain the following information:
257261
@@ -265,6 +269,9 @@ def _send(self, data_dict):
265269
:type read_response: bool
266270
:return: Response packet (bytearray) if no error occured, None otherwise
267271
"""
272+
if kwargs:
273+
self.logger.debug(f'got additional kw args {kwargs}')
274+
268275
(packet, responselen) = self._build_payload(data_dict)
269276

270277
# send payload

0 commit comments

Comments
 (0)