mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Update regex (#6216)
This commit is contained in:
parent
85d0f2e861
commit
9f2719bb1f
@ -18,7 +18,7 @@ from homeassistant.components.mqtt import CONF_STATE_TOPIC
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
TOPIC_MATCHER = re.compile(
|
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']
|
SUPPORTED_COMPONENTS = ['binary_sensor', 'sensor']
|
||||||
|
|
||||||
@ -26,6 +26,7 @@ SUPPORTED_COMPONENTS = ['binary_sensor', 'sensor']
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_start(hass, discovery_topic, hass_config):
|
def async_start(hass, discovery_topic, hass_config):
|
||||||
"""Initialization of MQTT Discovery."""
|
"""Initialization of MQTT Discovery."""
|
||||||
|
# pylint: disable=unused-variable
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_device_message_received(topic, payload, qos):
|
def async_device_message_received(topic, payload, qos):
|
||||||
"""Process the received message."""
|
"""Process the received message."""
|
||||||
@ -34,7 +35,7 @@ def async_start(hass, discovery_topic, hass_config):
|
|||||||
if not match:
|
if not match:
|
||||||
return
|
return
|
||||||
|
|
||||||
component, object_id = match.groups()
|
prefix_topic, component, object_id = match.groups()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
payload = json.loads(payload)
|
payload = json.loads(payload)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
"""The tests for the MQTT component."""
|
"""The tests for the MQTT discovery."""
|
||||||
import asyncio
|
import asyncio
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ def test_subscribing_config_topic(hass, mqtt_mock):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@patch('homeassistant.components.mqtt.discovery.async_load_platform')
|
@patch('homeassistant.components.mqtt.discovery.async_load_platform')
|
||||||
def test_invalid_topic(mock_load_platform, hass, mqtt_mock):
|
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()
|
mock_load_platform.return_value = mock_coro()
|
||||||
yield from async_start(hass, 'homeassistant', {})
|
yield from async_start(hass, 'homeassistant', {})
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ def test_invalid_json(mock_load_platform, hass, mqtt_mock, caplog):
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@patch('homeassistant.components.mqtt.discovery.async_load_platform')
|
@patch('homeassistant.components.mqtt.discovery.async_load_platform')
|
||||||
def test_only_valid_components(mock_load_platform, hass, mqtt_mock, caplog):
|
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()
|
mock_load_platform.return_value = mock_coro()
|
||||||
yield from async_start(hass, 'homeassistant', {})
|
yield from async_start(hass, 'homeassistant', {})
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ def test_only_valid_components(mock_load_platform, hass, mqtt_mock, caplog):
|
|||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_correct_config_discovery(hass, mqtt_mock, caplog):
|
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', {})
|
yield from async_start(hass, 'homeassistant', {})
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, 'homeassistant/binary_sensor/bla/config',
|
async_fire_mqtt_message(hass, 'homeassistant/binary_sensor/bla/config',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user