def test_encode(self): """Test encode of message.""" msg = Message() cmd = msg.encode() self.assertEqual(cmd, '0;0;0;0;0;\n') msg.node_id = 1 msg.child_id = 255 msg.type = MessageType.internal msg.sub_type = Internal.I_BATTERY_LEVEL msg.ack = 0 msg.payload = 57 cmd = msg.encode() self.assertEqual(cmd, '1;255;3;0;0;57\n')
def parse_message_to_mqtt(self, data): """Parse a mysensors command string. Return a MQTT topic, payload and qos-level as a tuple. """ msg = Message(data, self) payload = str(msg.payload) msg.payload = "" # prefix/node/child/type/ack/subtype : payload return "/{}".format(msg.encode("/"))[:-2], payload, msg.ack
def _parse_message_to_mqtt(self, data): """Parse a mysensors command string. Return a MQTT topic, payload and qos-level as a tuple. """ msg = Message(data, self) payload = str(msg.payload) msg.payload = '' # prefix/node/child/type/ack/subtype : payload return ('{}/{}'.format(self._out_prefix, msg.encode('/'))[:-2], payload, msg.ack)
def test_encode_bad_message(self): """Test encode of bad message.""" msg = Message() msg.sub_type = 'bad' cmd = msg.encode() self.assertEqual(cmd, None)