1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Service validation for MQTT component.

* Service validation for MQTT component.

* Fixes for failing mqtt tests.

- Changed behaviour when both 'payload' and 'payload_template' are provided
  instead of silently ignoring the payload_template value.
- Have validation accept any type of payload and leave encoding to paho-mqtt.
This commit is contained in:
Jan Harkes
2016-04-02 11:46:09 -04:00
committed by Paulus Schoutsen
parent ebd053824d
commit 5c753f8ffd
2 changed files with 32 additions and 24 deletions

View File

@@ -90,19 +90,16 @@ class TestMQTT(unittest.TestCase):
def test_service_call_with_payload_doesnt_render_template(self):
"""Test the service call with unrendered template.
If a 'payload' is provided then use that instead of 'payload_template'.
If both 'payload' and 'payload_template' are provided then fail.
"""
payload = "not a template"
payload_template = "a template"
# Call the service directly because the helper functions don't allow
# you to provide payload AND payload_template.
self.hass.services.call(mqtt.DOMAIN, mqtt.SERVICE_PUBLISH, {
mqtt.ATTR_TOPIC: "test/topic",
mqtt.ATTR_PAYLOAD: payload,
mqtt.ATTR_PAYLOAD_TEMPLATE: payload_template
}, blocking=True)
self.assertTrue(mqtt.MQTT_CLIENT.publish.called)
self.assertEqual(mqtt.MQTT_CLIENT.publish.call_args[0][1], payload)
self.assertFalse(mqtt.MQTT_CLIENT.publish.called)
def test_service_call_without_payload_or_payload_template(self):
"""Test the service call without payload or payload template.