* init setup of Anova Sous Vide * bump anova-wifi to 0.2.4 * Removed yaml support * Bump to anova-wifi 0.2.5 * Added support for adding sous vide while offline * Added basic test for sensor * added better tests for sensors and init * expanded code coverage * Decreased timedelta to lowest functioning value. * Updating my username * migrate to async_forward_entry_setups * applying pr recommended changes * bump anova-wifi to 0.2.7 * Improvements to hopefully get this review ready * formatting changes * clean ups for pr review * remove unneeded unique id check. * bump ao anova_wifi 0.3.0 * rename device_id to device_unique_id * renamed to 'anova' * added unique_id to MockConfigEntry * removed leftover anova sous vides * added device id to strings * added error for incorrect device id * add has_entity_name * added attr name for tests * added authentication functionality * bump to 0.4.3 * split entity into its own class/object * pulling firmware version out of async_setup Co-authored-by: J. Nick Koston <nick@koston.org> * addressed pr changes * fixed pytest * added anova data model * removed unneeded time change * add logging in package * rework step_user * Update homeassistant/components/anova/sensor.py Co-authored-by: J. Nick Koston <nick@koston.org> * Removed lower from attr unique id Co-authored-by: J. Nick Koston <nick@koston.org> * Removed unneeded member variables in sensor Co-authored-by: J. Nick Koston <nick@koston.org> * removed repeated subclass attr Co-authored-by: J. Nick Koston <nick@koston.org> * simplify update_failed test * created descriptionentity * bump to 0.6.1 limit ws connect * add translation for sensor entities * version bump - support pro model * add anova to strict typing * fixed sensor not getting datas type * Apply suggestions from code review Co-authored-by: J. Nick Koston <nick@koston.org> * Check for new devices in init * style changes * return false instead of config entry not ready * move serialize_device_list to utils * move repeating device check into api * moved unneeded code out of try except * fixed tests to get 100% cov * Update homeassistant/components/anova/strings.json Co-authored-by: J. Nick Koston <nick@koston.org> --------- Co-authored-by: J. Nick Koston <nick@koston.org>
133 lines
4.9 KiB
Python
133 lines
4.9 KiB
Python
"""Test Anova config flow."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
from anova_wifi import AnovaPrecisionCooker, InvalidLogin, NoDevicesFound
|
|
|
|
from homeassistant import config_entries, data_entry_flow
|
|
from homeassistant.components.anova.const import DOMAIN
|
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from . import CONF_INPUT, DEVICE_UNIQUE_ID, create_entry
|
|
|
|
|
|
async def test_flow_user(
|
|
hass: HomeAssistant,
|
|
) -> None:
|
|
"""Test user initialized flow."""
|
|
with patch(
|
|
"homeassistant.components.anova.config_flow.AnovaApi.authenticate",
|
|
) as auth_patch, patch(
|
|
"homeassistant.components.anova.AnovaApi.get_devices"
|
|
) as device_patch, patch(
|
|
"homeassistant.components.anova.AnovaApi.authenticate"
|
|
), patch(
|
|
"homeassistant.components.anova.config_flow.AnovaApi.get_devices"
|
|
) as config_flow_device_patch:
|
|
auth_patch.return_value = True
|
|
device_patch.return_value = [
|
|
AnovaPrecisionCooker(None, DEVICE_UNIQUE_ID, "type_sample", None)
|
|
]
|
|
config_flow_device_patch.return_value = [
|
|
AnovaPrecisionCooker(None, DEVICE_UNIQUE_ID, "type_sample", None)
|
|
]
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN,
|
|
context={"source": config_entries.SOURCE_USER},
|
|
)
|
|
result = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
user_input=CONF_INPUT,
|
|
)
|
|
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
|
assert result["data"] == {
|
|
CONF_USERNAME: "sample@gmail.com",
|
|
CONF_PASSWORD: "sample",
|
|
"devices": [(DEVICE_UNIQUE_ID, "type_sample")],
|
|
}
|
|
|
|
|
|
async def test_flow_user_already_configured(hass: HomeAssistant) -> None:
|
|
"""Test user initialized flow with duplicate device."""
|
|
with patch(
|
|
"homeassistant.components.anova.config_flow.AnovaApi.authenticate",
|
|
) as auth_patch, patch(
|
|
"homeassistant.components.anova.AnovaApi.get_devices"
|
|
) as device_patch, patch(
|
|
"homeassistant.components.anova.config_flow.AnovaApi.get_devices"
|
|
) as config_flow_device_patch:
|
|
auth_patch.return_value = True
|
|
device_patch.return_value = [
|
|
AnovaPrecisionCooker(None, DEVICE_UNIQUE_ID, "type_sample", None)
|
|
]
|
|
config_flow_device_patch.return_value = [
|
|
AnovaPrecisionCooker(None, DEVICE_UNIQUE_ID, "type_sample", None)
|
|
]
|
|
create_entry(hass)
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN,
|
|
context={"source": config_entries.SOURCE_USER},
|
|
)
|
|
result = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
user_input=CONF_INPUT,
|
|
)
|
|
assert result["type"] == data_entry_flow.FlowResultType.ABORT
|
|
assert result["reason"] == "already_configured"
|
|
|
|
|
|
async def test_flow_wrong_login(hass: HomeAssistant) -> None:
|
|
"""Test incorrect login throwing error."""
|
|
with patch(
|
|
"homeassistant.components.anova.config_flow.AnovaApi.authenticate",
|
|
side_effect=InvalidLogin,
|
|
):
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN,
|
|
context={"source": config_entries.SOURCE_USER},
|
|
)
|
|
result = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
user_input=CONF_INPUT,
|
|
)
|
|
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
|
assert result["errors"] == {"base": "invalid_auth"}
|
|
|
|
|
|
async def test_flow_unknown_error(hass: HomeAssistant) -> None:
|
|
"""Test unknown error throwing error."""
|
|
with patch(
|
|
"homeassistant.components.anova.config_flow.AnovaApi.authenticate",
|
|
side_effect=Exception(),
|
|
):
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN,
|
|
context={"source": config_entries.SOURCE_USER},
|
|
)
|
|
result = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
user_input=CONF_INPUT,
|
|
)
|
|
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
|
assert result["errors"] == {"base": "unknown"}
|
|
|
|
|
|
async def test_flow_no_devices(hass: HomeAssistant) -> None:
|
|
"""Test unknown error throwing error."""
|
|
with patch(
|
|
"homeassistant.components.anova.config_flow.AnovaApi.authenticate"
|
|
), patch(
|
|
"homeassistant.components.anova.config_flow.AnovaApi.get_devices",
|
|
side_effect=NoDevicesFound(),
|
|
):
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN,
|
|
context={"source": config_entries.SOURCE_USER},
|
|
)
|
|
result = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
user_input=CONF_INPUT,
|
|
)
|
|
assert result["type"] == data_entry_flow.FlowResultType.FORM
|
|
assert result["errors"] == {"base": "no_devices_found"}
|