* Create config_flow.py
* Update __init__.py
* Create const.py
* Create strings.json
* Update sensor.py
* Update manifest.json
* Update manifest.json
* Add device name to entities
* Correcting health sensor
* Update manifest.json
* Adding integration_type
* Update sensor.py
* Update __init__.py
* Enums
* Update sensor.py
* Removed unused notify_create
* Switch to SensorDeviceClass.TEMPERATURE
* Update enums
* Remove SENSOR_TYPES from const.py
* Add SENSOR_TYPES to sensor.py
* Removed dependancies
* Removed import yaml
* Removed entity_registry_enabled_default
* Update const.py remove dups
* Update manifest.json removed dups
* Update __init__.py
* Update const.py
* Update manifest.json
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py remove unused
* Update sensor.py add docstring
* Update sensor.py add super
* Remove FOLDER sensors
* Remove VOLUME_NAME
* fix cli
* fix cli
* Add config flow tests
* Update requirements_test_all.txt
* Update CODEOWNERS
* Update homeassistant/components/qnap/config_flow.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/config_flow.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/config_flow.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update __init__.py
Change unload to walrus
Remove async_setup
* Update const.py remove PLATFORMS
* Update __init__.py add Platform Enum
As per epenet
* Update __init__.py
* Update config_flow.py
* Update sensor.py
* Update __init__.py
ruff
* Update config_flow.py
Ruff
* Update sensor.py
* Update const.py remove attrs
* Update sensor.py add attrs
* Revert tuple for sensor extend
* Update sensor.py
* Update coordinator.py
* Update coordinator.py
* Update sensor.py
* Update coordinator.py
* Update homeassistant/components/qnap/__init__.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/const.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/__init__.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update coordinator.py
* Update __init__.py
* Update coordinator.py
* Update sensor.py
* Add device_info
* Update sensor.py
* Update sensor.py self._attr_unique_id
* Update sensor.py
* Update sensor.py
* Type Hints
* Move tuples
* Drive sensor name
* Remove caps
* Remove caps
* Add YAML import
* Update sensor.py fix ruff
* Revert tuples
* Update sensor.py as per review
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* Update sensor.py
* assert uid is not None
* Update homeassistant/components/qnap/sensor.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/sensor.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update .coveragerc
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/config_flow.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/config_flow.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/const.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update homeassistant/components/qnap/const.py
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Apply suggestions from code review
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Apply suggestions from code review
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
* Update sensor.py
* Update config_flow.py add imports
* Update const.py
* Update sensor.py move confs to const
* Update config_flow.py add const
* Update test_config_flow.py remove const name
* Update test_config_flow.py remove standard result const
* Update test_config_flow.py
* Combine tests
* Update test_config_flow.py
* Update config_flow.py
* Update test_config_flow.py
* Update config_flow.py
* Update test_config_flow.py
* Update test_config_flow.py
* Update sensor.py change UID as requested
* Update sensor.py added check for monitor_device
* fix tests
* Remove rounding
* Revert "Remove rounding"
This reverts commit 61bf653c06
.
---------
Co-authored-by: starkillerOG <starkiller.og@gmail.com>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
110 lines
3.4 KiB
Python
110 lines
3.4 KiB
Python
"""Test the QNAP config flow."""
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
from requests.exceptions import ConnectTimeout
|
|
|
|
from homeassistant import config_entries, data_entry_flow
|
|
from homeassistant.components.qnap import const
|
|
from homeassistant.const import (
|
|
CONF_HOST,
|
|
CONF_PASSWORD,
|
|
CONF_PORT,
|
|
CONF_SSL,
|
|
CONF_USERNAME,
|
|
CONF_VERIFY_SSL,
|
|
)
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from .conftest import TEST_HOST, TEST_PASSWORD, TEST_USERNAME
|
|
|
|
STANDARD_CONFIG = {
|
|
CONF_USERNAME: TEST_USERNAME,
|
|
CONF_PASSWORD: TEST_PASSWORD,
|
|
CONF_HOST: TEST_HOST,
|
|
}
|
|
|
|
|
|
pytestmark = pytest.mark.usefixtures("mock_setup_entry", "qnap_connect")
|
|
|
|
|
|
async def test_config_flow(hass: HomeAssistant, qnap_connect: MagicMock) -> None:
|
|
"""Config flow manually initialized by the user."""
|
|
result = await hass.config_entries.flow.async_init(
|
|
const.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
|
)
|
|
|
|
assert result["type"] is data_entry_flow.FlowResultType.FORM
|
|
assert result["step_id"] == "user"
|
|
assert result["errors"] == {}
|
|
|
|
qnap_connect.get_system_stats.side_effect = ConnectTimeout("Test error")
|
|
result = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
STANDARD_CONFIG,
|
|
)
|
|
|
|
assert result["type"] is data_entry_flow.FlowResultType.FORM
|
|
assert result["step_id"] == "user"
|
|
assert result["errors"] == {"base": "cannot_connect"}
|
|
|
|
qnap_connect.get_system_stats.side_effect = TypeError("Test error")
|
|
result = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
STANDARD_CONFIG,
|
|
)
|
|
|
|
assert result["type"] is data_entry_flow.FlowResultType.FORM
|
|
assert result["step_id"] == "user"
|
|
assert result["errors"] == {"base": "invalid_auth"}
|
|
|
|
qnap_connect.get_system_stats.side_effect = Exception("Test error")
|
|
result = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
STANDARD_CONFIG,
|
|
)
|
|
|
|
assert result["type"] is data_entry_flow.FlowResultType.FORM
|
|
assert result["step_id"] == "user"
|
|
assert result["errors"] == {"base": "unknown"}
|
|
|
|
qnap_connect.get_system_stats.side_effect = None
|
|
result = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
STANDARD_CONFIG,
|
|
)
|
|
|
|
assert result["type"] is data_entry_flow.FlowResultType.CREATE_ENTRY
|
|
assert result["title"] == "Test NAS name"
|
|
assert result["data"] == {
|
|
CONF_HOST: "1.2.3.4",
|
|
CONF_USERNAME: "admin",
|
|
CONF_PASSWORD: "password",
|
|
CONF_SSL: const.DEFAULT_SSL,
|
|
CONF_VERIFY_SSL: const.DEFAULT_VERIFY_SSL,
|
|
CONF_PORT: const.DEFAULT_PORT,
|
|
}
|
|
|
|
|
|
async def test_config_flow_import(hass: HomeAssistant) -> None:
|
|
"""Test import of YAML config."""
|
|
data = STANDARD_CONFIG
|
|
data[CONF_SSL] = const.DEFAULT_SSL
|
|
data[CONF_VERIFY_SSL] = const.DEFAULT_VERIFY_SSL
|
|
data[CONF_PORT] = const.DEFAULT_PORT
|
|
result = await hass.config_entries.flow.async_init(
|
|
const.DOMAIN,
|
|
context={"source": config_entries.SOURCE_IMPORT},
|
|
data=data,
|
|
)
|
|
|
|
assert result["type"] is data_entry_flow.FlowResultType.CREATE_ENTRY
|
|
assert result["title"] == "Test NAS name"
|
|
assert result["data"] == {
|
|
CONF_HOST: "1.2.3.4",
|
|
CONF_USERNAME: "admin",
|
|
CONF_PASSWORD: "password",
|
|
CONF_SSL: const.DEFAULT_SSL,
|
|
CONF_VERIFY_SSL: const.DEFAULT_VERIFY_SSL,
|
|
CONF_PORT: const.DEFAULT_PORT,
|
|
}
|