-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
correct MQTT subscription filter #7269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
6a0bba6
1165f70
d789856
ee2dc4b
32bee57
cefd353
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -209,6 +209,46 @@ def test_subscribe_topic_subtree_wildcard_no_match(self): | |
| 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, 'hello/test-topic', 'test-payload') | ||
|
|
||
| self.hass.block_till_done() | ||
| self.assertEqual(1, len(self.calls)) | ||
| self.assertEqual('hello/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, 'hello/test-topic/here-iam', 'test-payload') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (81 > 79 characters) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (81 > 79 characters) |
||
|
|
||
| self.hass.block_till_done() | ||
| self.assertEqual(1, len(self.calls)) | ||
| self.assertEqual('hello/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_wildcard_no_match(self): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (87 > 79 characters) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (87 > 79 characters) |
||
| """Test the subscription of wildcard topics.""" | ||
| mqtt.subscribe(self.hass, '+/test-topic/#', self.record_calls) | ||
|
|
||
| fire_mqtt_message(self.hass, 'hello/here-iam/test-topic', 'test-payload') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (81 > 79 characters) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (81 > 79 characters) |
||
|
|
||
| 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, 'hello/another-test-topic', 'test-payload') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (80 > 79 characters) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (80 > 79 characters) |
||
|
|
||
| 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, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not escaping the characters that do have special meaning in regular expressions, and in fact causes issue #7478. Using regular expressions in case where both subscription and topic are variables is only asking for troubles and this fix should be reverted IMO.