1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-15 07:36:16 +00:00

Suppress warning if object_id is still added when default_entity_id is used in MQTT discovery (#151996)

This commit is contained in:
Jan Bouwhuis
2025-09-12 13:11:10 +02:00
committed by GitHub
parent 85afe87b5e
commit 4724ecbc38
2 changed files with 45 additions and 2 deletions

View File

@@ -1445,7 +1445,7 @@ class MqttEntity(
},
translation_key="deprecated_object_id",
)
else:
elif CONF_DEFAULT_ENTITY_ID not in self._config:
if CONF_ORIGIN in self._config:
origin_name = self._config[CONF_ORIGIN][CONF_NAME]
url = self._config[CONF_ORIGIN].get(CONF_URL)

View File

@@ -1331,7 +1331,7 @@ async def test_discover_alarm_control_panel(
@pytest.mark.parametrize(
("topic", "config", "entity_id", "name", "domain"),
("topic", "config", "entity_id", "name", "domain", "deprecation_warning"),
[
(
"homeassistant/alarm_control_panel/object/bla/config",
@@ -1339,6 +1339,7 @@ async def test_discover_alarm_control_panel(
"alarm_control_panel.hello_id",
"Hello World 1",
"alarm_control_panel",
True,
),
(
"homeassistant/binary_sensor/object/bla/config",
@@ -1346,6 +1347,7 @@ async def test_discover_alarm_control_panel(
"binary_sensor.hello_id",
"Hello World 2",
"binary_sensor",
True,
),
(
"homeassistant/button/object/bla/config",
@@ -1353,6 +1355,7 @@ async def test_discover_alarm_control_panel(
"button.hello_id",
"Hello World button",
"button",
True,
),
(
"homeassistant/camera/object/bla/config",
@@ -1360,6 +1363,7 @@ async def test_discover_alarm_control_panel(
"camera.hello_id",
"Hello World 3",
"camera",
True,
),
(
"homeassistant/climate/object/bla/config",
@@ -1367,6 +1371,7 @@ async def test_discover_alarm_control_panel(
"climate.hello_id",
"Hello World 4",
"climate",
True,
),
(
"homeassistant/cover/object/bla/config",
@@ -1374,6 +1379,7 @@ async def test_discover_alarm_control_panel(
"cover.hello_id",
"Hello World 5",
"cover",
True,
),
(
"homeassistant/fan/object/bla/config",
@@ -1381,6 +1387,7 @@ async def test_discover_alarm_control_panel(
"fan.hello_id",
"Hello World 6",
"fan",
True,
),
(
"homeassistant/humidifier/object/bla/config",
@@ -1388,6 +1395,7 @@ async def test_discover_alarm_control_panel(
"humidifier.hello_id",
"Hello World 7",
"humidifier",
True,
),
(
"homeassistant/number/object/bla/config",
@@ -1395,6 +1403,7 @@ async def test_discover_alarm_control_panel(
"number.hello_id",
"Hello World 8",
"number",
True,
),
(
"homeassistant/scene/object/bla/config",
@@ -1402,6 +1411,7 @@ async def test_discover_alarm_control_panel(
"scene.hello_id",
"Hello World 9",
"scene",
True,
),
(
"homeassistant/select/object/bla/config",
@@ -1409,6 +1419,7 @@ async def test_discover_alarm_control_panel(
"select.hello_id",
"Hello World 10",
"select",
True,
),
(
"homeassistant/sensor/object/bla/config",
@@ -1416,6 +1427,7 @@ async def test_discover_alarm_control_panel(
"sensor.hello_id",
"Hello World 11",
"sensor",
True,
),
(
"homeassistant/switch/object/bla/config",
@@ -1423,6 +1435,7 @@ async def test_discover_alarm_control_panel(
"switch.hello_id",
"Hello World 12",
"switch",
True,
),
(
"homeassistant/light/object/bla/config",
@@ -1430,6 +1443,7 @@ async def test_discover_alarm_control_panel(
"light.hello_id",
"Hello World 13",
"light",
True,
),
(
"homeassistant/light/object/bla/config",
@@ -1437,6 +1451,7 @@ async def test_discover_alarm_control_panel(
"light.hello_id",
"Hello World 14",
"light",
True,
),
(
"homeassistant/light/object/bla/config",
@@ -1444,6 +1459,7 @@ async def test_discover_alarm_control_panel(
"light.hello_id",
"Hello World 15",
"light",
True,
),
(
"homeassistant/vacuum/object/bla/config",
@@ -1451,6 +1467,7 @@ async def test_discover_alarm_control_panel(
"vacuum.hello_id",
"Hello World 16",
"vacuum",
True,
),
(
"homeassistant/valve/object/bla/config",
@@ -1458,6 +1475,7 @@ async def test_discover_alarm_control_panel(
"valve.hello_id",
"Hello World 17",
"valve",
True,
),
(
"homeassistant/lock/object/bla/config",
@@ -1465,6 +1483,7 @@ async def test_discover_alarm_control_panel(
"lock.hello_id",
"Hello World 18",
"lock",
True,
),
(
"homeassistant/device_tracker/object/bla/config",
@@ -1472,6 +1491,7 @@ async def test_discover_alarm_control_panel(
"device_tracker.hello_id",
"Hello World 19",
"device_tracker",
True,
),
(
"homeassistant/binary_sensor/object/bla/config",
@@ -1480,6 +1500,7 @@ async def test_discover_alarm_control_panel(
"binary_sensor.hello_id",
"Hello World 2",
"binary_sensor",
True,
),
(
"homeassistant/button/object/bla/config",
@@ -1489,6 +1510,7 @@ async def test_discover_alarm_control_panel(
"button.hello_id",
"Hello World button",
"button",
True,
),
(
"homeassistant/alarm_control_panel/object/bla/config",
@@ -1497,6 +1519,7 @@ async def test_discover_alarm_control_panel(
"alarm_control_panel.hello_id",
"Hello World 1",
"alarm_control_panel",
False,
),
(
"homeassistant/binary_sensor/object/bla/config",
@@ -1505,6 +1528,7 @@ async def test_discover_alarm_control_panel(
"binary_sensor.hello_id",
"Hello World 2",
"binary_sensor",
False,
),
(
"homeassistant/button/object/bla/config",
@@ -1514,17 +1538,31 @@ async def test_discover_alarm_control_panel(
"button.hello_id",
"Hello World button",
"button",
False,
),
(
"homeassistant/button/object/bla/config",
'{ "name": "Hello World button", "def_ent_id": "button.hello_id", '
'"obj_id": "hello_id_old", '
'"o": {"name": "X2mqtt", "url": "https://example.com/x2mqtt"}, '
'"command_topic": "test-topic" }',
"button.hello_id",
"Hello World button",
"button",
False,
),
],
)
async def test_discovery_with_object_id(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
topic: str,
config: str,
entity_id: str,
name: str,
domain: str,
deprecation_warning: bool,
) -> None:
"""Test discovering an MQTT entity with object_id."""
await mqtt_mock_entry()
@@ -1537,6 +1575,11 @@ async def test_discovery_with_object_id(
assert state.name == name
assert (domain, "object bla") in hass.data["mqtt"].discovery_already_discovered
assert (
f"The configuration for entity {domain}.hello_id uses the deprecated option `object_id`"
in caplog.text
) is deprecation_warning
async def test_discovery_with_default_entity_id_for_previous_deleted_entity(
hass: HomeAssistant,