Update regex (#6216)
parent
85d0f2e861
commit
9f2719bb1f
|
@ -18,7 +18,7 @@ from homeassistant.components.mqtt import CONF_STATE_TOPIC
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
TOPIC_MATCHER = re.compile(
|
||||
r'homeassistant/(?P<component>\w+)/(?P<object_id>\w+)/config')
|
||||
r'(?P<prefix_topic>\w+)/(?P<component>\w+)/(?P<object_id>\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)
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue