Add sensor to show how many clients are connected. (#4430)

* Add sensor to show how many clients are connected.

* Lint

* Fix tests
This commit is contained in:
Paulus Schoutsen 2016-11-17 21:54:47 -08:00 committed by GitHub
parent 23fb8c4cdd
commit af77341494
2 changed files with 100 additions and 0 deletions

View file

@ -0,0 +1,39 @@
import asyncio
import logging
from homeassistant.bootstrap import async_setup_component
from tests.common import assert_setup_component
@asyncio.coroutine
def test_api_streams(hass):
"""Test API streams."""
log = logging.getLogger('homeassistant.components.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('STREAM 1 ATTACHED')
yield from hass.async_block_till_done()
state = hass.states.get('sensor.connected_clients')
assert state.state == '1'
log.debug('STREAM 1 ATTACHED')
yield from hass.async_block_till_done()
state = hass.states.get('sensor.connected_clients')
assert state.state == '2'
log.debug('STREAM 1 RESPONSE CLOSED')
yield from hass.async_block_till_done()
state = hass.states.get('sensor.connected_clients')
assert state.state == '1'