mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Raise ConfigEntryNotReady for MQTT connection exception (#22540)
* Raise ConfigEntryNotReady for connection exception Raise ConfigEntryNotReady for the connection exception like if the MQTT Server container/device is being restarted or was unavailable on boot. * Add new exception * grammar fix * Possibly resolve hound comments * raise `ConfigEntryNotReady` for mqtt connection error * revert exceptions.py * Update exceptions.py * modify test to handle exception * use constants to control exception scope * Raise ConfigEntryNotReady for connection exception Raise ConfigEntryNotReady for the connection exception like if the MQTT Server container/device is being restarted or was unavailable on boot. * Add new exception * Add new exception * grammar fix * Possibly resolve hound comments * raise `ConfigEntryNotReady` for mqtt connection error * revert exceptions.py * Update exceptions.py * modify test to handle exception * use constants to control exception scope * revert test change as it's not the same thing * Update test_init.py * Add test for MQTT OSError * revert file changes from a bad rebase * Rewrite test with valid syntax * rewrite test to be less ambiguous * add empty line * add back 'axis' * Remove empty line * Update tests and undo merge from earlier * correctly restore test for no connect broker * fix test mock correctly * line was too long. hit enter.
This commit is contained in:
committed by
Paulus Schoutsen
parent
d81a627739
commit
a5a926bcc6
@@ -12,6 +12,7 @@ from homeassistant.const import (
|
||||
ATTR_DOMAIN, ATTR_SERVICE, EVENT_CALL_SERVICE, EVENT_HOMEASSISTANT_STOP)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
|
||||
from tests.common import (
|
||||
MockConfigEntry, async_fire_mqtt_message, async_mock_mqtt_component,
|
||||
@@ -621,6 +622,19 @@ async def test_setup_fails_if_no_connect_broker(hass):
|
||||
assert not await mqtt.async_setup_entry(hass, entry)
|
||||
|
||||
|
||||
async def test_setup_raises_ConfigEntryNotReady_if_no_connect_broker(hass):
|
||||
"""Test for setup failure if connection to broker is missing."""
|
||||
entry = MockConfigEntry(domain=mqtt.DOMAIN, data={
|
||||
mqtt.CONF_BROKER: 'test-broker'
|
||||
})
|
||||
|
||||
with mock.patch('paho.mqtt.client.Client') as mock_client:
|
||||
mock_client().connect = mock.Mock(
|
||||
side_effect=OSError("Connection error"))
|
||||
with pytest.raises(ConfigEntryNotReady):
|
||||
await mqtt.async_setup_entry(hass, entry)
|
||||
|
||||
|
||||
async def test_setup_uses_certificate_on_certificate_set_to_auto(
|
||||
hass, mock_MQTT):
|
||||
"""Test setup uses bundled certs when certificate is set to auto."""
|
||||
|
||||
Reference in New Issue
Block a user