mirror of
https://github.com/home-assistant/core.git
synced 2025-07-31 03:08:01 +02:00
Fix mqtt config validation error handling (#103210)
* Fix MQTT config check * Fix handling invalid enity_category for sensors * Improve docstr * Update comment * Use correct util for yaml dump
This commit is contained in:
@ -2134,7 +2134,7 @@ async def test_setup_manual_mqtt_with_platform_key(
|
||||
"""Test set up a manual MQTT item with a platform key."""
|
||||
assert await mqtt_mock_entry()
|
||||
assert (
|
||||
"extra keys not allowed @ data['platform'] for manual configured MQTT light item"
|
||||
"extra keys not allowed @ data['platform'] for manually configured MQTT light item"
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
@ -2151,6 +2151,42 @@ async def test_setup_manual_mqtt_with_invalid_config(
|
||||
assert "required key not provided" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"hass_config",
|
||||
[
|
||||
{
|
||||
mqtt.DOMAIN: {
|
||||
"sensor": {
|
||||
"name": "test",
|
||||
"state_topic": "test-topic",
|
||||
"entity_category": "config",
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
mqtt.DOMAIN: {
|
||||
"binary_sensor": {
|
||||
"name": "test",
|
||||
"state_topic": "test-topic",
|
||||
"entity_category": "config",
|
||||
}
|
||||
}
|
||||
},
|
||||
],
|
||||
)
|
||||
@patch(
|
||||
"homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR, Platform.SENSOR]
|
||||
)
|
||||
async def test_setup_manual_mqtt_with_invalid_entity_category(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test set up a manual sensor item with an invalid entity category."""
|
||||
assert await mqtt_mock_entry()
|
||||
assert "Entity category `config` is invalid" in caplog.text
|
||||
|
||||
|
||||
@patch("homeassistant.components.mqtt.PLATFORMS", [])
|
||||
@pytest.mark.parametrize(
|
||||
("mqtt_config_entry_data", "protocol"),
|
||||
|
Reference in New Issue
Block a user