* Add integration for wiffi devices wiffi devices are DIY board manufactured by stall.biz. Several devices are available, e.g. a weather station (weatherman), an indoor environmental sensor (wiffi-wz) and some more. This intgration has been developed using a weatherman device, but should also work for other devices from stall.biz. * Fix pylint warning * Use WIFFI / STALL WIFFI instead of wiffi to be consistent with stall.biz * Don't update disabled entities. * fix complains - move wiffi specific code to pypi - remove yaml configuration code * incorporate various suggestions from code review * fix remaining comments from Martin * fix comments * add tests for config flow * fix comments * add missing requirements for tests * fix pylint warnings * fix comments * fix comments remove debug log rename .translations to translations * rebase and adapt to latest dev branch * Update homeassistant/components/wiffi/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/wiffi/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * fix missing import Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
110 lines
3.0 KiB
Python
110 lines
3.0 KiB
Python
"""Test the wiffi integration config flow."""
|
|
import errno
|
|
|
|
from asynctest import patch
|
|
import pytest
|
|
|
|
from homeassistant import config_entries
|
|
from homeassistant.components.wiffi.const import DOMAIN
|
|
from homeassistant.const import CONF_PORT
|
|
from homeassistant.data_entry_flow import (
|
|
RESULT_TYPE_ABORT,
|
|
RESULT_TYPE_CREATE_ENTRY,
|
|
RESULT_TYPE_FORM,
|
|
)
|
|
|
|
|
|
@pytest.fixture(name="dummy_tcp_server")
|
|
def mock_dummy_tcp_server():
|
|
"""Mock a valid WiffiTcpServer."""
|
|
|
|
class Dummy:
|
|
async def start_server(self):
|
|
pass
|
|
|
|
async def close_server(self):
|
|
pass
|
|
|
|
server = Dummy()
|
|
with patch(
|
|
"homeassistant.components.wiffi.config_flow.WiffiTcpServer", return_value=server
|
|
):
|
|
yield server
|
|
|
|
|
|
@pytest.fixture(name="addr_in_use")
|
|
def mock_addr_in_use_server():
|
|
"""Mock a WiffiTcpServer with addr_in_use."""
|
|
|
|
class Dummy:
|
|
async def start_server(self):
|
|
raise OSError(errno.EADDRINUSE, "")
|
|
|
|
async def close_server(self):
|
|
pass
|
|
|
|
server = Dummy()
|
|
with patch(
|
|
"homeassistant.components.wiffi.config_flow.WiffiTcpServer", return_value=server
|
|
):
|
|
yield server
|
|
|
|
|
|
@pytest.fixture(name="start_server_failed")
|
|
def mock_start_server_failed():
|
|
"""Mock a WiffiTcpServer with start_server_failed."""
|
|
|
|
class Dummy:
|
|
async def start_server(self):
|
|
raise OSError(errno.EACCES, "")
|
|
|
|
async def close_server(self):
|
|
pass
|
|
|
|
server = Dummy()
|
|
with patch(
|
|
"homeassistant.components.wiffi.config_flow.WiffiTcpServer", return_value=server
|
|
):
|
|
yield server
|
|
|
|
|
|
async def test_form(hass, dummy_tcp_server):
|
|
"""Test how we get the form."""
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
|
)
|
|
assert result["type"] == RESULT_TYPE_FORM
|
|
assert result["errors"] == {}
|
|
assert result["step_id"] == config_entries.SOURCE_USER
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"], user_input={CONF_PORT: 8765},
|
|
)
|
|
assert result2["type"] == RESULT_TYPE_CREATE_ENTRY
|
|
|
|
|
|
async def test_form_addr_in_use(hass, addr_in_use):
|
|
"""Test how we handle addr_in_use error."""
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
|
)
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"], user_input={CONF_PORT: 8765},
|
|
)
|
|
assert result2["type"] == RESULT_TYPE_ABORT
|
|
assert result2["reason"] == "addr_in_use"
|
|
|
|
|
|
async def test_form_start_server_failed(hass, start_server_failed):
|
|
"""Test how we handle start_server_failed error."""
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
|
)
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"], user_input={CONF_PORT: 8765},
|
|
)
|
|
assert result2["type"] == RESULT_TYPE_ABORT
|
|
assert result2["reason"] == "start_server_failed"
|