Skip to content

correct MQTT subscription filter#7269

Merged
balloob merged 6 commits into
home-assistant:devfrom
amigian74:mqtt-filter
May 2, 2017
Merged

correct MQTT subscription filter#7269
balloob merged 6 commits into
home-assistant:devfrom
amigian74:mqtt-filter

Conversation

@amigian74
Copy link
Copy Markdown
Contributor

The current topic filter within the mqtt component won't match something like "+/something/#". This change should work for all subscriptions

Issue: #6449

@mention-bot
Copy link
Copy Markdown

@amigian74, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @pvizeli and @fabaff to be potential reviewers.

@homeassistant
Copy link
Copy Markdown
Contributor

Hi @amigian74,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@balloob
Copy link
Copy Markdown
Member

balloob commented Apr 24, 2017

Please add tests to show that this is working.

Comment thread tests/components/mqtt/test_init.py Outdated
"""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')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (80 > 79 characters)

Comment thread tests/components/mqtt/test_init.py Outdated
"""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')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (81 > 79 characters)

Comment thread tests/components/mqtt/test_init.py Outdated
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):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (87 > 79 characters)

Comment thread tests/components/mqtt/test_init.py Outdated
"""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')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (81 > 79 characters)

Comment thread tests/components/mqtt/test_init.py Outdated
"""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')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (80 > 79 characters)

Comment thread tests/components/mqtt/test_init.py Outdated
"""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')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (81 > 79 characters)

Comment thread tests/components/mqtt/test_init.py Outdated
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):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (87 > 79 characters)

Comment thread tests/components/mqtt/test_init.py Outdated
"""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')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (81 > 79 characters)

@balloob
Copy link
Copy Markdown
Member

balloob commented May 2, 2017

Perfect, thanks! 🐬

@balloob balloob merged commit 0e08925 into home-assistant:dev May 2, 2017
@amigian74 amigian74 deleted the mqtt-filter branch May 4, 2017 11:07
@balloob balloob mentioned this pull request May 5, 2017
if sub_part == "+":
reg_ex_parts.append(r"([^\/]+)")
else:
reg_ex_parts.append(sub_part)
Copy link
Copy Markdown
Contributor

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.

@home-assistant home-assistant locked and limited conversation to collaborators Oct 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants