diff --git a/tests/components/mqtt/test_common.py b/tests/components/mqtt/test_common.py index d8a263131a9..c3a4022fdd8 100644 --- a/tests/components/mqtt/test_common.py +++ b/tests/components/mqtt/test_common.py @@ -506,11 +506,8 @@ async def help_test_setting_blocked_attribute_via_mqtt_json_message( # Add JSON attributes settings to config config = copy.deepcopy(config) config[domain]["json_attributes_topic"] = "attr-topic" - assert await async_setup_component( - hass, - domain, - config, - ) + data = json.dumps(config[domain]) + async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data) await hass.async_block_till_done() val = "abc123" diff --git a/tests/components/mqtt/test_device_tracker_discovery.py b/tests/components/mqtt/test_device_tracker_discovery.py index 174db8f017a..4020c2beaeb 100644 --- a/tests/components/mqtt/test_device_tracker_discovery.py +++ b/tests/components/mqtt/test_device_tracker_discovery.py @@ -2,11 +2,22 @@ import pytest +from homeassistant.components import device_tracker from homeassistant.components.mqtt.discovery import ALREADY_DISCOVERED from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_UNKNOWN +from .test_common import help_test_setting_blocked_attribute_via_mqtt_json_message + from tests.common import async_fire_mqtt_message, mock_device_registry, mock_registry +DEFAULT_CONFIG = { + device_tracker.DOMAIN: { + "platform": "mqtt", + "name": "test", + "state_topic": "test-topic", + } +} + @pytest.fixture def device_reg(hass): @@ -360,3 +371,10 @@ async def test_setting_device_tracker_location_via_lat_lon_message( state = hass.states.get("device_tracker.test") assert state.attributes["latitude"] == 32.87336 assert state.state == STATE_UNKNOWN + + +async def test_setting_blocked_attribute_via_mqtt_json_message(hass, mqtt_mock): + """Test the setting of attribute via MQTT with JSON payload.""" + await help_test_setting_blocked_attribute_via_mqtt_json_message( + hass, mqtt_mock, device_tracker.DOMAIN, DEFAULT_CONFIG, None + )