Skip to content

Commit b01f5dd

Browse files
Raise repairs on platform setup for sql (home-assistant#153581)
1 parent 0cda0c4 commit b01f5dd

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

homeassistant/components/sql/sensor.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
AddConfigEntryEntitiesCallback,
3131
AddEntitiesCallback,
3232
)
33+
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
3334
from homeassistant.helpers.template import Template
3435
from homeassistant.helpers.trigger_template_entity import (
3536
CONF_AVAILABILITY,
@@ -69,6 +70,15 @@ async def async_setup_platform(
6970
) -> None:
7071
"""Set up the SQL sensor from yaml."""
7172
if (conf := discovery_info) is None:
73+
async_create_issue(
74+
hass,
75+
DOMAIN,
76+
"sensor_platform_yaml_not_supported",
77+
is_fixable=False,
78+
severity=IssueSeverity.WARNING,
79+
translation_key="platform_yaml_not_supported",
80+
learn_more_url="https://www.home-assistant.io/integrations/sql/",
81+
)
7282
return
7383

7484
name: Template = conf[CONF_NAME]

homeassistant/components/sql/strings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@
166166
"entity_id_query_does_full_table_scan": {
167167
"title": "SQL query does full table scan",
168168
"description": "The query `{query}` contains the keyword `entity_id` but does not reference the `states_meta` table. This will cause a full table scan and database instability. Please check the documentation and use `states_meta.entity_id` instead."
169+
},
170+
"platform_yaml_not_supported": {
171+
"title": "Platform YAML is not supported for SQL",
172+
"description": "Platform YAML setup is not supported.\nChange from configuring it in the `sensor:` key to use the `sql:` key directly in configuration.yaml.\nClick on learn more to see the documentation for details."
169173
}
170174
}
171175
}

tests/components/sql/test_sensor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ async def test_templates_with_yaml(
345345

346346

347347
async def test_config_from_old_yaml(
348-
recorder_mock: Recorder, hass: HomeAssistant
348+
recorder_mock: Recorder, hass: HomeAssistant, issue_registry: ir.IssueRegistry
349349
) -> None:
350350
"""Test the SQL sensor from old yaml config does not create any entity."""
351351
config = {
@@ -366,6 +366,9 @@ async def test_config_from_old_yaml(
366366

367367
state = hass.states.get("sensor.count_tables")
368368
assert not state
369+
issue = issue_registry.async_get_issue(DOMAIN, "sensor_platform_yaml_not_supported")
370+
assert issue is not None
371+
assert issue.severity == ir.IssueSeverity.WARNING
369372

370373

371374
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)