mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Fixed mqtt subscription filter on sys $ topics (#8166)
* Fixed mqtt subscription filter on sys $ topics * fixed linting issue * added unit tests for $ topics and changed fix to use re.escape * merge upstream/dev mqtt unit tests * Update test_init.py
This commit is contained in:
parent
af54311718
commit
23400c4b0a
@ -249,6 +249,40 @@ class TestMQTT(unittest.TestCase):
|
|||||||
self.hass.block_till_done()
|
self.hass.block_till_done()
|
||||||
self.assertEqual(0, len(self.calls))
|
self.assertEqual(0, len(self.calls))
|
||||||
|
|
||||||
|
def test_subscribe_topic_sys_root(self):
|
||||||
|
"""Test the subscription of $ root topics."""
|
||||||
|
mqtt.subscribe(self.hass, '$test-topic/subtree/on', self.record_calls)
|
||||||
|
|
||||||
|
fire_mqtt_message(self.hass, '$test-topic/subtree/on', 'test-payload')
|
||||||
|
|
||||||
|
self.hass.block_till_done()
|
||||||
|
self.assertEqual(1, len(self.calls))
|
||||||
|
self.assertEqual('$test-topic/subtree/on', self.calls[0][0])
|
||||||
|
self.assertEqual('test-payload', self.calls[0][1])
|
||||||
|
|
||||||
|
def test_subscribe_topic_sys_root_and_wildcard_topic(self):
|
||||||
|
"""Test the subscription of $ root and wildcard topics."""
|
||||||
|
mqtt.subscribe(self.hass, '$test-topic/#', self.record_calls)
|
||||||
|
|
||||||
|
fire_mqtt_message(self.hass, '$test-topic/some-topic', 'test-payload')
|
||||||
|
|
||||||
|
self.hass.block_till_done()
|
||||||
|
self.assertEqual(1, len(self.calls))
|
||||||
|
self.assertEqual('$test-topic/some-topic', self.calls[0][0])
|
||||||
|
self.assertEqual('test-payload', self.calls[0][1])
|
||||||
|
|
||||||
|
def test_subscribe_topic_sys_root_and_wildcard_subtree_topic(self):
|
||||||
|
"""Test the subscription of $ root and wildcard subtree topics."""
|
||||||
|
mqtt.subscribe(self.hass, '$test-topic/subtree/#', self.record_calls)
|
||||||
|
|
||||||
|
fire_mqtt_message(self.hass, '$test-topic/subtree/some-topic',
|
||||||
|
'test-payload')
|
||||||
|
|
||||||
|
self.hass.block_till_done()
|
||||||
|
self.assertEqual(1, len(self.calls))
|
||||||
|
self.assertEqual('$test-topic/subtree/some-topic', self.calls[0][0])
|
||||||
|
self.assertEqual('test-payload', self.calls[0][1])
|
||||||
|
|
||||||
def test_subscribe_special_characters(self):
|
def test_subscribe_special_characters(self):
|
||||||
"""Test the subscription to topics with special characters."""
|
"""Test the subscription to topics with special characters."""
|
||||||
topic = '/test-topic/$(.)[^]{-}'
|
topic = '/test-topic/$(.)[^]{-}'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user