Convert Anova to cloud push (#109508)
* current state * finish refactor * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * address MR comments * Change to sensor setup to be listener based. * remove assert for websocket handler * added assert for log * remove mixin * fix linting * fix merge change * Add clarifying comment * Apply suggestions from code review Co-authored-by: Erik Montnemery <erik@montnemery.com> * Address MR comments * bump version and fix typing check --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
parent
de62e205dd
commit
22bc11f397
17 changed files with 387 additions and 304 deletions
|
@ -2,83 +2,33 @@
|
|||
|
||||
from unittest.mock import patch
|
||||
|
||||
from anova_wifi import AnovaPrecisionCooker, InvalidLogin, NoDevicesFound
|
||||
from anova_wifi import AnovaApi, InvalidLogin
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.anova.const import DOMAIN
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.const import CONF_DEVICES, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from . import CONF_INPUT, DEVICE_UNIQUE_ID, create_entry
|
||||
from . import CONF_INPUT
|
||||
|
||||
|
||||
async def test_flow_user(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
async def test_flow_user(hass: HomeAssistant, anova_api: AnovaApi) -> 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"] is 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"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
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"] == FlowResultType.CREATE_ENTRY
|
||||
assert result["data"] == {
|
||||
CONF_USERNAME: "sample@gmail.com",
|
||||
CONF_PASSWORD: "sample",
|
||||
CONF_DEVICES: [],
|
||||
}
|
||||
|
||||
|
||||
async def test_flow_wrong_login(hass: HomeAssistant) -> None:
|
||||
|
@ -115,24 +65,3 @@ async def test_flow_unknown_error(hass: HomeAssistant) -> None:
|
|||
)
|
||||
assert result["type"] is 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"] is FlowResultType.FORM
|
||||
assert result["errors"] == {"base": "no_devices_found"}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue