Skip to content

Commit 4e29476

Browse files
authored
Cleanup deprecated YAML import from datadog (home-assistant#161870)
1 parent b432808 commit 4e29476

6 files changed

Lines changed: 35 additions & 217 deletions

File tree

homeassistant/components/datadog/__init__.py

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import logging
44

55
from datadog import DogStatsd, initialize
6-
import voluptuous as vol
76

8-
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
7+
from homeassistant.config_entries import ConfigEntry
98
from homeassistant.const import (
109
CONF_HOST,
1110
CONF_PORT,
@@ -16,53 +15,15 @@
1615
)
1716
from homeassistant.core import HomeAssistant
1817
from homeassistant.helpers import config_validation as cv, state as state_helper
19-
from homeassistant.helpers.typing import ConfigType
2018

2119
from . import config_flow as config_flow
22-
from .const import (
23-
CONF_RATE,
24-
DEFAULT_HOST,
25-
DEFAULT_PORT,
26-
DEFAULT_PREFIX,
27-
DEFAULT_RATE,
28-
DOMAIN,
29-
)
20+
from .const import CONF_RATE, DOMAIN
3021

3122
_LOGGER = logging.getLogger(__name__)
3223

3324
type DatadogConfigEntry = ConfigEntry[DogStatsd]
3425

35-
CONFIG_SCHEMA = vol.Schema(
36-
{
37-
DOMAIN: vol.Schema(
38-
{
39-
vol.Required(CONF_HOST, default=DEFAULT_HOST): cv.string,
40-
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
41-
vol.Optional(CONF_PREFIX, default=DEFAULT_PREFIX): cv.string,
42-
vol.Optional(CONF_RATE, default=DEFAULT_RATE): vol.All(
43-
vol.Coerce(int), vol.Range(min=1)
44-
),
45-
}
46-
)
47-
},
48-
extra=vol.ALLOW_EXTRA,
49-
)
50-
51-
52-
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
53-
"""Set up the Datadog integration from YAML, initiating config flow import."""
54-
if DOMAIN not in config:
55-
return True
56-
57-
hass.async_create_task(
58-
hass.config_entries.flow.async_init(
59-
DOMAIN,
60-
context={"source": SOURCE_IMPORT},
61-
data=config[DOMAIN],
62-
)
63-
)
64-
65-
return True
26+
CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
6627

6728

6829
async def async_setup_entry(hass: HomeAssistant, entry: DatadogConfigEntry) -> bool:

homeassistant/components/datadog/config_flow.py

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
OptionsFlow,
1313
)
1414
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_PREFIX
15-
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant, callback
16-
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
15+
from homeassistant.core import HomeAssistant, callback
1716

1817
from .const import (
1918
CONF_RATE,
@@ -71,22 +70,6 @@ async def async_step_user(
7170
errors=errors,
7271
)
7372

74-
async def async_step_import(self, user_input: dict[str, Any]) -> ConfigFlowResult:
75-
"""Handle import from configuration.yaml."""
76-
# Check for duplicates
77-
self._async_abort_entries_match(
78-
{CONF_HOST: user_input[CONF_HOST], CONF_PORT: user_input[CONF_PORT]}
79-
)
80-
81-
result = await self.async_step_user(user_input)
82-
83-
if errors := result.get("errors"):
84-
await deprecate_yaml_issue(self.hass, False)
85-
return self.async_abort(reason=errors["base"])
86-
87-
await deprecate_yaml_issue(self.hass, True)
88-
return result
89-
9073
@staticmethod
9174
@callback
9275
def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlow:
@@ -163,41 +146,3 @@ async def validate_datadog_connection(
163146
return False
164147
else:
165148
return True
166-
167-
168-
async def deprecate_yaml_issue(
169-
hass: HomeAssistant,
170-
import_success: bool,
171-
) -> None:
172-
"""Create an issue to deprecate YAML config."""
173-
if import_success:
174-
async_create_issue(
175-
hass,
176-
HOMEASSISTANT_DOMAIN,
177-
f"deprecated_yaml_{DOMAIN}",
178-
is_fixable=False,
179-
issue_domain=DOMAIN,
180-
breaks_in_ha_version="2026.2.0",
181-
severity=IssueSeverity.WARNING,
182-
translation_key="deprecated_yaml",
183-
translation_placeholders={
184-
"domain": DOMAIN,
185-
"integration_title": "Datadog",
186-
},
187-
)
188-
else:
189-
async_create_issue(
190-
hass,
191-
DOMAIN,
192-
"deprecated_yaml_import_connection_error",
193-
breaks_in_ha_version="2026.2.0",
194-
is_fixable=False,
195-
issue_domain=DOMAIN,
196-
severity=IssueSeverity.WARNING,
197-
translation_key="deprecated_yaml_import_connection_error",
198-
translation_placeholders={
199-
"domain": DOMAIN,
200-
"integration_title": "Datadog",
201-
"url": f"/config/integrations/dashboard/add?domain={DOMAIN}",
202-
},
203-
)

homeassistant/components/datadog/strings.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@
2525
}
2626
}
2727
},
28-
"issues": {
29-
"deprecated_yaml_import_connection_error": {
30-
"description": "There was an error connecting to the Datadog Agent when trying to import the YAML configuration.\n\nEnsure the YAML configuration is correct and restart Home Assistant to try again or remove the {domain} configuration from your `configuration.yaml` file and continue to [set up the integration]({url}) manually.",
31-
"title": "{domain} YAML configuration import failed"
32-
}
33-
},
3428
"options": {
3529
"abort": {
3630
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",

tests/components/datadog/common.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@
1414

1515
MOCK_CONFIG = {**MOCK_DATA, **MOCK_OPTIONS}
1616

17-
MOCK_YAML_INVALID = {
18-
"host": "127.0.0.1",
19-
"port": 65535,
20-
"prefix": "failtest",
21-
"rate": 1,
22-
}
23-
24-
2517
CONNECTION_TEST_METRIC = "connection_test"
2618

2719

tests/components/datadog/test_config_flow.py

Lines changed: 10 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
from unittest.mock import MagicMock, patch
44

5-
from homeassistant.components import datadog
6-
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
7-
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
5+
from homeassistant.components.datadog.const import DOMAIN
6+
from homeassistant.config_entries import SOURCE_USER
7+
from homeassistant.core import HomeAssistant
88
from homeassistant.data_entry_flow import FlowResultType
9-
import homeassistant.helpers.issue_registry as ir
109

11-
from .common import MOCK_CONFIG, MOCK_DATA, MOCK_OPTIONS, MOCK_YAML_INVALID
10+
from .common import MOCK_CONFIG, MOCK_DATA, MOCK_OPTIONS
1211

1312
from tests.common import MockConfigEntry
1413

@@ -22,7 +21,7 @@ async def test_user_flow_success(hass: HomeAssistant) -> None:
2221
mock_dogstatsd.return_value = mock_instance
2322

2423
result = await hass.config_entries.flow.async_init(
25-
datadog.DOMAIN, context={"source": SOURCE_USER}
24+
DOMAIN, context={"source": SOURCE_USER}
2625
)
2726
assert result["type"] is FlowResultType.FORM
2827

@@ -42,7 +41,7 @@ async def test_user_flow_retry_after_connection_fail(hass: HomeAssistant) -> Non
4241
side_effect=OSError("Connection failed"),
4342
):
4443
result = await hass.config_entries.flow.async_init(
45-
datadog.DOMAIN, context={"source": SOURCE_USER}
44+
DOMAIN, context={"source": SOURCE_USER}
4645
)
4746

4847
result2 = await hass.config_entries.flow.async_configure(
@@ -67,14 +66,14 @@ async def test_user_flow_abort_already_configured_service(
6766
) -> None:
6867
"""Abort user-initiated config flow if the same host/port is already configured."""
6968
existing_entry = MockConfigEntry(
70-
domain=datadog.DOMAIN,
69+
domain=DOMAIN,
7170
data=MOCK_DATA,
7271
options=MOCK_OPTIONS,
7372
)
7473
existing_entry.add_to_hass(hass)
7574

7675
result = await hass.config_entries.flow.async_init(
77-
datadog.DOMAIN,
76+
DOMAIN,
7877
context={"source": SOURCE_USER},
7978
)
8079

@@ -93,7 +92,7 @@ async def test_user_flow_abort_already_configured_service(
9392
async def test_options_flow_cannot_connect(hass: HomeAssistant) -> None:
9493
"""Test that the options flow shows an error when connection fails."""
9594
mock_entry = MockConfigEntry(
96-
domain=datadog.DOMAIN,
95+
domain=DOMAIN,
9796
data=MOCK_DATA,
9897
options=MOCK_OPTIONS,
9998
)
@@ -123,67 +122,10 @@ async def test_options_flow_cannot_connect(hass: HomeAssistant) -> None:
123122
assert result3["data"] == MOCK_OPTIONS
124123

125124

126-
async def test_import_flow(
127-
hass: HomeAssistant, issue_registry: ir.IssueRegistry
128-
) -> None:
129-
"""Test import triggers config flow and is accepted."""
130-
with (
131-
patch(
132-
"homeassistant.components.datadog.config_flow.DogStatsd"
133-
) as mock_dogstatsd,
134-
):
135-
mock_instance = MagicMock()
136-
mock_dogstatsd.return_value = mock_instance
137-
138-
result = await hass.config_entries.flow.async_init(
139-
datadog.DOMAIN,
140-
context={"source": SOURCE_IMPORT},
141-
data=MOCK_CONFIG,
142-
)
143-
144-
assert result["type"] is FlowResultType.CREATE_ENTRY
145-
assert result["data"] == MOCK_DATA
146-
assert result["options"] == MOCK_OPTIONS
147-
148-
await hass.async_block_till_done()
149-
150-
# Deprecation issue should be created
151-
issue = issue_registry.async_get_issue(
152-
HOMEASSISTANT_DOMAIN, "deprecated_yaml_datadog"
153-
)
154-
assert issue is not None
155-
assert issue.translation_key == "deprecated_yaml"
156-
assert issue.severity == ir.IssueSeverity.WARNING
157-
158-
159-
async def test_import_connection_error(
160-
hass: HomeAssistant, issue_registry: ir.IssueRegistry
161-
) -> None:
162-
"""Test import triggers connection error issue."""
163-
with patch(
164-
"homeassistant.components.datadog.config_flow.DogStatsd",
165-
side_effect=OSError("connection refused"),
166-
):
167-
result = await hass.config_entries.flow.async_init(
168-
datadog.DOMAIN,
169-
context={"source": SOURCE_IMPORT},
170-
data=MOCK_YAML_INVALID,
171-
)
172-
assert result["type"] == "abort"
173-
assert result["reason"] == "cannot_connect"
174-
175-
issue = issue_registry.async_get_issue(
176-
datadog.DOMAIN, "deprecated_yaml_import_connection_error"
177-
)
178-
assert issue is not None
179-
assert issue.translation_key == "deprecated_yaml_import_connection_error"
180-
assert issue.severity == ir.IssueSeverity.WARNING
181-
182-
183125
async def test_options_flow(hass: HomeAssistant) -> None:
184126
"""Test updating options after setup."""
185127
mock_entry = MockConfigEntry(
186-
domain=datadog.DOMAIN,
128+
domain=DOMAIN,
187129
data=MOCK_DATA,
188130
options=MOCK_OPTIONS,
189131
)
@@ -234,24 +176,3 @@ async def test_options_flow(hass: HomeAssistant) -> None:
234176
assert result["type"] is FlowResultType.CREATE_ENTRY
235177
assert result["data"] == new_options
236178
mock_instance.increment.assert_called_once_with("connection_test")
237-
238-
239-
async def test_import_flow_abort_already_configured_service(
240-
hass: HomeAssistant,
241-
) -> None:
242-
"""Abort import if the same host/port is already configured."""
243-
existing_entry = MockConfigEntry(
244-
domain=datadog.DOMAIN,
245-
data=MOCK_DATA,
246-
options=MOCK_OPTIONS,
247-
)
248-
existing_entry.add_to_hass(hass)
249-
250-
result = await hass.config_entries.flow.async_init(
251-
datadog.DOMAIN,
252-
context={"source": SOURCE_IMPORT},
253-
data=MOCK_CONFIG,
254-
)
255-
256-
assert result["type"] is FlowResultType.ABORT
257-
assert result["reason"] == "already_configured"

0 commit comments

Comments
 (0)