diff --git a/homeassistant/components/mqtt/discovery.py b/homeassistant/components/mqtt/discovery.py index a3b120410c5..d01fb848eab 100644 --- a/homeassistant/components/mqtt/discovery.py +++ b/homeassistant/components/mqtt/discovery.py @@ -18,7 +18,7 @@ from homeassistant.components.mqtt import CONF_STATE_TOPIC _LOGGER = logging.getLogger(__name__) TOPIC_MATCHER = re.compile( - r'homeassistant/(?P\w+)/(?P\w+)/config') + r'(?P\w+)/(?P\w+)/(?P\w+)/config') SUPPORTED_COMPONENTS = ['binary_sensor', 'sensor'] @@ -26,6 +26,7 @@ SUPPORTED_COMPONENTS = ['binary_sensor', 'sensor'] @asyncio.coroutine def async_start(hass, discovery_topic, hass_config): """Initialization of MQTT Discovery.""" + # pylint: disable=unused-variable @asyncio.coroutine def async_device_message_received(topic, payload, qos): """Process the received message.""" @@ -34,7 +35,7 @@ def async_start(hass, discovery_topic, hass_config): if not match: return - component, object_id = match.groups() + prefix_topic, component, object_id = match.groups() try: payload = json.loads(payload) diff --git a/tests/components/mqtt/test_discovery.py b/tests/components/mqtt/test_discovery.py index 389fb37b489..134b679daea 100644 --- a/tests/components/mqtt/test_discovery.py +++ b/tests/components/mqtt/test_discovery.py @@ -1,4 +1,4 @@ -"""The tests for the MQTT component.""" +"""The tests for the MQTT discovery.""" import asyncio from unittest.mock import patch @@ -23,7 +23,7 @@ def test_subscribing_config_topic(hass, mqtt_mock): @asyncio.coroutine @patch('homeassistant.components.mqtt.discovery.async_load_platform') def test_invalid_topic(mock_load_platform, hass, mqtt_mock): - """Test sending in invalid JSON.""" + """Test sending to invalid topic.""" mock_load_platform.return_value = mock_coro() yield from async_start(hass, 'homeassistant', {}) @@ -50,7 +50,7 @@ def test_invalid_json(mock_load_platform, hass, mqtt_mock, caplog): @asyncio.coroutine @patch('homeassistant.components.mqtt.discovery.async_load_platform') def test_only_valid_components(mock_load_platform, hass, mqtt_mock, caplog): - """Test sending in invalid JSON.""" + """Test for a valid component.""" mock_load_platform.return_value = mock_coro() yield from async_start(hass, 'homeassistant', {}) @@ -62,7 +62,7 @@ def test_only_valid_components(mock_load_platform, hass, mqtt_mock, caplog): @asyncio.coroutine def test_correct_config_discovery(hass, mqtt_mock, caplog): - """Test sending in invalid JSON.""" + """Test sending in correct JSON.""" yield from async_start(hass, 'homeassistant', {}) async_fire_mqtt_message(hass, 'homeassistant/binary_sensor/bla/config',