mirror of
https://github.com/home-assistant/core.git
synced 2026-10-05 21:57:45 -04:00
correct MQTT subscription filter (#7269)
* correct MQTT subscription filter * wildcard handling (#) fixed * wildcard handling (#) fixed * added tests for topic subscription like +/something/# * function names changed (line too long) * using raw strings for regular expression import order changed
This commit is contained in:
committed by
Paulus Schoutsen
parent
570c5549a9
commit
0e08925259
@@ -209,6 +209,46 @@ class TestMQTT(unittest.TestCase):
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_subscribe_topic_level_wildcard_and_wildcard_root_topic(self):
|
||||
"""Test the subscription of wildcard topics."""
|
||||
mqtt.subscribe(self.hass, '+/test-topic/#', self.record_calls)
|
||||
|
||||
fire_mqtt_message(self.hass, 'hi/test-topic', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
self.assertEqual('hi/test-topic', self.calls[0][0])
|
||||
self.assertEqual('test-payload', self.calls[0][1])
|
||||
|
||||
def test_subscribe_topic_level_wildcard_and_wildcard_subtree_topic(self):
|
||||
"""Test the subscription of wildcard topics."""
|
||||
mqtt.subscribe(self.hass, '+/test-topic/#', self.record_calls)
|
||||
|
||||
fire_mqtt_message(self.hass, 'hi/test-topic/here-iam', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
self.assertEqual('hi/test-topic/here-iam', self.calls[0][0])
|
||||
self.assertEqual('test-payload', self.calls[0][1])
|
||||
|
||||
def test_subscribe_topic_level_wildcard_and_wildcard_level_no_match(self):
|
||||
"""Test the subscription of wildcard topics."""
|
||||
mqtt.subscribe(self.hass, '+/test-topic/#', self.record_calls)
|
||||
|
||||
fire_mqtt_message(self.hass, 'hi/here-iam/test-topic', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_subscribe_topic_level_wildcard_and_wildcard_no_match(self):
|
||||
"""Test the subscription of wildcard topics."""
|
||||
mqtt.subscribe(self.hass, '+/test-topic/#', self.record_calls)
|
||||
|
||||
fire_mqtt_message(self.hass, 'hi/another-test-topic', 'test-payload')
|
||||
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_subscribe_binary_topic(self):
|
||||
"""Test the subscription to a binary topic."""
|
||||
mqtt.subscribe(self.hass, 'test-topic', self.record_calls,
|
||||
|
||||
Reference in New Issue
Block a user