Fix for MQTT config validation on the protocol field. (#1765)

This commit is contained in:
Jan Harkes 2016-04-09 12:03:41 -04:00 committed by Paulus Schoutsen
parent b3bad10dab
commit 3aa4727b18
2 changed files with 12 additions and 1 deletions

View File

@ -90,7 +90,7 @@ CONFIG_SCHEMA = vol.Schema({
vol.Optional(CONF_PASSWORD): cv.string,
vol.Optional(CONF_CERTIFICATE): cv.isfile,
vol.Optional(CONF_PROTOCOL, default=DEFAULT_PROTOCOL):
[PROTOCOL_31, PROTOCOL_311],
vol.All(cv.string, vol.In([PROTOCOL_31, PROTOCOL_311])),
vol.Optional(CONF_EMBEDDED): _HBMQTT_CONFIG_SCHEMA,
}),
}, extra=vol.ALLOW_EXTRA)

View File

@ -58,6 +58,17 @@ class TestMQTT(unittest.TestCase):
}
})
def test_setup_protocol_validation(self):
"""Test for setup failure if connection to broker is missing."""
with mock.patch('paho.mqtt.client.Client'):
self.hass.config.components = []
assert _setup_component(self.hass, mqtt.DOMAIN, {
mqtt.DOMAIN: {
mqtt.CONF_BROKER: 'test-broker',
mqtt.CONF_PROTOCOL: 3.1,
}
})
def test_publish_calls_service(self):
"""Test the publishing of call to services."""
self.hass.bus.listen_once(EVENT_CALL_SERVICE, self.record_calls)