Pass Message object to MQTT message callbacks (#21959)

* Pass Message object to MQTT message callbacks

* Improve method of detecting deprecated msg callback

* Fix mysensors

* Fixup

* Review comments

* Fix merge error
This commit is contained in:
emontnemery authored and Paulus Schoutsen committed 2019-03-13 12:58:20 -07:00
1 parent 50ec3d7de5
commit 5957e4b75b
19 files changed
+203 -142

No files matched your search

+20 -20
View File
@@ -316,8 +316,8 @@ class TestMQTTCallbacks(unittest.TestCase):
self.hass.block_till_done()
assert 1 == len(self.calls)
assert 'test-topic' == self.calls[0][0]
assert 'test-payload' == self.calls[0][1]
assert 'test-topic' == self.calls[0][0].topic
assert 'test-payload' == self.calls[0][0].payload
unsub()
@@ -343,8 +343,8 @@ class TestMQTTCallbacks(unittest.TestCase):
self.hass.block_till_done()
assert 1 == len(self.calls)
assert 'test-topic/bier/on' == self.calls[0][0]
assert 'test-payload' == self.calls[0][1]
assert 'test-topic/bier/on' == self.calls[0][0].topic
assert 'test-payload' == self.calls[0][0].payload
def test_subscribe_topic_level_wildcard_no_subtree_match(self):
"""Test the subscription of wildcard topics."""
@@ -372,8 +372,8 @@ class TestMQTTCallbacks(unittest.TestCase):
self.hass.block_till_done()
assert 1 == len(self.calls)
assert 'test-topic/bier/on' == self.calls[0][0]
assert 'test-payload' == self.calls[0][1]
assert 'test-topic/bier/on' == self.calls[0][0].topic
assert 'test-payload' == self.calls[0][0].payload
def test_subscribe_topic_subtree_wildcard_root_topic(self):
"""Test the subscription of wildcard topics."""
@@ -383,8 +383,8 @@ class TestMQTTCallbacks(unittest.TestCase):
self.hass.block_till_done()
assert 1 == len(self.calls)
assert 'test-topic' == self.calls[0][0]
assert 'test-payload' == self.calls[0][1]
assert 'test-topic' == self.calls[0][0].topic
assert 'test-payload' == self.calls[0][0].payload
def test_subscribe_topic_subtree_wildcard_no_match(self):
"""Test the subscription of wildcard topics."""
@@ -403,8 +403,8 @@ class TestMQTTCallbacks(unittest.TestCase):
self.hass.block_till_done()
assert 1 == len(self.calls)
assert 'hi/test-topic' == self.calls[0][0]
assert 'test-payload' == self.calls[0][1]
assert 'hi/test-topic' == self.calls[0][0].topic
assert 'test-payload' == self.calls[0][0].payload
def test_subscribe_topic_level_wildcard_and_wildcard_subtree_topic(self):
"""Test the subscription of wildcard topics."""
@@ -414,8 +414,8 @@ class TestMQTTCallbacks(unittest.TestCase):
self.hass.block_till_done()
assert 1 == len(self.calls)
assert 'hi/test-topic/here-iam' == self.calls[0][0]
assert 'test-payload' == self.calls[0][1]
assert 'hi/test-topic/here-iam' == self.calls[0][0].topic
assert 'test-payload' == self.calls[0][0].payload
def test_subscribe_topic_level_wildcard_and_wildcard_level_no_match(self):
"""Test the subscription of wildcard topics."""
@@ -443,8 +443,8 @@ class TestMQTTCallbacks(unittest.TestCase):
self.hass.block_till_done()
assert 1 == len(self.calls)
assert '$test-topic/subtree/on' == self.calls[0][0]
assert 'test-payload' == self.calls[0][1]
assert '$test-topic/subtree/on' == self.calls[0][0].topic
assert 'test-payload' == self.calls[0][0].payload
def test_subscribe_topic_sys_root_and_wildcard_topic(self):
"""Test the subscription of $ root and wildcard topics."""
@@ -454,8 +454,8 @@ class TestMQTTCallbacks(unittest.TestCase):
self.hass.block_till_done()
assert 1 == len(self.calls)
assert '$test-topic/some-topic' == self.calls[0][0]
assert 'test-payload' == self.calls[0][1]
assert '$test-topic/some-topic' == self.calls[0][0].topic
assert 'test-payload' == self.calls[0][0].payload
def test_subscribe_topic_sys_root_and_wildcard_subtree_topic(self):
"""Test the subscription of $ root and wildcard subtree topics."""
@@ -466,8 +466,8 @@ class TestMQTTCallbacks(unittest.TestCase):
self.hass.block_till_done()
assert 1 == len(self.calls)
assert '$test-topic/subtree/some-topic' == self.calls[0][0]
assert 'test-payload' == self.calls[0][1]
assert '$test-topic/subtree/some-topic' == self.calls[0][0].topic
assert 'test-payload' == self.calls[0][0].payload
def test_subscribe_special_characters(self):
"""Test the subscription to topics with special characters."""
@@ -479,8 +479,8 @@ class TestMQTTCallbacks(unittest.TestCase):
fire_mqtt_message(self.hass, topic, payload)
self.hass.block_till_done()
assert 1 == len(self.calls)
assert topic == self.calls[0][0]
assert payload == self.calls[0][1]
assert topic == self.calls[0][0].topic
assert payload == self.calls[0][0].payload
def test_mqtt_failed_connection_results_in_disconnect(self):
"""Test if connection failure leads to disconnect."""
+6 -6
View File
@@ -35,8 +35,8 @@ async def test_subscribe_topics(hass, mqtt_mock, caplog):
async_fire_mqtt_message(hass, 'test-topic1', 'test-payload1')
await hass.async_block_till_done()
assert 1 == len(calls1)
assert 'test-topic1' == calls1[0][0]
assert 'test-payload1' == calls1[0][1]
assert 'test-topic1' == calls1[0][0].topic
assert 'test-payload1' == calls1[0][0].payload
assert 0 == len(calls2)
async_fire_mqtt_message(hass, 'test-topic2', 'test-payload2')
@@ -44,8 +44,8 @@ async def test_subscribe_topics(hass, mqtt_mock, caplog):
await hass.async_block_till_done()
assert 1 == len(calls1)
assert 1 == len(calls2)
assert 'test-topic2' == calls2[0][0]
assert 'test-payload2' == calls2[0][1]
assert 'test-topic2' == calls2[0][0].topic
assert 'test-payload2' == calls2[0][0].payload
await async_unsubscribe_topics(hass, sub_state)
@@ -108,8 +108,8 @@ async def test_modify_topics(hass, mqtt_mock, caplog):
await hass.async_block_till_done()
await hass.async_block_till_done()
assert 2 == len(calls1)
assert 'test-topic1_1' == calls1[1][0]
assert 'test-payload' == calls1[1][1]
assert 'test-topic1_1' == calls1[1][0].topic
assert 'test-payload' == calls1[1][0].payload
assert 1 == len(calls2)
await async_unsubscribe_topics(hass, sub_state)