Clean up RFLink tests and add two tests (#19511)

* some minor tests refactor

* unused import
This commit is contained in:
javicalle authored and Martin Hjelmare committed 2018-12-22 08:53:02 +01:00
1 parent 3a3d488de3
commit fb226e3e3b
5 files changed
+136 -143

No files matched your search

+12 -17
View File
@@ -5,12 +5,10 @@ automatic sensor creation.
"""
import asyncio
from ..test_rflink import mock_rflink
from homeassistant.components.rflink import (
CONF_RECONNECT_INTERVAL)
from homeassistant.const import STATE_UNKNOWN
from ..test_rflink import mock_rflink
DOMAIN = 'sensor'
@@ -31,11 +29,10 @@ CONFIG = {
}
@asyncio.coroutine
def test_default_setup(hass, monkeypatch):
async def test_default_setup(hass, monkeypatch):
"""Test all basic functionality of the rflink sensor component."""
# setup mocking rflink module
event_callback, create, _, disconnect_callback = yield from mock_rflink(
event_callback, create, _, _ = await mock_rflink(
hass, CONFIG, DOMAIN, monkeypatch)
# make sure arguments are passed
@@ -54,7 +51,7 @@ def test_default_setup(hass, monkeypatch):
'value': 1,
'unit': '°C',
})
yield from hass.async_block_till_done()
await hass.async_block_till_done()
assert hass.states.get('sensor.test').state == '1'
@@ -65,7 +62,7 @@ def test_default_setup(hass, monkeypatch):
'value': 0,
'unit': '°C',
})
yield from hass.async_block_till_done()
await hass.async_block_till_done()
# test state of new sensor
new_sensor = hass.states.get('sensor.test2')
@@ -75,8 +72,7 @@ def test_default_setup(hass, monkeypatch):
assert new_sensor.attributes['icon'] == 'mdi:thermometer'
@asyncio.coroutine
def test_disable_automatic_add(hass, monkeypatch):
async def test_disable_automatic_add(hass, monkeypatch):
"""If disabled new devices should not be automatically added."""
config = {
'rflink': {
@@ -89,7 +85,7 @@ def test_disable_automatic_add(hass, monkeypatch):
}
# setup mocking rflink module
event_callback, _, _, _ = yield from mock_rflink(
event_callback, _, _, _ = await mock_rflink(
hass, config, DOMAIN, monkeypatch)
# test event for new unconfigured sensor
@@ -99,14 +95,13 @@ def test_disable_automatic_add(hass, monkeypatch):
'value': 0,
'unit': '°C',
})
yield from hass.async_block_till_done()
await hass.async_block_till_done()
# make sure new device is not added
assert not hass.states.get('sensor.test2')
@asyncio.coroutine
def test_entity_availability(hass, monkeypatch):
async def test_entity_availability(hass, monkeypatch):
"""If Rflink device is disconnected, entities should become unavailable."""
# Make sure Rflink mock does not 'recover' to quickly from the
# disconnect or else the unavailability cannot be measured
@@ -115,7 +110,7 @@ def test_entity_availability(hass, monkeypatch):
config[CONF_RECONNECT_INTERVAL] = 60
# Create platform and entities
event_callback, create, _, disconnect_callback = yield from mock_rflink(
_, _, _, disconnect_callback = await mock_rflink(
hass, config, DOMAIN, monkeypatch, failures=failures)
# Entities are available by default
@@ -125,7 +120,7 @@ def test_entity_availability(hass, monkeypatch):
disconnect_callback()
# Wait for dispatch events to propagate
yield from hass.async_block_till_done()
await hass.async_block_till_done()
# Entity should be unavailable
assert hass.states.get('sensor.test').state == 'unavailable'
@@ -134,7 +129,7 @@ def test_entity_availability(hass, monkeypatch):
disconnect_callback()
# Wait for dispatch events to propagate
yield from hass.async_block_till_done()
await hass.async_block_till_done()
# Entities should be available again
assert hass.states.get('sensor.test').state == STATE_UNKNOWN