core/tests/components/technove/test_config_flow.py

105 lines
3.6 KiB
Python
Raw Normal View History

Implement TechnoVE integration (#106029) * Implement TechnoVE integration Only the basic sensors for now. * Add technoVE to strict typing * Implement TechnoVE PR suggestions * Remove Diagnostic from TechnoVE initial PR * Switch status sensor to Enum device class * Revert zeroconf for adding it back in subsequent PR * Implement changes from feedback in TechnoVE PR * Update homeassistant/components/technove/models.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/technove/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/technove/models.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Remove unnecessary translation keys * Fix existing technoVE tests * Use snapshot testing for TechnoVE sensors * Improve unit tests for TechnoVE * Add missing coverage for technoVE config flow * Add TechnoVE coordinator tests * Modify device_fixture for TechnoVE from PR Feedback * Change CONF_IP_ADDRESS to CONF_HOST for TechnoVE * Update homeassistant/components/technove/config_flow.py Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com> * Update homeassistant/components/technove/models.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/technove/models.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Implement feedback from TechnoVE PR * Add test_sensor_update_failure to TechnoVE sensor tests * Add test for error recovery during config flow of TechnoVE * Remove test_coordinator.py from TechnoVE --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
2024-01-17 10:04:35 +00:00
"""Tests for the TechnoVE config flow."""
from unittest.mock import MagicMock
import pytest
from technove import TechnoVEConnectionError
from homeassistant.components.technove.const import DOMAIN
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry
@pytest.mark.usefixtures("mock_setup_entry", "mock_technove")
async def test_full_user_flow_implementation(hass: HomeAssistant) -> None:
"""Test the full manual user flow from start to finish."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
)
assert result.get("step_id") == "user"
assert result.get("type") == FlowResultType.FORM
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_HOST: "192.168.1.123"}
)
assert result.get("title") == "TechnoVE Station"
assert result.get("type") == FlowResultType.CREATE_ENTRY
assert "data" in result
assert result["data"][CONF_HOST] == "192.168.1.123"
assert "result" in result
assert result["result"].unique_id == "AA:AA:AA:AA:AA:BB"
@pytest.mark.usefixtures("mock_technove")
async def test_user_device_exists_abort(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_technove: MagicMock,
) -> None:
"""Test we abort the config flow if TechnoVE station is already configured."""
mock_config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
data={CONF_HOST: "192.168.1.123"},
)
assert result.get("type") == FlowResultType.ABORT
assert result.get("reason") == "already_configured"
async def test_connection_error(hass: HomeAssistant, mock_technove: MagicMock) -> None:
"""Test we show user form on TechnoVE connection error."""
mock_technove.update.side_effect = TechnoVEConnectionError
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
data={CONF_HOST: "example.com"},
)
assert result.get("type") == FlowResultType.FORM
assert result.get("step_id") == "user"
assert result.get("errors") == {"base": "cannot_connect"}
@pytest.mark.usefixtures("mock_setup_entry", "mock_technove")
async def test_full_user_flow_with_error(
hass: HomeAssistant, mock_technove: MagicMock
) -> None:
"""Test the full manual user flow from start to finish with some errors in the middle."""
mock_technove.update.side_effect = TechnoVEConnectionError
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
)
assert result.get("step_id") == "user"
assert result.get("type") == FlowResultType.FORM
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_HOST: "192.168.1.123"}
)
assert result.get("type") == FlowResultType.FORM
assert result.get("step_id") == "user"
assert result.get("errors") == {"base": "cannot_connect"}
mock_technove.update.side_effect = None
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_HOST: "192.168.1.123"}
)
assert result.get("title") == "TechnoVE Station"
assert result.get("type") == FlowResultType.CREATE_ENTRY
assert "data" in result
assert result["data"][CONF_HOST] == "192.168.1.123"
assert "result" in result
assert result["result"].unique_id == "AA:AA:AA:AA:AA:BB"