No update in MQTT Binary Sensor #7478 (#8057)

pull/8055/head
pezinek 2017-06-16 14:55:59 +02:00 committed by Paulus Schoutsen
parent d24b45054a
commit d796e8db5c
2 changed files with 14 additions and 1 deletions

View File

@ -646,7 +646,7 @@ def _match_topic(subscription, topic):
if sub_part == "+":
reg_ex_parts.append(r"([^\/]+)")
else:
reg_ex_parts.append(sub_part)
reg_ex_parts.append(re.escape(sub_part))
reg_ex = "^" + (r'\/'.join(reg_ex_parts)) + suffix + "$"

View File

@ -249,6 +249,19 @@ class TestMQTT(unittest.TestCase):
self.hass.block_till_done()
self.assertEqual(0, len(self.calls))
def test_subscribe_special_characters(self):
"""Test the subscription to topics with special characters."""
topic = '/test-topic/$(.)[^]{-}'
payload = 'p4y.l[]a|> ?'
mqtt.subscribe(self.hass, topic, self.record_calls)
fire_mqtt_message(self.hass, topic, payload)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
self.assertEqual(topic, self.calls[0][0])
self.assertEqual(payload, self.calls[0][1])
def test_subscribe_binary_topic(self):
"""Test the subscription to a binary topic."""
mqtt.subscribe(self.hass, 'test-topic', self.record_calls,