Raise vol.Invalid for invalid mqtt device_tracker config (#101399)
Raise vol.Invalid for invalid mqtt device_trackerpull/101547/head
parent
10e43048bd
commit
223f3a434b
|
@ -52,7 +52,7 @@ DEFAULT_SOURCE_TYPE = SourceType.GPS
|
||||||
def valid_config(config: ConfigType) -> ConfigType:
|
def valid_config(config: ConfigType) -> ConfigType:
|
||||||
"""Check if there is a state topic or json_attributes_topic."""
|
"""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:
|
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}"
|
f"Invalid device tracker config, missing {CONF_STATE_TOPIC} or {CONF_JSON_ATTRS_TOPIC}, got: {config}"
|
||||||
)
|
)
|
||||||
return config
|
return config
|
||||||
|
|
|
@ -122,6 +122,28 @@ async def test_invalid_json(
|
||||||
assert not mock_dispatcher_send.called
|
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(
|
async def test_only_valid_components(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||||
|
|
Loading…
Reference in New Issue