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:
Jan Bouwhuis
2023-10-19 17:34:43 +02:00
committed by GitHub
parent 90687e9794
commit d149bffb07
9 changed files with 107 additions and 166 deletions

View File

@ -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", [])