Add test to MQTT device tracker (#52292)
This commit is contained in:
parent
8a82557142
commit
30a9198d97
2 changed files with 20 additions and 5 deletions
|
@ -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"
|
||||
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue