* Add Huum integration * Use DeviceInfo instead of name property for huum climate * Simplify entry setup for huum climate entry * Don’t take status as attribute for huum climate init * Remove unused import * Set unique id as entity id in huum init * Remove unused import for huum climate * Use entry ID as unique ID for device entity * Remove extra newline in huum climate * Upgrade pyhuum to 0.7.4 This version no longer users Pydantic * Parameterize error huum tests * Update all requirements after pyhuum upgrade * Use Huum specific naming for ConfigFlow * Use constants for username and password in huum config flow * Use constants for temperature units * Fix typing and pylint issues * Update pyhuum to 0.7.5 * Use correct enums for data entry flow in Huum tests * Remove test for non-thrown CannotConnect in huum flow tests * Refactor failure config test to also test a successful flow after failure * Fix ruff-format issues * Move _status outside of __init__ and type it * Type temperature argument for _turn_on in huum climate * Use constants for auth in huum config flow test * Refactor validate_into into a inline call in huum config flow * Refactor current and target temperature to be able to return None values * Remove unused huum exceptions * Flip if-statment in async_step_user flow setup to simplify code * Change current and target temperature to be more future proof * Log exception instead of error * Use custom pyhuum exceptions * Add checks for duplicate entries * Use min temp if no target temp has been fetched yet when heating huum * Fix tests so that mock config entry also include username and password * Fix ruff styling issues I don’t know why it keeps doing this. I run `ruff` locally, and then it does not complain, but CI must be doing something else here. * Remove unneded setting of unique id * Update requirements * Refactor temperature setting to support settings target temparature properly
135 lines
3.9 KiB
Python
135 lines
3.9 KiB
Python
"""Test the huum config flow."""
|
|
from unittest.mock import patch
|
|
|
|
from huum.exceptions import Forbidden
|
|
import pytest
|
|
|
|
from homeassistant import config_entries
|
|
from homeassistant.components.huum.const import DOMAIN
|
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.data_entry_flow import FlowResultType
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
TEST_USERNAME = "test-username"
|
|
TEST_PASSWORD = "test-password"
|
|
|
|
|
|
async def test_form(hass: HomeAssistant) -> None:
|
|
"""Test we get the form."""
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
|
)
|
|
assert result["type"] == FlowResultType.FORM
|
|
assert result["errors"] == {}
|
|
|
|
with patch(
|
|
"homeassistant.components.huum.config_flow.Huum.status",
|
|
return_value=True,
|
|
), patch(
|
|
"homeassistant.components.huum.async_setup_entry",
|
|
return_value=True,
|
|
) as mock_setup_entry:
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
{
|
|
CONF_USERNAME: TEST_USERNAME,
|
|
CONF_PASSWORD: TEST_PASSWORD,
|
|
},
|
|
)
|
|
await hass.async_block_till_done()
|
|
|
|
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
|
assert result2["title"] == TEST_USERNAME
|
|
assert result2["data"] == {
|
|
CONF_USERNAME: TEST_USERNAME,
|
|
CONF_PASSWORD: TEST_PASSWORD,
|
|
}
|
|
assert len(mock_setup_entry.mock_calls) == 1
|
|
|
|
|
|
async def test_signup_flow_already_set_up(hass: HomeAssistant) -> None:
|
|
"""Test that we handle already existing entities with same id."""
|
|
mock_config_entry = MockConfigEntry(
|
|
title="Huum Sauna",
|
|
domain=DOMAIN,
|
|
unique_id=TEST_USERNAME,
|
|
data={
|
|
CONF_USERNAME: TEST_USERNAME,
|
|
CONF_PASSWORD: TEST_PASSWORD,
|
|
},
|
|
)
|
|
mock_config_entry.add_to_hass(hass)
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
|
)
|
|
|
|
with patch(
|
|
"homeassistant.components.huum.config_flow.Huum.status",
|
|
return_value=True,
|
|
), patch(
|
|
"homeassistant.components.huum.async_setup_entry",
|
|
return_value=True,
|
|
):
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
{
|
|
CONF_USERNAME: TEST_USERNAME,
|
|
CONF_PASSWORD: TEST_PASSWORD,
|
|
},
|
|
)
|
|
await hass.async_block_till_done()
|
|
assert result2["type"] == FlowResultType.ABORT
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
(
|
|
"raises",
|
|
"error_base",
|
|
),
|
|
[
|
|
(Exception, "unknown"),
|
|
(Forbidden, "invalid_auth"),
|
|
],
|
|
)
|
|
async def test_huum_errors(
|
|
hass: HomeAssistant, raises: Exception, error_base: str
|
|
) -> None:
|
|
"""Test we handle cannot connect error."""
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
|
)
|
|
|
|
with patch(
|
|
"homeassistant.components.huum.config_flow.Huum.status",
|
|
side_effect=raises,
|
|
):
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
{
|
|
CONF_USERNAME: TEST_USERNAME,
|
|
CONF_PASSWORD: TEST_PASSWORD,
|
|
},
|
|
)
|
|
|
|
assert result2["type"] == FlowResultType.FORM
|
|
assert result2["errors"] == {"base": error_base}
|
|
|
|
with patch(
|
|
"homeassistant.components.huum.config_flow.Huum.status",
|
|
return_value=True,
|
|
), patch(
|
|
"homeassistant.components.huum.async_setup_entry",
|
|
return_value=True,
|
|
):
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
{
|
|
CONF_USERNAME: TEST_USERNAME,
|
|
CONF_PASSWORD: TEST_PASSWORD,
|
|
},
|
|
)
|
|
assert result2["type"] == FlowResultType.CREATE_ENTRY
|