hass-core/tests/components/tasmota/test_config_flow.py
Erik Montnemery 06e9489fc7
Add Tasmota integration (#39624)
* Add Tasmota integration

* Refactor

* Add tests, small improvements

* isort

* Attempt to fix tests failing with Python 3.8

* Revert "Attempt to fix tests failing with Python 3.8"

This reverts commit 11454f8a00136f068ea27204183fa3e62f3cd263.

* Fix tests failing with Python 3.8

* Cleanup tests

* Address review comments

* Address review comments

* Address review comments

* Use MAC address for device identification

* Bump hatasmota

* Bump hatasmota

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Fix indentation

* Remove preparation for device remove WS API

* Address review comments

* Remove useless try-except

* Tweak

* Improve tests

* Tweak

* Address review comments

* Correct test

* Update manifest.json

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-10-06 14:51:58 +02:00

61 lines
1.9 KiB
Python

"""Test config flow."""
from tests.common import MockConfigEntry
async def test_user_setup(hass, mqtt_mock):
"""Test we can finish a config flow."""
result = await hass.config_entries.flow.async_init(
"tasmota", context={"source": "user"}
)
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": "tasmota/discovery",
}
async def test_user_setup_advanced(hass, mqtt_mock):
"""Test we can finish a config flow."""
result = await hass.config_entries.flow.async_init(
"tasmota", context={"source": "user", "show_advanced_options": True}
)
assert result["type"] == "form"
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {"discovery_prefix": "test_tasmota/discovery"}
)
assert result["type"] == "create_entry"
assert result["result"].data == {
"discovery_prefix": "test_tasmota/discovery",
}
async def test_user_setup_invalid_topic_prefix(hass, mqtt_mock):
"""Test if connection cannot be made."""
result = await hass.config_entries.flow.async_init(
"tasmota", context={"source": "user", "show_advanced_options": True}
)
assert result["type"] == "form"
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {"discovery_prefix": "tasmota/config/#"}
)
assert result["type"] == "form"
assert result["errors"]["base"] == "invalid_discovery_topic"
async def test_user_single_instance(hass, mqtt_mock):
"""Test we only allow a single config flow."""
MockConfigEntry(domain="tasmota").add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
"tasmota", context={"source": "user"}
)
assert result["type"] == "abort"
assert result["reason"] == "single_instance_allowed"