Raise vol.Invalid for invalid mqtt device_tracker config (#101399)
Raise vol.Invalid for invalid mqtt device_trackerpull/101406/head
parent
1d7d7c3540
commit
a3fe120457
|
@ -52,7 +52,7 @@ DEFAULT_SOURCE_TYPE = SourceType.GPS
|
|||
def valid_config(config: ConfigType) -> ConfigType:
|
||||
"""Check if there is a state topic or json_attributes_topic."""
|
||||
if CONF_STATE_TOPIC not in config and CONF_JSON_ATTRS_TOPIC not in config:
|
||||
raise vol.MultipleInvalid(
|
||||
raise vol.Invalid(
|
||||
f"Invalid device tracker config, missing {CONF_STATE_TOPIC} or {CONF_JSON_ATTRS_TOPIC}, got: {config}"
|
||||
)
|
||||
return config
|
||||
|
|
|
@ -122,6 +122,28 @@ async def test_invalid_json(
|
|||
assert not mock_dispatcher_send.called
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||
async def test_discovery_schema_error(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test unexpected error JSON config."""
|
||||
with patch(
|
||||
"homeassistant.components.mqtt.binary_sensor.DISCOVERY_SCHEMA",
|
||||
side_effect=AttributeError("Attribute abc not found"),
|
||||
):
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/binary_sensor/bla/config",
|
||||
'{"name": "Beer", "state_topic": "ok"}',
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert "AttributeError: Attribute abc not found" in caplog.text
|
||||
|
||||
|
||||
async def test_only_valid_components(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
|
|
Loading…
Reference in New Issue