mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 18:28:14 +02:00
Do not fail MQTT setup if lights configured via yaml can't be validated (#101649)
* Add light * Deduplicate code * Follow up comment
This commit is contained in:
@ -2114,35 +2114,30 @@ async def test_handle_message_callback(
|
||||
}
|
||||
],
|
||||
)
|
||||
@patch("homeassistant.components.mqtt.PLATFORMS", [])
|
||||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LIGHT])
|
||||
async def test_setup_manual_mqtt_with_platform_key(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test set up a manual MQTT item with a platform key."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry()
|
||||
assert await mqtt_mock_entry()
|
||||
assert (
|
||||
"Invalid config for [mqtt]: [platform] is an invalid option for [mqtt]"
|
||||
"extra keys not allowed @ data['platform'] for manual configured MQTT light item"
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [{mqtt.DOMAIN: {"light": {"name": "test"}}}])
|
||||
@patch("homeassistant.components.mqtt.PLATFORMS", [])
|
||||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LIGHT])
|
||||
async def test_setup_manual_mqtt_with_invalid_config(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test set up a manual MQTT item with an invalid config."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry()
|
||||
assert (
|
||||
"Invalid config for [mqtt]: required key not provided @ data['mqtt'][0]['light'][0]['command_topic']. "
|
||||
"Got None. (See ?, line ?)" in caplog.text
|
||||
)
|
||||
assert await mqtt_mock_entry()
|
||||
assert "required key not provided" in caplog.text
|
||||
|
||||
|
||||
@patch("homeassistant.components.mqtt.PLATFORMS", [])
|
||||
|
Reference in New Issue
Block a user