Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions tests/components/mqtt/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,40 @@ def test_subscribe_topic_level_wildcard_and_wildcard_no_match(self):
self.hass.block_till_done()
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):
"""Test the subscription to topics with special characters."""
topic = '/test-topic/$(.)[^]{-}'
Expand Down