mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add Integration for Goal Zero Yeti Power Stations (#39231)
* Add Integration for Goal Zero Yeti Power Stations * Goal Zero Yeti integration with config flow * Remove unused entities * Remove entry from requirements_test_all * Pylint fix * Apply suggestions from code review Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Add tests for goalzero integration * Fix UNIT_PERCENTAGE to PERCENTAGE * isort PERCENTAGE * Add tests * Add en translation * Fix tests * bump goalzero to 0.1.1 * fix await * bump goalzero to 0.1.2 * Update tests/components/goalzero/__init__.py Co-authored-by: J. Nick Koston <nick@koston.org> * apply recommended changes * isort * bump goalzero to 0.1.4 * apply recommended changes * apply recommended changes Co-authored-by: Franck Nijhof <frenck@frenck.nl> Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
120
tests/components/goalzero/test_config_flow.py
Normal file
120
tests/components/goalzero/test_config_flow.py
Normal file
@@ -0,0 +1,120 @@
|
||||
"""Test Goal Zero Yeti config flow."""
|
||||
from goalzero import exceptions
|
||||
|
||||
from homeassistant.components.goalzero.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.data_entry_flow import (
|
||||
RESULT_TYPE_ABORT,
|
||||
RESULT_TYPE_CREATE_ENTRY,
|
||||
RESULT_TYPE_FORM,
|
||||
)
|
||||
|
||||
from . import (
|
||||
CONF_CONFIG_FLOW,
|
||||
CONF_DATA,
|
||||
CONF_HOST,
|
||||
CONF_NAME,
|
||||
NAME,
|
||||
_create_mocked_yeti,
|
||||
_patch_config_flow_yeti,
|
||||
)
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
def _flow_next(hass, flow_id):
|
||||
return next(
|
||||
flow
|
||||
for flow in hass.config_entries.flow.async_progress()
|
||||
if flow["flow_id"] == flow_id
|
||||
)
|
||||
|
||||
|
||||
def _patch_setup():
|
||||
return patch(
|
||||
"homeassistant.components.goalzero.async_setup_entry",
|
||||
return_value=True,
|
||||
)
|
||||
|
||||
|
||||
async def test_flow_user(hass):
|
||||
"""Test user initialized flow."""
|
||||
mocked_yeti = await _create_mocked_yeti()
|
||||
with _patch_config_flow_yeti(mocked_yeti), _patch_setup():
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {}
|
||||
_flow_next(hass, result["flow_id"])
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input=CONF_CONFIG_FLOW,
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == NAME
|
||||
assert result["data"] == CONF_DATA
|
||||
|
||||
|
||||
async def test_flow_user_already_configured(hass):
|
||||
"""Test user initialized flow with duplicate server."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={CONF_HOST: "1.2.3.4", CONF_NAME: "Yeti"},
|
||||
)
|
||||
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
service_info = {
|
||||
"host": "1.2.3.4",
|
||||
"name": "Yeti",
|
||||
}
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=service_info
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_flow_user_cannot_connect(hass):
|
||||
"""Test user initialized flow with unreachable server."""
|
||||
mocked_yeti = await _create_mocked_yeti(True)
|
||||
with _patch_config_flow_yeti(mocked_yeti) as yetimock:
|
||||
yetimock.side_effect = exceptions.ConnectError
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=CONF_CONFIG_FLOW
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
|
||||
async def test_flow_user_invalid_host(hass):
|
||||
"""Test user initialized flow with invalid server."""
|
||||
mocked_yeti = await _create_mocked_yeti(True)
|
||||
with _patch_config_flow_yeti(mocked_yeti) as yetimock:
|
||||
yetimock.side_effect = exceptions.InvalidHost
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=CONF_CONFIG_FLOW
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {"base": "invalid_host"}
|
||||
|
||||
|
||||
async def test_flow_user_unknown_error(hass):
|
||||
"""Test user initialized flow with unreachable server."""
|
||||
mocked_yeti = await _create_mocked_yeti(True)
|
||||
with _patch_config_flow_yeti(mocked_yeti) as yetimock:
|
||||
yetimock.side_effect = Exception
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=CONF_CONFIG_FLOW
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {"base": "unknown"}
|
||||
Reference in New Issue
Block a user