Remove deprecated YAML connection configuration from influxdb (#189851)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
G Johansson
2026-11-03 09:16:45 +00:00
committed by GitHub
co-authored by Claude
parent abc5dbc26e
commit f9cbb69e55
8 changed files with 57 additions and 639 deletions
+21 -44
View File
@@ -19,7 +19,7 @@ import requests.exceptions
import urllib3.exceptions
from homeassistant import config as conf_util
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_API_VERSION,
CONF_DOMAIN,
@@ -43,7 +43,6 @@ from homeassistant.const import (
EntityStateAttribute,
)
from homeassistant.core import Event, HomeAssistant, State, callback
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import config_validation as cv, state as state_helper
from homeassistant.helpers.entity_values import EntityValues
@@ -51,7 +50,6 @@ from homeassistant.helpers.entityfilter import (
INCLUDE_EXCLUDE_BASE_FILTER_SCHEMA,
convert_include_exclude_filter,
)
from homeassistant.helpers.typing import ConfigType
from .const import (
API_VERSION_2,
@@ -61,8 +59,6 @@ from .const import (
CLIENT_ERROR_V1,
CLIENT_ERROR_V2,
CODE_INVALID_INPUTS,
COMPONENT_CONFIG_SCHEMA_CONNECTION,
COMPONENT_CONFIG_SCHEMA_CONNECTION_VALIDATORS,
CONF_BUCKET,
CONF_COMPONENT_CONFIG,
CONF_COMPONENT_CONFIG_DOMAIN,
@@ -104,7 +100,6 @@ from .const import (
WRITE_ERROR,
WROTE_MESSAGE,
)
from .issue import async_create_deprecated_yaml_issue
_LOGGER = logging.getLogger(__name__)
@@ -169,8 +164,9 @@ _CUSTOMIZE_ENTITY_SCHEMA = probatio.Schema(
}
)
_INFLUX_BASE_SCHEMA = INCLUDE_EXCLUDE_BASE_FILTER_SCHEMA.extend(
INFLUX_SCHEMA = INCLUDE_EXCLUDE_BASE_FILTER_SCHEMA.extend(
{
probatio.Optional(CONF_PRECISION): probatio.In(["ms", "s", "us", "ns"]),
probatio.Optional(CONF_RETRY_COUNT, default=0): cv.positive_int,
probatio.Optional(CONF_DEFAULT_MEASUREMENT): cv.string,
probatio.Optional(
@@ -198,13 +194,25 @@ _INFLUX_BASE_SCHEMA = INCLUDE_EXCLUDE_BASE_FILTER_SCHEMA.extend(
}
)
INFLUX_SCHEMA = _INFLUX_BASE_SCHEMA.extend(
COMPONENT_CONFIG_SCHEMA_CONNECTION_VALIDATORS
)
CONFIG_SCHEMA = probatio.Schema(
{DOMAIN: probatio.All(INFLUX_SCHEMA, validate_version_specific_config)},
{
DOMAIN: probatio.All(
cv.removed(CONF_API_VERSION, raise_if_present=False),
cv.removed(CONF_HOST, raise_if_present=False),
cv.removed(CONF_PORT, raise_if_present=False),
cv.removed(CONF_SSL, raise_if_present=False),
cv.removed(CONF_VERIFY_SSL, raise_if_present=False),
cv.removed(CONF_SSL_CA_CERT, raise_if_present=False),
cv.removed(CONF_USERNAME, raise_if_present=False),
cv.removed(CONF_PASSWORD, raise_if_present=False),
cv.removed(CONF_DB_NAME, raise_if_present=False),
cv.removed(CONF_TOKEN, raise_if_present=False),
cv.removed(CONF_ORG, raise_if_present=False),
cv.removed(CONF_BUCKET, raise_if_present=False),
cv.removed(CONF_PATH, raise_if_present=False),
INFLUX_SCHEMA,
)
},
extra=probatio.ALLOW_EXTRA,
)
@@ -507,37 +515,6 @@ def get_influx_connection( # noqa: C901
return InfluxClient(databases, write_v1, query_v1, close_v1)
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the InfluxDB component."""
if DOMAIN not in config:
return True
hass.async_create_task(_async_setup(hass, config[DOMAIN]))
return True
async def _async_setup(hass: HomeAssistant, config: dict[str, Any]) -> None:
"""Import YAML configuration into a config entry."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data=config,
)
if (
result.get("type") is FlowResultType.ABORT
and (reason := result["reason"]) != "single_instance_allowed"
):
async_create_deprecated_yaml_issue(hass, error=reason)
return
# If we are here, the entry already exists (single instance allowed)
if config.keys() & (
{k.schema for k in COMPONENT_CONFIG_SCHEMA_CONNECTION} - {CONF_PRECISION}
):
async_create_deprecated_yaml_issue(hass)
async def async_setup_entry(hass: HomeAssistant, entry: InfluxDBConfigEntry) -> None:
"""Set up InfluxDB from a config entry."""
data = entry.data
@@ -32,7 +32,7 @@ from homeassistant.helpers.selector import (
)
from homeassistant.helpers.storage import STORAGE_DIR
from . import create_influx_url, get_influx_connection
from . import get_influx_connection
from .const import (
API_VERSION_2,
CONF_BUCKET,
@@ -40,11 +40,8 @@ from .const import (
CONF_ORG,
CONF_SSL_CA_CERT,
DEFAULT_API_VERSION,
DEFAULT_BUCKET,
DEFAULT_DATABASE,
DEFAULT_HOST,
DEFAULT_PORT,
DEFAULT_VERIFY_SSL,
DOMAIN,
)
@@ -342,50 +339,3 @@ class InfluxDBConfigFlow(ConfigFlow, domain=DOMAIN):
),
errors=errors,
)
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Handle the initial step."""
import_data = {**import_data}
import_data.setdefault(CONF_API_VERSION, DEFAULT_API_VERSION)
import_data.setdefault(CONF_VERIFY_SSL, DEFAULT_VERIFY_SSL)
import_data.setdefault(CONF_DB_NAME, DEFAULT_DATABASE)
import_data.setdefault(CONF_BUCKET, DEFAULT_BUCKET)
api_version = import_data[CONF_API_VERSION]
if api_version == DEFAULT_API_VERSION:
host = import_data.get(CONF_HOST, DEFAULT_HOST)
database = import_data[CONF_DB_NAME]
title = f"{database} ({host})"
data = {
CONF_API_VERSION: api_version,
CONF_HOST: host,
CONF_PORT: import_data.get(CONF_PORT),
CONF_USERNAME: import_data.get(CONF_USERNAME),
CONF_PASSWORD: import_data.get(CONF_PASSWORD),
CONF_DB_NAME: database,
CONF_SSL: import_data.get(CONF_SSL),
CONF_PATH: import_data.get(CONF_PATH),
CONF_VERIFY_SSL: import_data[CONF_VERIFY_SSL],
CONF_SSL_CA_CERT: import_data.get(CONF_SSL_CA_CERT),
}
else:
create_influx_url(import_data) # Only modifies dict for api_version == 2
bucket = import_data[CONF_BUCKET]
url = import_data.get(CONF_URL)
title = f"{bucket} ({url})"
data = {
CONF_API_VERSION: api_version,
CONF_URL: url,
CONF_TOKEN: import_data.get(CONF_TOKEN),
CONF_ORG: import_data.get(CONF_ORG),
CONF_BUCKET: bucket,
CONF_VERIFY_SSL: import_data[CONF_VERIFY_SSL],
CONF_SSL_CA_CERT: import_data.get(CONF_SSL_CA_CERT),
}
errors = await _validate_influxdb_connection(self.hass, data)
if errors:
return self.async_abort(reason=errors["base"])
return self.async_create_entry(title=title, data=data)
@@ -154,14 +154,3 @@ COMPONENT_CONFIG_SCHEMA_CONNECTION = {
probatio.Inclusive(CONF_ORG, "v2_authentication"): cv.string,
probatio.Optional(CONF_BUCKET, default=DEFAULT_BUCKET): cv.string,
}
# Same keys without defaults, used in CONFIG_SCHEMA to validate
# without injecting default values (so we can detect explicit keys).
COMPONENT_CONFIG_SCHEMA_CONNECTION_VALIDATORS = {
(
probatio.Optional(k.schema)
if isinstance(k, probatio.Optional) and k.default is not probatio.UNDEFINED
else k
): v
for k, v in COMPONENT_CONFIG_SCHEMA_CONNECTION.items()
}
@@ -1,34 +0,0 @@
"""Issues for InfluxDB integration."""
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from .const import DOMAIN
@callback
def async_create_deprecated_yaml_issue(
hass: HomeAssistant, *, error: str | None = None
) -> None:
"""Create a repair issue for deprecated YAML connection configuration."""
if error is None:
issue_id = "deprecated_yaml"
severity = IssueSeverity.WARNING
else:
issue_id = f"deprecated_yaml_import_issue_{error}"
severity = IssueSeverity.ERROR
async_create_issue(
hass,
DOMAIN,
issue_id,
is_fixable=False,
issue_domain=DOMAIN,
breaks_in_ha_version="2026.9.0",
severity=severity,
translation_key=issue_id,
translation_placeholders={
"domain": DOMAIN,
"url": f"/config/integrations/dashboard/add?domain={DOMAIN}",
},
)
@@ -43,9 +43,6 @@
},
"title": "InfluxDB configuration"
},
"import": {
"title": "Import configuration"
},
"reconfigure_v1": {
"data": {
"database": "[%key:component::influxdb::config::step::configure_v1::data::database%]",
@@ -87,31 +84,5 @@
"title": "Choose InfluxDB version"
}
}
},
"issues": {
"deprecated_yaml": {
"description": "Configuring InfluxDB connection settings using YAML is being removed. Your existing YAML connection configuration has been imported into the UI automatically.\n\nRemove the `{domain}` connection and authentication keys from your `configuration.yaml` file and restart Home Assistant to fix this issue. Other options like `include`, `exclude`, and `tags` remain in YAML for now. \n\nThe following keys should be removed:\n- `api_version`\n- `host`\n- `port`\n- `ssl`\n- `verify_ssl`\n- `ssl_ca_cert`\n- `username`\n- `password`\n- `database`\n- `token`\n- `organization`\n- `bucket`\n- `path`",
"title": "The InfluxDB YAML configuration is being removed"
},
"deprecated_yaml_import_issue_cannot_connect": {
"description": "Configuring InfluxDB connection settings using YAML is being removed but the import failed because Home Assistant could not connect to the InfluxDB server.\n\nPlease correct your YAML configuration and restart Home Assistant.\n\nAlternatively you can remove the `{domain}` connection and authentication keys from your `configuration.yaml` file and continue to [set up the integration]({url}) manually. \n\nThe following keys should be removed:\n- `api_version`\n- `host`\n- `port`\n- `ssl`\n- `verify_ssl`\n- `ssl_ca_cert`\n- `username`\n- `password`\n- `database`\n- `token`\n- `organization`\n- `bucket`\n- `path`",
"title": "Failed to import InfluxDB YAML configuration"
},
"deprecated_yaml_import_issue_invalid_auth": {
"description": "Configuring InfluxDB connection settings using YAML is being removed but the import failed because the provided credentials are invalid.\n\nPlease correct your YAML configuration and restart Home Assistant.\n\nAlternatively you can remove the `{domain}` connection and authentication keys from your `configuration.yaml` file and continue to [set up the integration]({url}) manually. \n\nThe following keys should be removed:\n- `api_version`\n- `host`\n- `port`\n- `ssl`\n- `verify_ssl`\n- `ssl_ca_cert`\n- `username`\n- `password`\n- `database`\n- `token`\n- `organization`\n- `bucket`\n- `path`",
"title": "[%key:component::influxdb::issues::deprecated_yaml_import_issue_cannot_connect::title%]"
},
"deprecated_yaml_import_issue_invalid_database": {
"description": "Configuring InfluxDB connection settings using YAML is being removed but the import failed because the specified database was not found.\n\nPlease correct your YAML configuration and restart Home Assistant.\n\nAlternatively you can remove the `{domain}` connection and authentication keys from your `configuration.yaml` file and continue to [set up the integration]({url}) manually. \n\nThe following keys should be removed:\n- `api_version`\n- `host`\n- `port`\n- `ssl`\n- `verify_ssl`\n- `ssl_ca_cert`\n- `username`\n- `password`\n- `database`\n- `token`\n- `organization`\n- `bucket`\n- `path`",
"title": "[%key:component::influxdb::issues::deprecated_yaml_import_issue_cannot_connect::title%]"
},
"deprecated_yaml_import_issue_ssl_error": {
"description": "Configuring InfluxDB connection settings using YAML is being removed but the import failed due to an SSL certificate error.\n\nPlease correct your YAML configuration and restart Home Assistant.\n\nAlternatively you can remove the `{domain}` connection and authentication keys from your `configuration.yaml` file and continue to [set up the integration]({url}) manually. \n\nThe following keys should be removed:\n- `api_version`\n- `host`\n- `port`\n- `ssl`\n- `verify_ssl`\n- `ssl_ca_cert`\n- `username`\n- `password`\n- `database`\n- `token`\n- `organization`\n- `bucket`\n- `path`",
"title": "[%key:component::influxdb::issues::deprecated_yaml_import_issue_cannot_connect::title%]"
},
"deprecated_yaml_import_issue_unknown": {
"description": "Configuring InfluxDB connection settings using YAML is being removed but the import failed due to an unknown error.\n\nPlease correct your YAML configuration and restart Home Assistant.\n\nAlternatively you can remove the `{domain}` connection and authentication keys from your `configuration.yaml` file and continue to [set up the integration]({url}) manually. \n\nThe following keys should be removed:\n- `api_version`\n- `host`\n- `port`\n- `ssl`\n- `verify_ssl`\n- `ssl_ca_cert`\n- `username`\n- `password`\n- `database`\n- `token`\n- `organization`\n- `bucket`\n- `path`",
"title": "[%key:component::influxdb::issues::deprecated_yaml_import_issue_cannot_connect::title%]"
}
}
}
-1
View File
@@ -75,7 +75,6 @@ BASE_OPTIONS = {
CONF_COMPONENT_CONFIG: {},
CONF_COMPONENT_CONFIG_GLOB: {},
CONF_COMPONENT_CONFIG_DOMAIN: {},
CONF_BUCKET: "Home Assistant",
}
INFLUX_PATH = "homeassistant.components.influxdb"
+1 -154
View File
@@ -6,7 +6,7 @@ from pathlib import Path
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch
from influxdb.exceptions import InfluxDBClientError, InfluxDBServerError
from influxdb.exceptions import InfluxDBClientError
import pytest
from pytest_homeassistant.common import MockConfigEntry
@@ -38,7 +38,6 @@ from homeassistant.data_entry_flow import FlowResultType
from . import (
BASE_V1_CONFIG,
BASE_V2_CONFIG,
INFLUX_CLIENT_PATH,
_get_write_api_mock_v1,
_get_write_api_mock_v2,
@@ -594,158 +593,6 @@ async def test_single_instance(
assert result["reason"] == "single_instance_allowed"
@pytest.mark.parametrize(
("mock_client", "config_base", "get_write_api", "db_name", "host"),
[
(
DEFAULT_API_VERSION,
BASE_V1_CONFIG,
_get_write_api_mock_v1,
BASE_V1_CONFIG[CONF_DB_NAME],
BASE_V1_CONFIG[CONF_HOST],
),
(
API_VERSION_2,
BASE_V2_CONFIG,
_get_write_api_mock_v2,
BASE_V2_CONFIG[CONF_BUCKET],
BASE_V2_CONFIG[CONF_URL],
),
],
indirect=["mock_client"],
)
@pytest.mark.usefixtures("mock_setup_entry")
async def test_import(
hass: HomeAssistant,
mock_client: MagicMock,
config_base: dict[str, Any],
get_write_api: Any,
db_name: str,
host: str,
) -> None:
"""Test we can import."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data=config_base,
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == f"{db_name} ({host})"
assert result["data"] == config_base
assert get_write_api(mock_client).call_count == 1
@pytest.mark.parametrize(
("mock_client", "config_base", "get_write_api", "test_exception", "reason"),
[
(
DEFAULT_API_VERSION,
BASE_V1_CONFIG,
_get_write_api_mock_v1,
ConnectionError("fail"),
"cannot_connect",
),
(
DEFAULT_API_VERSION,
BASE_V1_CONFIG,
_get_write_api_mock_v1,
InfluxDBClientError("fail"),
"cannot_connect",
),
(
DEFAULT_API_VERSION,
BASE_V1_CONFIG,
_get_write_api_mock_v1,
InfluxDBServerError("fail"),
"cannot_connect",
),
(
API_VERSION_2,
BASE_V2_CONFIG,
_get_write_api_mock_v2,
ConnectionError("fail"),
"cannot_connect",
),
(
API_VERSION_2,
BASE_V2_CONFIG,
_get_write_api_mock_v2,
ApiException(http_resp=MagicMock()),
"invalid_config",
),
(
API_VERSION_2,
BASE_V2_CONFIG,
_get_write_api_mock_v2,
Exception(),
"unknown",
),
],
indirect=["mock_client"],
)
async def test_import_connection_error(
hass: HomeAssistant,
mock_client: MagicMock,
config_base: dict[str, Any],
get_write_api: Any,
test_exception: Exception,
reason: str,
) -> None:
"""Test abort on connection error."""
write_api = get_write_api(mock_client)
write_api.side_effect = test_exception
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data=config_base,
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == reason
@pytest.mark.parametrize(
("mock_client", "config_base", "get_write_api"),
[
(
DEFAULT_API_VERSION,
BASE_V1_CONFIG,
_get_write_api_mock_v1,
),
],
indirect=["mock_client"],
)
@pytest.mark.usefixtures("mock_setup_entry")
async def test_single_instance_import(
hass: HomeAssistant,
mock_client: MagicMock,
config_base: dict[str, Any],
get_write_api: Any,
) -> None:
"""Test we cannot setup a second entry for InfluxDB."""
mock_entry = MockConfigEntry(
domain=DOMAIN,
data=config_base,
)
mock_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_entry.entry_id)
await hass.async_block_till_done()
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data=config_base,
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "single_instance_allowed"
@pytest.mark.parametrize(
("mock_client", "entry_data", "user_input", "expected_data", "expected_title"),
[
+34 -315
View File
@@ -9,6 +9,7 @@ import math
from typing import Any
from unittest.mock import ANY, MagicMock, Mock, call, patch
import probatio
import pytest
from pytest_homeassistant.common import MockConfigEntry
@@ -23,7 +24,7 @@ from homeassistant.const import (
STATE_STANDBY,
)
from homeassistant.core import HomeAssistant, split_entity_id
from homeassistant.helpers import issue_registry as ir
from homeassistant.helpers.typing import ConfigType
from homeassistant.setup import async_setup_component
from . import (
@@ -96,91 +97,6 @@ def get_mock_call_fixture(request: pytest.FixtureRequest):
return lambda body, precision=None: call(body, time_precision=precision)
@pytest.mark.parametrize(
(
"hass_config",
"mock_client",
"config_base",
"config_ext",
"config_update",
"get_write_api",
),
[
(
{"influxdb": BASE_OPTIONS},
influxdb.DEFAULT_API_VERSION,
BASE_V1_CONFIG,
{
"api_version": influxdb.DEFAULT_API_VERSION,
"username": "user",
"password": "password",
"database": "db",
"ssl": False,
"verify_ssl": False,
},
{
"host": "host",
"port": 123,
},
_get_write_api_mock_v1,
),
(
{"influxdb": BASE_OPTIONS},
influxdb.API_VERSION_2,
BASE_V2_CONFIG,
{
"api_version": influxdb.API_VERSION_2,
"token": "token",
"organization": "organization",
"bucket": "bucket",
},
{"url": "https://host:123"},
_get_write_api_mock_v2,
),
],
indirect=["mock_client"],
)
async def test_setup_config_full(
hass: HomeAssistant,
mock_client,
config_base,
config_ext,
config_update,
get_write_api,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test the setup with full configuration."""
config = {
"influxdb": {
"host": "host",
"port": 123,
}
}
config["influxdb"].update(config_ext)
assert await async_setup_component(hass, influxdb.DOMAIN, config)
await hass.async_block_till_done()
assert get_write_api(mock_client).call_count == 2
conf_entries = hass.config_entries.async_entries(DOMAIN)
assert len(conf_entries) == 1
entry = conf_entries[0]
full_config = config_base.copy()
full_config.update(config_update)
full_config.update(config_ext)
assert entry.state is ConfigEntryState.LOADED
assert entry.data == full_config
assert issue_registry.async_get_issue(
domain=DOMAIN,
issue_id="deprecated_yaml",
)
@pytest.mark.parametrize(
("hass_config", "mock_client", "config_base", "config_ext", "expected_client_args"),
[
@@ -367,159 +283,56 @@ async def test_setup_config_path(
assert mock_client.call_args.kwargs.get(CONF_PATH) == expected_path
@pytest.mark.parametrize(
("mock_client", "get_write_api", "config_ext"),
[
(influxdb.DEFAULT_API_VERSION, _get_write_api_mock_v1, {}),
(influxdb.DEFAULT_API_VERSION, _get_write_api_mock_v1, {"precision": "s"}),
],
indirect=["mock_client"],
)
async def test_setup_minimal_config_no_connection_keys(
hass: HomeAssistant,
mock_client,
get_write_api,
config_ext,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test the setup with non-connection YAML keys creates no deprecation issue."""
config = {"influxdb": {}}
config["influxdb"].update(config_ext)
assert await async_setup_component(hass, influxdb.DOMAIN, config)
await hass.async_block_till_done()
assert get_write_api(mock_client).call_count == 2
conf_entries = hass.config_entries.async_entries(DOMAIN)
assert len(conf_entries) == 1
entry = conf_entries[0]
assert entry.state is ConfigEntryState.LOADED
assert entry.data == BASE_V1_CONFIG
assert not issue_registry.async_get_issue(domain=DOMAIN, issue_id="deprecated_yaml")
async def test_invalid_config_schema(hass: HomeAssistant) -> None:
"""Test that invalid options are rejected in YAML."""
with pytest.raises(probatio.Invalid):
influxdb.CONFIG_SCHEMA({"influxdb": {"precision": "invalid"}})
@pytest.mark.parametrize(
("mock_client", "config_ext", "config_base", "get_write_api"),
("hass_config", "mock_client", "config_base"),
[
(
influxdb.API_VERSION_2,
{
"api_version": influxdb.API_VERSION_2,
"organization": "org",
"token": "token",
},
BASE_V2_CONFIG,
_get_write_api_mock_v2,
),
],
indirect=["mock_client"],
)
async def test_setup_minimal_config_with_connection_keys(
hass: HomeAssistant,
mock_client,
config_ext,
config_base,
get_write_api,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test the setup with connection keys creates a deprecation issue."""
config = {"influxdb": {}}
config["influxdb"].update(config_ext)
assert await async_setup_component(hass, influxdb.DOMAIN, config)
await hass.async_block_till_done()
assert get_write_api(mock_client).call_count == 2
conf_entries = hass.config_entries.async_entries(DOMAIN)
assert len(conf_entries) == 1
entry = conf_entries[0]
assert entry.state is ConfigEntryState.LOADED
assert entry.data == config_base
assert issue_registry.async_get_issue(domain=DOMAIN, issue_id="deprecated_yaml")
@pytest.mark.parametrize(
"config_ext",
[
{"username": "user"},
{"api_version": influxdb.API_VERSION_2, "organization": "organization"},
{"token": "token", "organization": "organization"},
{"api_version": influxdb.API_VERSION_2},
{
"api_version": influxdb.API_VERSION_2,
"token": "token",
"organization": "organization",
"username": "user",
"password": "pass",
},
],
)
async def test_invalid_config_schema(
hass: HomeAssistant,
config_ext,
) -> None:
"""Test that invalid schema configs are rejected at setup."""
config = {"influxdb": {}}
config["influxdb"].update(config_ext)
assert not await async_setup_component(hass, influxdb.DOMAIN, config)
@pytest.mark.parametrize(
("mock_client", "config_base", "config_ext", "get_write_api"),
[
(
pytest.param(
{"influxdb": {"host": "host", "port": 123, "precision": "s"}},
influxdb.DEFAULT_API_VERSION,
BASE_V1_CONFIG,
{},
_get_write_api_mock_v1,
id="v1",
),
(
pytest.param(
{
"influxdb": {
"api_version": influxdb.API_VERSION_2,
"token": "token",
"organization": "organization",
"bucket": "bucket",
"precision": "s",
}
},
influxdb.API_VERSION_2,
BASE_V2_CONFIG,
{
"api_version": influxdb.API_VERSION_2,
"organization": "org",
"token": "token",
},
_get_write_api_mock_v2,
id="v2",
),
],
indirect=["mock_client"],
)
async def test_setup_no_import_when_config_entry_exist(
hass: HomeAssistant, mock_client, config_base, config_ext, get_write_api
async def test_removed_connection_keys(
hass: HomeAssistant,
hass_config: ConfigType,
mock_client: MagicMock,
config_base: dict[str, Any],
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test the setup with minimal configuration and defaults."""
config = {"influxdb": {}}
config["influxdb"].update(config_ext)
mock_entry = MockConfigEntry(
domain=DOMAIN,
data=config_base,
)
"""Test that leftover YAML connection keys are logged and ignored."""
mock_entry = MockConfigEntry(domain=DOMAIN, data=config_base)
mock_entry.add_to_hass(hass)
conf_entries = hass.config_entries.async_entries(DOMAIN)
assert len(conf_entries) == 1
assert await async_setup_component(hass, influxdb.DOMAIN, config)
assert await async_setup_component(hass, DOMAIN, hass_config)
await hass.async_block_till_done()
conf_entries = hass.config_entries.async_entries(DOMAIN)
assert len(conf_entries) == 1
assert mock_entry.state is ConfigEntryState.LOADED
for key in hass_config[DOMAIN].keys() - {"precision"}:
assert f"The '{key}' option has been removed" in caplog.text
assert "The 'precision' option" not in caplog.text
async def _setup(
@@ -2285,97 +2098,3 @@ async def test_precision(
assert write_api.call_count == 1
assert write_api.call_args == get_mock_call(body, precision)
write_api.reset_mock()
@pytest.mark.parametrize(
("mock_client", "config_ext", "get_write_api"),
[
(
influxdb.DEFAULT_API_VERSION,
{
"api_version": influxdb.DEFAULT_API_VERSION,
"host": "host",
"port": 123,
"username": "user",
"password": "password",
"database": "db",
"ssl": False,
"verify_ssl": False,
},
_get_write_api_mock_v1,
),
(
influxdb.API_VERSION_2,
{
"api_version": influxdb.API_VERSION_2,
"token": "token",
"organization": "organization",
"bucket": "bucket",
},
_get_write_api_mock_v2,
),
],
indirect=["mock_client"],
)
async def test_setup_import_connection_error(
hass: HomeAssistant,
mock_client: MagicMock,
config_ext: dict[str, Any],
get_write_api,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test that a repair issue is created on import connection error."""
write_api = get_write_api(mock_client)
write_api.side_effect = ConnectionError("fail")
config = {"influxdb": {}}
config["influxdb"].update(config_ext)
assert await async_setup_component(hass, influxdb.DOMAIN, config)
await hass.async_block_till_done()
assert issue_registry.async_get_issue(
domain=DOMAIN,
issue_id="deprecated_yaml_import_issue_cannot_connect",
)
@pytest.mark.parametrize(
("mock_client", "config_ext", "get_write_api"),
[
(
influxdb.DEFAULT_API_VERSION,
{
"host": "localhost",
"username": "user",
"password": "password",
"database": "db",
},
_get_write_api_mock_v1,
),
],
indirect=["mock_client"],
)
async def test_setup_import_already_exists(
hass: HomeAssistant,
mock_client: MagicMock,
config_ext: dict[str, Any],
get_write_api,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test that no error issue is created when a config entry already exists."""
mock_entry = MockConfigEntry(domain=DOMAIN, data=BASE_V1_CONFIG)
mock_entry.add_to_hass(hass)
config = {"influxdb": {}}
config["influxdb"].update(config_ext)
assert await async_setup_component(hass, influxdb.DOMAIN, config)
await hass.async_block_till_done()
# No error issue should be created for single_instance_allowed
for issue in issue_registry.issues.values():
assert "deprecated_yaml_import_issue" not in issue.issue_id
# Deprecation warning should still be shown
assert issue_registry.async_get_issue(domain=DOMAIN, issue_id="deprecated_yaml")