async def test_mqtt_abort_invalid_topic(hass, mqtt_mock):
    """Check MQTT flow aborts if discovery topic is invalid."""
    discovery_info = Message("",
                             "",
                             0,
                             False,
                             subscribed_topic="custom_prefix/##")
    result = await hass.config_entries.flow.async_init(
        "tasmota", context={"source": "mqtt"}, data=discovery_info)
    assert result["type"] == "abort"
    assert result["reason"] == "invalid_discovery_info"
async def test_mqtt_setup(hass, mqtt_mock) -> None:
    """Test we can finish a config flow through MQTT with custom prefix."""
    discovery_info = Message("",
                             "",
                             0,
                             False,
                             subscribed_topic="custom_prefix/123/#")
    result = await hass.config_entries.flow.async_init(
        "tasmota", context={"source": "mqtt"}, data=discovery_info)
    assert result["type"] == "form"

    result = await hass.config_entries.flow.async_configure(
        result["flow_id"], {})

    assert result["type"] == "create_entry"
    assert result["result"].data == {
        "discovery_prefix": "custom_prefix/123",
    }
Ejemplo n.º 3
0
def async_fire_mqtt_message(hass, topic, payload, qos=0, retain=False):
    """Fire the MQTT message."""
    if isinstance(payload, str):
        payload = payload.encode("utf-8")
    msg = Message(topic, payload, qos, retain)
    hass.data["mqtt"]._mqtt_handle_message(msg)