mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Add test to MQTT device tracker (#52292)
This commit is contained in:
parent
8a82557142
commit
30a9198d97
@ -506,11 +506,8 @@ async def help_test_setting_blocked_attribute_via_mqtt_json_message(
|
|||||||
# Add JSON attributes settings to config
|
# Add JSON attributes settings to config
|
||||||
config = copy.deepcopy(config)
|
config = copy.deepcopy(config)
|
||||||
config[domain]["json_attributes_topic"] = "attr-topic"
|
config[domain]["json_attributes_topic"] = "attr-topic"
|
||||||
assert await async_setup_component(
|
data = json.dumps(config[domain])
|
||||||
hass,
|
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
|
||||||
domain,
|
|
||||||
config,
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
val = "abc123"
|
val = "abc123"
|
||||||
|
|
||||||
|
@ -2,11 +2,22 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.components import device_tracker
|
||||||
from homeassistant.components.mqtt.discovery import ALREADY_DISCOVERED
|
from homeassistant.components.mqtt.discovery import ALREADY_DISCOVERED
|
||||||
from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_UNKNOWN
|
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
|
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
|
@pytest.fixture
|
||||||
def device_reg(hass):
|
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")
|
state = hass.states.get("device_tracker.test")
|
||||||
assert state.attributes["latitude"] == 32.87336
|
assert state.attributes["latitude"] == 32.87336
|
||||||
assert state.state == STATE_UNKNOWN
|
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…
x
Reference in New Issue
Block a user