Add initial test

This commit is contained in:
G Johansson
2026-05-03 19:44:35 +00:00
parent 4d71e8d594
commit 6308a2e691
2 changed files with 88 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
"""Compensation fixtures."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
import pytest
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.compensation.async_setup_entry",
return_value=True,
) as mock_setup_entry:
yield mock_setup_entry
@@ -0,0 +1,72 @@
"""Test for compensation config flow."""
from unittest.mock import AsyncMock
from homeassistant.components.compensation.const import (
CONF_DATAPOINTS,
CONF_DEGREE,
CONF_LOWER_LIMIT,
CONF_POLYNOMIAL_CONFIG,
CONF_PRECISION,
CONF_UPPER_LIMIT,
DEFAULT_NAME,
DOMAIN,
)
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_ENTITY_ID, CONF_NAME
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
async def test_user_flow(
hass: HomeAssistant,
mock_setup_entry: AsyncMock,
) -> None:
"""Test full flow."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "user"
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_NAME: DEFAULT_NAME, CONF_ENTITY_ID: "sensor.test_sensor"},
)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "options"
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
CONF_LOWER_LIMIT: False,
CONF_POLYNOMIAL_CONFIG: {
CONF_DATAPOINTS: [
{"compensated_value": 6, "uncompensated_value": 5},
{"compensated_value": 8, "uncompensated_value": 7},
],
CONF_DEGREE: 1,
},
CONF_PRECISION: 2,
CONF_UPPER_LIMIT: False,
},
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == DEFAULT_NAME
assert result["data"] == {}
assert result["options"] == {
CONF_ENTITY_ID: "sensor.test_sensor",
CONF_LOWER_LIMIT: False,
CONF_NAME: "Compensation",
CONF_POLYNOMIAL_CONFIG: {
CONF_DATAPOINTS: [
{"compensated_value": 6, "uncompensated_value": 5},
{"compensated_value": 8, "uncompensated_value": 7},
],
CONF_DEGREE: 1,
},
CONF_PRECISION: 2,
CONF_UPPER_LIMIT: False,
}