mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Fix MQTT payload decode returning prematurely (#12420)
* Fix MQTT returning prematurely * Add test
This commit is contained in:
parent
c25c4c85d6
commit
5d4b1ecd3b
@ -607,7 +607,7 @@ class MQTT(object):
|
|||||||
"with encoding %s",
|
"with encoding %s",
|
||||||
msg.payload, msg.topic,
|
msg.payload, msg.topic,
|
||||||
subscription.encoding)
|
subscription.encoding)
|
||||||
return
|
continue
|
||||||
|
|
||||||
self.hass.async_run_job(subscription.callback,
|
self.hass.async_run_job(subscription.callback,
|
||||||
msg.topic, payload, msg.qos)
|
msg.topic, payload, msg.qos)
|
||||||
|
@ -172,6 +172,17 @@ class TestMQTTCallbacks(unittest.TestCase):
|
|||||||
"b'\\x9a' on test-topic with encoding utf-8",
|
"b'\\x9a' on test-topic with encoding utf-8",
|
||||||
test_handle.output[0])
|
test_handle.output[0])
|
||||||
|
|
||||||
|
def test_all_subscriptions_run_when_decode_fails(self):
|
||||||
|
"""Test all other subscriptions still run when decode fails for one."""
|
||||||
|
mqtt.subscribe(self.hass, 'test-topic', self.record_calls,
|
||||||
|
encoding='ascii')
|
||||||
|
mqtt.subscribe(self.hass, 'test-topic', self.record_calls)
|
||||||
|
|
||||||
|
fire_mqtt_message(self.hass, 'test-topic', '°C')
|
||||||
|
|
||||||
|
self.hass.block_till_done()
|
||||||
|
self.assertEqual(1, len(self.calls))
|
||||||
|
|
||||||
def test_subscribe_topic(self):
|
def test_subscribe_topic(self):
|
||||||
"""Test the subscription of a topic."""
|
"""Test the subscription of a topic."""
|
||||||
unsub = mqtt.subscribe(self.hass, 'test-topic', self.record_calls)
|
unsub = mqtt.subscribe(self.hass, 'test-topic', self.record_calls)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user