Have api_streams sensor also monitor websocket connections (#4668)

This commit is contained in:
Paulus Schoutsen 2016-12-02 18:17:46 -08:00 committed by GitHub
parent 84c89686a9
commit 4874030b70
2 changed files with 68 additions and 8 deletions

View file

@ -37,3 +37,37 @@ def test_api_streams(hass):
state = hass.states.get('sensor.connected_clients')
assert state.state == '1'
@asyncio.coroutine
def test_websocket_api(hass):
"""Test API streams."""
log = logging.getLogger('homeassistant.components.websocket_api')
with assert_setup_component(1):
yield from async_setup_component(hass, 'sensor', {
'sensor': {
'platform': 'api_streams',
}
})
state = hass.states.get('sensor.connected_clients')
assert state.state == '0'
log.debug('WS %s: %s', id(log), 'Connected')
yield from hass.async_block_till_done()
state = hass.states.get('sensor.connected_clients')
assert state.state == '1'
log.debug('WS %s: %s', id(log), 'Connected')
yield from hass.async_block_till_done()
state = hass.states.get('sensor.connected_clients')
assert state.state == '2'
log.debug('WS %s: %s', id(log), 'Closed connection')
yield from hass.async_block_till_done()
state = hass.states.get('sensor.connected_clients')
assert state.state == '1'