Skip to content

Commit

Permalink
Update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery committed Sep 19, 2018
1 parent 0489815 commit b757c07
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions tests/components/mqtt/test_discovery.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""The tests for the MQTT discovery."""
import asyncio
import unittest
from unittest.mock import patch

from homeassistant.components.mqtt.discovery import async_start, \
ALREADY_DISCOVERED
from homeassistant.const import STATE_ON, STATE_OFF

from tests.common import async_fire_mqtt_message, mock_coro

from tests.common import (
mock_mqtt_component, fire_mqtt_message, get_test_home_assistant,
async_fire_mqtt_message, mock_coro)

@asyncio.coroutine
def test_subscribing_config_topic(hass, mqtt_mock):
Expand Down Expand Up @@ -189,17 +192,25 @@ def test_discovery_expansion(hass, mqtt_mock, caplog):
yield from async_start(hass, 'homeassistant', {})

data = (
'{ "name": "DiscoveryExpansionTest",'
' "stat_t": "test_topic",'
' "cmd_t": "test_topic" }'
'{ "~": "some/prefix",'
' "name": "DiscoveryExpansionTest",'
' "stat_t": "~/test_topic",'
' "cmd_t": "~/test_topic" }'
)

async_fire_mqtt_message(
hass, 'homeassistant/switch/bla/config', data)
yield from hass.async_block_till_done()

state = hass.states.get('switch.DiscoveryExpansionTest')

assert state is not None
assert state.name == 'DiscoveryExpansionTest'
assert ('switch', 'bla') in hass.data[ALREADY_DISCOVERED]
assert state.state == STATE_OFF

async_fire_mqtt_message(hass, 'some/prefix/test_topic', 'ON')
yield from hass.async_block_till_done()
yield from hass.async_block_till_done()

state = hass.states.get('switch.DiscoveryExpansionTest')
assert state.state == STATE_ON

0 comments on commit b757c07

Please sign in to comment.