core/tests/components/device_tracker/test_mqtt.py

45 lines
1.5 KiB
Python
Raw Normal View History

2016-03-09 09:25:50 +00:00
"""The tests for the MQTT device tracker platform."""
2015-09-12 16:15:28 +00:00
import unittest
import os
from homeassistant.bootstrap import _setup_component
2015-09-12 16:15:28 +00:00
from homeassistant.components import device_tracker
from homeassistant.const import CONF_PLATFORM
from tests.common import (
get_test_home_assistant, mock_mqtt_component, fire_mqtt_message)
class TestComponentsDeviceTrackerMQTT(unittest.TestCase):
2016-03-09 09:25:50 +00:00
"""Test MQTT device tracker platform."""
2015-09-12 16:15:28 +00:00
def setUp(self): # pylint: disable=invalid-name
2016-03-09 09:25:50 +00:00
"""Setup things to be run when tests are started."""
2015-09-12 16:15:28 +00:00
self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
def tearDown(self): # pylint: disable=invalid-name
2016-03-09 09:25:50 +00:00
"""Stop everything that was started."""
2015-09-12 16:15:28 +00:00
try:
os.remove(self.hass.config.path(device_tracker.YAML_DEVICES))
except FileNotFoundError:
pass
def test_new_message(self):
2016-03-09 09:25:50 +00:00
"""Test new message."""
2015-09-12 16:15:28 +00:00
dev_id = 'paulus'
enttiy_id = device_tracker.ENTITY_ID_FORMAT.format(dev_id)
topic = '/location/paulus'
location = 'work'
self.hass.config.components = ['mqtt', 'zone']
assert _setup_component(self.hass, device_tracker.DOMAIN, {
2015-09-12 16:15:28 +00:00
device_tracker.DOMAIN: {
CONF_PLATFORM: 'mqtt',
'devices': {dev_id: topic}
}
})
2015-09-12 16:15:28 +00:00
fire_mqtt_message(self.hass, topic, location)
self.hass.pool.block_till_done()
self.assertEqual(location, self.hass.states.get(enttiy_id).state)