mknx / smarthome

http://mknx.github.io/smarthome/
GNU General Public License v3.0
126 stars 69 forks source link

Network plugin item value not send as payload #186

Open rthill opened 8 years ago

rthill commented 8 years ago

The network plugin documentation claims that you can send the actual item value as:

    [test]
        [[item1]]
            type = str
            nw_udp_send = 11.11.11.11:7777  # sends an UDP packet with the item value as payload

But this does actually not work, this simply sends nothing.

One way of correcting this error is to update the documentation as follows which currently works for me:

    [test]
        [[item1]]
            type = str
            nw_udp_send = 11.11.11.11:7777=itemvalue  # sends an UDP packet with the item value as payload

or by modifying the code which I didn't choose for me. I tested only the following modification in the code which was working too:

diff --git a/plugins/network/__init__.py b/plugins/network/__init__.py
index 4aa2f66..3b8618a 100755
--- a/plugins/network/__init__.py
+++ b/plugins/network/__init__.py
@@ -290,7 +290,10 @@ class Network():
             else:
                 message = message.replace('itemvalue', str(item()))
             host, __, port = addr.partition(':')
-            self.udp(host, port, message)
+            if message:
+                self.udp(host, port, message)
+            else:
+                self.udp(host, port, str(item()))

     def parse_obj(self, obj, obj_type):
         # nw_acl, nw_udp, nw_tcp
ohinckel commented 8 years ago

Inspecting the code it seems that only the check if message is None is simply wrong and should check on an empty string instead, e.g. if message = ''. At least the documentation tells us that the partition() method returns a three-item-tuple with empty strings when separator was not found.