forked from martenjacobs/py-otgw-mqtt
-
Notifications
You must be signed in to change notification settings - Fork 2
/
opentherm_tcp.py
44 lines (34 loc) · 1.08 KB
/
opentherm_tcp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from opentherm import OTGWClient
import logging
import socket
log = logging.getLogger(__name__)
class OTGWTcpClient(OTGWClient):
r"""
A skeleton for a TCP-client based
"""
def __init__(self, listener, **kwargs):
super(OTGWTcpClient, self).__init__(listener)
self._args=kwargs
def open(self):
r"""
Open the connection to the OTGW
"""
self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._socket.connect((self._args['ipadress'], self._args['port']))
def close(self):
r"""
Close the connection to the OTGW
"""
self._socket.close()
def write(self, data):
r"""
Write data to the OTGW
Packet inspection with wireshark of the original otmonitor learned
that the command must only be terminated with a \r and not with \r\n
"""
self._socket.sendall("{}\r".format(data.rstrip('\r\n')).encode())
def read(self):
r"""
Read data from the OTGW
"""
return self._socket.recv(128).decode()