@@ -1331,147 +1331,167 @@ async def test_discover_alarm_control_panel(
13311331
13321332
13331333@pytest .mark .parametrize (
1334- ("topic" , "config" , "entity_id" , "name" , "domain" ),
1334+ ("topic" , "config" , "entity_id" , "name" , "domain" , "deprecation_warning" ),
13351335 [
13361336 (
13371337 "homeassistant/alarm_control_panel/object/bla/config" ,
13381338 '{ "name": "Hello World 1", "obj_id": "hello_id", "state_topic": "test-topic", "command_topic": "test-topic" }' ,
13391339 "alarm_control_panel.hello_id" ,
13401340 "Hello World 1" ,
13411341 "alarm_control_panel" ,
1342+ True ,
13421343 ),
13431344 (
13441345 "homeassistant/binary_sensor/object/bla/config" ,
13451346 '{ "name": "Hello World 2", "obj_id": "hello_id", "state_topic": "test-topic" }' ,
13461347 "binary_sensor.hello_id" ,
13471348 "Hello World 2" ,
13481349 "binary_sensor" ,
1350+ True ,
13491351 ),
13501352 (
13511353 "homeassistant/button/object/bla/config" ,
13521354 '{ "name": "Hello World button", "obj_id": "hello_id", "command_topic": "test-topic" }' ,
13531355 "button.hello_id" ,
13541356 "Hello World button" ,
13551357 "button" ,
1358+ True ,
13561359 ),
13571360 (
13581361 "homeassistant/camera/object/bla/config" ,
13591362 '{ "name": "Hello World 3", "obj_id": "hello_id", "state_topic": "test-topic", "topic": "test-topic" }' ,
13601363 "camera.hello_id" ,
13611364 "Hello World 3" ,
13621365 "camera" ,
1366+ True ,
13631367 ),
13641368 (
13651369 "homeassistant/climate/object/bla/config" ,
13661370 '{ "name": "Hello World 4", "obj_id": "hello_id", "state_topic": "test-topic" }' ,
13671371 "climate.hello_id" ,
13681372 "Hello World 4" ,
13691373 "climate" ,
1374+ True ,
13701375 ),
13711376 (
13721377 "homeassistant/cover/object/bla/config" ,
13731378 '{ "name": "Hello World 5", "obj_id": "hello_id", "state_topic": "test-topic" }' ,
13741379 "cover.hello_id" ,
13751380 "Hello World 5" ,
13761381 "cover" ,
1382+ True ,
13771383 ),
13781384 (
13791385 "homeassistant/fan/object/bla/config" ,
13801386 '{ "name": "Hello World 6", "obj_id": "hello_id", "state_topic": "test-topic", "command_topic": "test-topic" }' ,
13811387 "fan.hello_id" ,
13821388 "Hello World 6" ,
13831389 "fan" ,
1390+ True ,
13841391 ),
13851392 (
13861393 "homeassistant/humidifier/object/bla/config" ,
13871394 '{ "name": "Hello World 7", "obj_id": "hello_id", "state_topic": "test-topic", "target_humidity_command_topic": "test-topic", "command_topic": "test-topic" }' ,
13881395 "humidifier.hello_id" ,
13891396 "Hello World 7" ,
13901397 "humidifier" ,
1398+ True ,
13911399 ),
13921400 (
13931401 "homeassistant/number/object/bla/config" ,
13941402 '{ "name": "Hello World 8", "obj_id": "hello_id", "state_topic": "test-topic", "command_topic": "test-topic" }' ,
13951403 "number.hello_id" ,
13961404 "Hello World 8" ,
13971405 "number" ,
1406+ True ,
13981407 ),
13991408 (
14001409 "homeassistant/scene/object/bla/config" ,
14011410 '{ "name": "Hello World 9", "obj_id": "hello_id", "state_topic": "test-topic", "command_topic": "test-topic" }' ,
14021411 "scene.hello_id" ,
14031412 "Hello World 9" ,
14041413 "scene" ,
1414+ True ,
14051415 ),
14061416 (
14071417 "homeassistant/select/object/bla/config" ,
14081418 '{ "name": "Hello World 10", "obj_id": "hello_id", "state_topic": "test-topic", "options": [ "opt1", "opt2" ], "command_topic": "test-topic" }' ,
14091419 "select.hello_id" ,
14101420 "Hello World 10" ,
14111421 "select" ,
1422+ True ,
14121423 ),
14131424 (
14141425 "homeassistant/sensor/object/bla/config" ,
14151426 '{ "name": "Hello World 11", "obj_id": "hello_id", "state_topic": "test-topic" }' ,
14161427 "sensor.hello_id" ,
14171428 "Hello World 11" ,
14181429 "sensor" ,
1430+ True ,
14191431 ),
14201432 (
14211433 "homeassistant/switch/object/bla/config" ,
14221434 '{ "name": "Hello World 12", "obj_id": "hello_id", "state_topic": "test-topic", "command_topic": "test-topic" }' ,
14231435 "switch.hello_id" ,
14241436 "Hello World 12" ,
14251437 "switch" ,
1438+ True ,
14261439 ),
14271440 (
14281441 "homeassistant/light/object/bla/config" ,
14291442 '{ "name": "Hello World 13", "obj_id": "hello_id", "state_topic": "test-topic", "command_topic": "test-topic" }' ,
14301443 "light.hello_id" ,
14311444 "Hello World 13" ,
14321445 "light" ,
1446+ True ,
14331447 ),
14341448 (
14351449 "homeassistant/light/object/bla/config" ,
14361450 '{ "name": "Hello World 14", "obj_id": "hello_id", "state_topic": "test-topic", "command_topic": "test-topic", "schema": "json" }' ,
14371451 "light.hello_id" ,
14381452 "Hello World 14" ,
14391453 "light" ,
1454+ True ,
14401455 ),
14411456 (
14421457 "homeassistant/light/object/bla/config" ,
14431458 '{ "name": "Hello World 15", "obj_id": "hello_id", "state_topic": "test-topic", "command_off_template": "template", "command_on_template": "template", "command_topic": "test-topic", "schema": "template" }' ,
14441459 "light.hello_id" ,
14451460 "Hello World 15" ,
14461461 "light" ,
1462+ True ,
14471463 ),
14481464 (
14491465 "homeassistant/vacuum/object/bla/config" ,
14501466 '{ "name": "Hello World 16", "obj_id": "hello_id", "state_topic": "test-topic", "schema": "state" }' ,
14511467 "vacuum.hello_id" ,
14521468 "Hello World 16" ,
14531469 "vacuum" ,
1470+ True ,
14541471 ),
14551472 (
14561473 "homeassistant/valve/object/bla/config" ,
14571474 '{ "name": "Hello World 17", "obj_id": "hello_id", "state_topic": "test-topic" }' ,
14581475 "valve.hello_id" ,
14591476 "Hello World 17" ,
14601477 "valve" ,
1478+ True ,
14611479 ),
14621480 (
14631481 "homeassistant/lock/object/bla/config" ,
14641482 '{ "name": "Hello World 18", "obj_id": "hello_id", "state_topic": "test-topic", "command_topic": "test-topic" }' ,
14651483 "lock.hello_id" ,
14661484 "Hello World 18" ,
14671485 "lock" ,
1486+ True ,
14681487 ),
14691488 (
14701489 "homeassistant/device_tracker/object/bla/config" ,
14711490 '{ "name": "Hello World 19", "obj_id": "hello_id", "state_topic": "test-topic" }' ,
14721491 "device_tracker.hello_id" ,
14731492 "Hello World 19" ,
14741493 "device_tracker" ,
1494+ True ,
14751495 ),
14761496 (
14771497 "homeassistant/binary_sensor/object/bla/config" ,
@@ -1480,6 +1500,7 @@ async def test_discover_alarm_control_panel(
14801500 "binary_sensor.hello_id" ,
14811501 "Hello World 2" ,
14821502 "binary_sensor" ,
1503+ True ,
14831504 ),
14841505 (
14851506 "homeassistant/button/object/bla/config" ,
@@ -1489,6 +1510,7 @@ async def test_discover_alarm_control_panel(
14891510 "button.hello_id" ,
14901511 "Hello World button" ,
14911512 "button" ,
1513+ True ,
14921514 ),
14931515 (
14941516 "homeassistant/alarm_control_panel/object/bla/config" ,
@@ -1497,6 +1519,7 @@ async def test_discover_alarm_control_panel(
14971519 "alarm_control_panel.hello_id" ,
14981520 "Hello World 1" ,
14991521 "alarm_control_panel" ,
1522+ False ,
15001523 ),
15011524 (
15021525 "homeassistant/binary_sensor/object/bla/config" ,
@@ -1505,6 +1528,7 @@ async def test_discover_alarm_control_panel(
15051528 "binary_sensor.hello_id" ,
15061529 "Hello World 2" ,
15071530 "binary_sensor" ,
1531+ False ,
15081532 ),
15091533 (
15101534 "homeassistant/button/object/bla/config" ,
@@ -1514,17 +1538,31 @@ async def test_discover_alarm_control_panel(
15141538 "button.hello_id" ,
15151539 "Hello World button" ,
15161540 "button" ,
1541+ False ,
1542+ ),
1543+ (
1544+ "homeassistant/button/object/bla/config" ,
1545+ '{ "name": "Hello World button", "def_ent_id": "button.hello_id", '
1546+ '"obj_id": "hello_id_old", '
1547+ '"o": {"name": "X2mqtt", "url": "https://example.com/x2mqtt"}, '
1548+ '"command_topic": "test-topic" }' ,
1549+ "button.hello_id" ,
1550+ "Hello World button" ,
1551+ "button" ,
1552+ False ,
15171553 ),
15181554 ],
15191555)
15201556async def test_discovery_with_object_id (
15211557 hass : HomeAssistant ,
15221558 mqtt_mock_entry : MqttMockHAClientGenerator ,
1559+ caplog : pytest .LogCaptureFixture ,
15231560 topic : str ,
15241561 config : str ,
15251562 entity_id : str ,
15261563 name : str ,
15271564 domain : str ,
1565+ deprecation_warning : bool ,
15281566) -> None :
15291567 """Test discovering an MQTT entity with object_id."""
15301568 await mqtt_mock_entry ()
@@ -1537,6 +1575,11 @@ async def test_discovery_with_object_id(
15371575 assert state .name == name
15381576 assert (domain , "object bla" ) in hass .data ["mqtt" ].discovery_already_discovered
15391577
1578+ assert (
1579+ f"The configuration for entity { domain } .hello_id uses the deprecated option `object_id`"
1580+ in caplog .text
1581+ ) is deprecation_warning
1582+
15401583
15411584async def test_discovery_with_default_entity_id_for_previous_deleted_entity (
15421585 hass : HomeAssistant ,
0 commit comments