mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Move MQTT discovery removal tests to platform test files (#16861)
This commit is contained in:
parent
399040de46
commit
eb59f2dd3c
@ -7,10 +7,11 @@ from homeassistant.const import (
|
|||||||
STATE_ALARM_PENDING, STATE_ALARM_TRIGGERED, STATE_UNAVAILABLE,
|
STATE_ALARM_PENDING, STATE_ALARM_TRIGGERED, STATE_UNAVAILABLE,
|
||||||
STATE_UNKNOWN)
|
STATE_UNKNOWN)
|
||||||
from homeassistant.components import alarm_control_panel
|
from homeassistant.components import alarm_control_panel
|
||||||
|
from homeassistant.components.mqtt.discovery import async_start
|
||||||
|
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
mock_mqtt_component, fire_mqtt_message, get_test_home_assistant,
|
mock_mqtt_component, async_fire_mqtt_message, fire_mqtt_message,
|
||||||
assert_setup_component)
|
get_test_home_assistant, assert_setup_component)
|
||||||
|
|
||||||
CODE = 'HELLO_CODE'
|
CODE = 'HELLO_CODE'
|
||||||
|
|
||||||
@ -239,3 +240,32 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
|
|||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||||
|
|
||||||
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
fire_mqtt_message(self.hass, 'availability-topic', 'good')
|
||||||
|
|
||||||
|
|
||||||
|
async def test_discovery_removal_alarm(hass, mqtt_mock, caplog):
|
||||||
|
"""Test removal of discovered alarm_control_panel."""
|
||||||
|
await async_start(hass, 'homeassistant', {})
|
||||||
|
|
||||||
|
data = (
|
||||||
|
'{ "name": "Beer",'
|
||||||
|
' "status_topic": "test_topic",'
|
||||||
|
' "command_topic": "test_topic" }'
|
||||||
|
)
|
||||||
|
|
||||||
|
async_fire_mqtt_message(hass,
|
||||||
|
'homeassistant/alarm_control_panel/bla/config',
|
||||||
|
data)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get('alarm_control_panel.beer')
|
||||||
|
assert state is not None
|
||||||
|
assert state.name == 'Beer'
|
||||||
|
|
||||||
|
async_fire_mqtt_message(hass,
|
||||||
|
'homeassistant/alarm_control_panel/bla/config',
|
||||||
|
'')
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get('alarm_control_panel.beer')
|
||||||
|
assert state is None
|
||||||
|
@ -4,6 +4,7 @@ import unittest
|
|||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.setup import setup_component, async_setup_component
|
from homeassistant.setup import setup_component, async_setup_component
|
||||||
import homeassistant.components.binary_sensor as binary_sensor
|
import homeassistant.components.binary_sensor as binary_sensor
|
||||||
|
from homeassistant.components.mqtt.discovery import async_start
|
||||||
|
|
||||||
from homeassistant.const import STATE_OFF, STATE_ON
|
from homeassistant.const import STATE_OFF, STATE_ON
|
||||||
from homeassistant.const import EVENT_STATE_CHANGED, STATE_UNAVAILABLE
|
from homeassistant.const import EVENT_STATE_CHANGED, STATE_UNAVAILABLE
|
||||||
@ -226,3 +227,24 @@ async def test_unique_id(hass):
|
|||||||
async_fire_mqtt_message(hass, 'test-topic', 'payload')
|
async_fire_mqtt_message(hass, 'test-topic', 'payload')
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(hass.states.async_all()) == 1
|
assert len(hass.states.async_all()) == 1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_discovery_removal_binary_sensor(hass, mqtt_mock, caplog):
|
||||||
|
"""Test removal of discovered binary_sensor."""
|
||||||
|
await async_start(hass, 'homeassistant', {})
|
||||||
|
data = (
|
||||||
|
'{ "name": "Beer",'
|
||||||
|
' "status_topic": "test_topic" }'
|
||||||
|
)
|
||||||
|
async_fire_mqtt_message(hass, 'homeassistant/binary_sensor/bla/config',
|
||||||
|
data)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
state = hass.states.get('binary_sensor.beer')
|
||||||
|
assert state is not None
|
||||||
|
assert state.name == 'Beer'
|
||||||
|
async_fire_mqtt_message(hass, 'homeassistant/binary_sensor/bla/config',
|
||||||
|
'')
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
state = hass.states.get('binary_sensor.beer')
|
||||||
|
assert state is None
|
||||||
|
@ -146,10 +146,11 @@ from homeassistant.setup import setup_component
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_ON, STATE_OFF, STATE_UNAVAILABLE, ATTR_ASSUMED_STATE)
|
STATE_ON, STATE_OFF, STATE_UNAVAILABLE, ATTR_ASSUMED_STATE)
|
||||||
import homeassistant.components.light as light
|
import homeassistant.components.light as light
|
||||||
|
from homeassistant.components.mqtt.discovery import async_start
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
assert_setup_component, get_test_home_assistant, mock_mqtt_component,
|
assert_setup_component, get_test_home_assistant, mock_mqtt_component,
|
||||||
fire_mqtt_message, mock_coro)
|
async_fire_mqtt_message, fire_mqtt_message, mock_coro)
|
||||||
|
|
||||||
|
|
||||||
class TestLightMQTT(unittest.TestCase):
|
class TestLightMQTT(unittest.TestCase):
|
||||||
@ -876,3 +877,30 @@ class TestLightMQTT(unittest.TestCase):
|
|||||||
|
|
||||||
state = self.hass.states.get('light.test')
|
state = self.hass.states.get('light.test')
|
||||||
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
self.assertEqual(STATE_UNAVAILABLE, state.state)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_discovery_removal_light(hass, mqtt_mock, caplog):
|
||||||
|
"""Test removal of discovered light."""
|
||||||
|
await async_start(hass, 'homeassistant', {})
|
||||||
|
|
||||||
|
data = (
|
||||||
|
'{ "name": "Beer",'
|
||||||
|
' "status_topic": "test_topic",'
|
||||||
|
' "command_topic": "test_topic" }'
|
||||||
|
)
|
||||||
|
|
||||||
|
async_fire_mqtt_message(hass, 'homeassistant/light/bla/config',
|
||||||
|
data)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get('light.beer')
|
||||||
|
assert state is not None
|
||||||
|
assert state.name == 'Beer'
|
||||||
|
|
||||||
|
async_fire_mqtt_message(hass, 'homeassistant/light/bla/config',
|
||||||
|
'')
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get('light.beer')
|
||||||
|
assert state is None
|
||||||
|
@ -181,111 +181,3 @@ def test_non_duplicate_discovery(hass, mqtt_mock, caplog):
|
|||||||
assert state_duplicate is None
|
assert state_duplicate is None
|
||||||
assert 'Component has already been discovered: ' \
|
assert 'Component has already been discovered: ' \
|
||||||
'binary_sensor bla' in caplog.text
|
'binary_sensor bla' in caplog.text
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
|
||||||
def test_discovery_removal(hass, mqtt_mock, caplog):
|
|
||||||
"""Test expansion of abbreviated discovery payload."""
|
|
||||||
yield from async_start(hass, 'homeassistant', {})
|
|
||||||
|
|
||||||
data = (
|
|
||||||
'{ "name": "Beer",'
|
|
||||||
' "status_topic": "test_topic",'
|
|
||||||
' "command_topic": "test_topic" }'
|
|
||||||
)
|
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, 'homeassistant/switch/bla/config',
|
|
||||||
data)
|
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = hass.states.get('switch.beer')
|
|
||||||
assert state is not None
|
|
||||||
assert state.name == 'Beer'
|
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, 'homeassistant/switch/bla/config',
|
|
||||||
'')
|
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = hass.states.get('switch.beer')
|
|
||||||
assert state is None
|
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
|
||||||
def test_discovery_removal_binary_sensor(hass, mqtt_mock, caplog):
|
|
||||||
"""Test removal of discovered binary_sensor."""
|
|
||||||
yield from async_start(hass, 'homeassistant', {})
|
|
||||||
data = (
|
|
||||||
'{ "name": "Beer",'
|
|
||||||
' "status_topic": "test_topic" }'
|
|
||||||
)
|
|
||||||
async_fire_mqtt_message(hass, 'homeassistant/binary_sensor/bla/config',
|
|
||||||
data)
|
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
state = hass.states.get('binary_sensor.beer')
|
|
||||||
assert state is not None
|
|
||||||
assert state.name == 'Beer'
|
|
||||||
async_fire_mqtt_message(hass, 'homeassistant/binary_sensor/bla/config',
|
|
||||||
'')
|
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
state = hass.states.get('binary_sensor.beer')
|
|
||||||
assert state is None
|
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
|
||||||
def test_discovery_removal_light(hass, mqtt_mock, caplog):
|
|
||||||
"""Test removal of discovered light."""
|
|
||||||
yield from async_start(hass, 'homeassistant', {})
|
|
||||||
|
|
||||||
data = (
|
|
||||||
'{ "name": "Beer",'
|
|
||||||
' "status_topic": "test_topic",'
|
|
||||||
' "command_topic": "test_topic" }'
|
|
||||||
)
|
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, 'homeassistant/light/bla/config',
|
|
||||||
data)
|
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = hass.states.get('light.beer')
|
|
||||||
assert state is not None
|
|
||||||
assert state.name == 'Beer'
|
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, 'homeassistant/light/bla/config',
|
|
||||||
'')
|
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = hass.states.get('light.beer')
|
|
||||||
assert state is None
|
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
|
||||||
def test_discovery_removal_alarm(hass, mqtt_mock, caplog):
|
|
||||||
"""Test removal of discovered alarm_control_panel."""
|
|
||||||
yield from async_start(hass, 'homeassistant', {})
|
|
||||||
|
|
||||||
data = (
|
|
||||||
'{ "name": "Beer",'
|
|
||||||
' "status_topic": "test_topic",'
|
|
||||||
' "command_topic": "test_topic" }'
|
|
||||||
)
|
|
||||||
|
|
||||||
async_fire_mqtt_message(hass,
|
|
||||||
'homeassistant/alarm_control_panel/bla/config',
|
|
||||||
data)
|
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = hass.states.get('alarm_control_panel.beer')
|
|
||||||
assert state is not None
|
|
||||||
assert state.name == 'Beer'
|
|
||||||
|
|
||||||
async_fire_mqtt_message(hass,
|
|
||||||
'homeassistant/alarm_control_panel/bla/config',
|
|
||||||
'')
|
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = hass.states.get('alarm_control_panel.beer')
|
|
||||||
assert state is None
|
|
||||||
|
@ -7,6 +7,7 @@ from homeassistant.const import STATE_ON, STATE_OFF, STATE_UNAVAILABLE,\
|
|||||||
ATTR_ASSUMED_STATE
|
ATTR_ASSUMED_STATE
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
import homeassistant.components.switch as switch
|
import homeassistant.components.switch as switch
|
||||||
|
from homeassistant.components.mqtt.discovery import async_start
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
mock_mqtt_component, fire_mqtt_message, get_test_home_assistant, mock_coro,
|
mock_mqtt_component, fire_mqtt_message, get_test_home_assistant, mock_coro,
|
||||||
async_mock_mqtt_component, async_fire_mqtt_message)
|
async_mock_mqtt_component, async_fire_mqtt_message)
|
||||||
@ -306,3 +307,30 @@ async def test_unique_id(hass):
|
|||||||
|
|
||||||
assert len(hass.states.async_entity_ids()) == 2
|
assert len(hass.states.async_entity_ids()) == 2
|
||||||
# all switches group is 1, unique id created is 1
|
# all switches group is 1, unique id created is 1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_discovery_removal_switch(hass, mqtt_mock, caplog):
|
||||||
|
"""Test expansion of discovered switch."""
|
||||||
|
await async_start(hass, 'homeassistant', {})
|
||||||
|
|
||||||
|
data = (
|
||||||
|
'{ "name": "Beer",'
|
||||||
|
' "status_topic": "test_topic",'
|
||||||
|
' "command_topic": "test_topic" }'
|
||||||
|
)
|
||||||
|
|
||||||
|
async_fire_mqtt_message(hass, 'homeassistant/switch/bla/config',
|
||||||
|
data)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get('switch.beer')
|
||||||
|
assert state is not None
|
||||||
|
assert state.name == 'Beer'
|
||||||
|
|
||||||
|
async_fire_mqtt_message(hass, 'homeassistant/switch/bla/config',
|
||||||
|
'')
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get('switch.beer')
|
||||||
|
assert state is None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user