Skip to content

Commit 08a335a

Browse files
Add support for sending unsolicited messages from device
This is used in the gamry device. It sends a "charge complete" message some seconds after being sent a command to "start charging". This is accomplished by code similar to the following in the device StreamInterface: def charged(self): self.handler.unsolicitedReply("STOPPED") def start_charging(self): t = Timer(self.charging_time, self.charged) t.start() return "STARTED"
1 parent 1251641 commit 08a335a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/lewis/adapters/stream.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def __init__(self, sock, target, stream_server):
4343
self._buffer = []
4444

4545
self._stream_server = stream_server
46+
self._target.handler = self
4647

4748
self._set_logging_context(target)
4849
self.log.info('Client connected from %s:%s', *sock.getpeername())
@@ -108,6 +109,10 @@ def found_terminator(self):
108109

109110
self._send_reply(reply)
110111

112+
def unsolicitedReply(self, reply):
113+
self.log.debug('Sending unsolicited reply %s', reply)
114+
self.push(b(reply + self._target.out_terminator))
115+
111116
def handle_close(self):
112117
self.log.info('Closing connection to client %s:%s', *self.socket.getpeername())
113118
self._stream_server.remove_handler(self)

0 commit comments

Comments
 (0)