Hi,
ich hab das mal selber bei mir zugefügt. Hier der Code, ist sicherlich nicht perfekt, da ich sonst nichts mit python mache. Aber es funktioniert bei mir (brauche es für die Kommunikation mit fhem):
Im __init__.py:
Gruß, Waldemar
ich hab das mal selber bei mir zugefügt. Hier der Code, ist sicherlich nicht perfekt, da ich sonst nichts mit python mache. Aber es funktioniert bei mir (brauche es für die Kommunikation mit fhem):
Im __init__.py:
Code:
def parse_item(self, item): self.parse_obj(item, 'item') if 'nw_udp_send' in item.conf: return self.update_item if 'nw_tcp_send' in item.conf: return self.update_item def update_item(self, item, caller=None, source=None, dest=None): if 'nw_udp_send' in item.conf: addr, __, message = item.conf['nw_udp_send'].partition('=') if message is None: message = str(item()) else: message = message.replace('itemvalue', str(item())) host, __, port = addr.partition(':') self.udp(host, port, message) if 'nw_tcp_send' in item.conf: addr, __, message = item.conf['nw_tcp_send'].partition('=') if message is None: message = str(item()) else: message = message.replace('itemvalue', str(item())) message = message + '\n' host, __, port = addr.partition(':') self.tcp(host, port, message) def tcp(self, host, port, data): try: family, type, proto, canonname, sockaddr = socket.getaddrinfo(host, port)[0] sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((host, int(port))) l = sock.send(data.encode()) sock.close() del(sock) except Exception as e: logger.warning("TCP: Problem sending data to {}:{}: {}".format(host, port, e)) pass else: logger.debug("TCP: Sending data to {}:{}: {}".format(host, port, data))
Kommentar