Add availability to Rflink entities. (#14977)
This commit is contained in:
1 parent
4bd7a7eee3
commit
2ec295a6f8
2 files changed
+70
-1
No files matched your search
@@ -8,6 +8,9 @@ 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
|
||||
|
||||
DOMAIN = 'sensor'
|
||||
|
||||
@@ -32,7 +35,7 @@ CONFIG = {
|
||||
def test_default_setup(hass, monkeypatch):
|
||||
"""Test all basic functionality of the rflink sensor component."""
|
||||
# setup mocking rflink module
|
||||
event_callback, create, _, _ = yield from mock_rflink(
|
||||
event_callback, create, _, disconnect_callback = yield from mock_rflink(
|
||||
hass, CONFIG, DOMAIN, monkeypatch)
|
||||
|
||||
# make sure arguments are passed
|
||||
@@ -100,3 +103,38 @@ def test_disable_automatic_add(hass, monkeypatch):
|
||||
|
||||
# make sure new device is not added
|
||||
assert not hass.states.get('sensor.test2')
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
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
|
||||
config = CONFIG
|
||||
failures = [True, True]
|
||||
config[CONF_RECONNECT_INTERVAL] = 60
|
||||
|
||||
# Create platform and entities
|
||||
event_callback, create, _, disconnect_callback = yield from mock_rflink(
|
||||
hass, config, DOMAIN, monkeypatch, failures=failures)
|
||||
|
||||
# Entities are available by default
|
||||
assert hass.states.get('sensor.test').state == STATE_UNKNOWN
|
||||
|
||||
# Mock a disconnect of the Rflink device
|
||||
disconnect_callback()
|
||||
|
||||
# Wait for dispatch events to propagate
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
# Entity should be unavailable
|
||||
assert hass.states.get('sensor.test').state == 'unavailable'
|
||||
|
||||
# Reconnect the Rflink device
|
||||
disconnect_callback()
|
||||
|
||||
# Wait for dispatch events to propagate
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
# Entities should be available again
|
||||
assert hass.states.get('sensor.test').state == STATE_UNKNOWN
|
||||
Reference in new issue
Block a user