2016-03-09 09:25:50 +00:00
|
|
|
"""The tests for the Demo component."""
|
2017-07-22 04:38:53 +00:00
|
|
|
import asyncio
|
2015-09-13 15:08:46 +00:00
|
|
|
import json
|
2016-02-14 23:08:23 +00:00
|
|
|
import os
|
2014-11-29 06:49:29 +00:00
|
|
|
|
2017-07-22 04:38:53 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from homeassistant.setup import async_setup_component
|
2016-02-14 23:08:23 +00:00
|
|
|
from homeassistant.components import demo, device_tracker
|
2015-09-13 15:08:46 +00:00
|
|
|
from homeassistant.remote import JSONEncoder
|
2014-11-29 06:49:29 +00:00
|
|
|
|
2017-07-22 04:38:53 +00:00
|
|
|
|
2018-02-26 08:28:25 +00:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def mock_history(hass):
|
|
|
|
"""Mock history component loaded."""
|
|
|
|
hass.config.components.add('history')
|
|
|
|
|
|
|
|
|
2017-07-22 04:38:53 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def minimize_demo_platforms(hass):
|
|
|
|
"""Cleanup demo component for tests."""
|
|
|
|
orig = demo.COMPONENTS_WITH_DEMO_PLATFORM
|
|
|
|
demo.COMPONENTS_WITH_DEMO_PLATFORM = [
|
|
|
|
'switch', 'light', 'media_player']
|
|
|
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
demo.COMPONENTS_WITH_DEMO_PLATFORM = orig
|
2015-07-11 07:02:52 +00:00
|
|
|
|
2014-11-29 06:49:29 +00:00
|
|
|
|
2017-07-22 04:38:53 +00:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def demo_cleanup(hass):
|
|
|
|
"""Clean up device tracker demo file."""
|
|
|
|
yield
|
|
|
|
try:
|
|
|
|
os.remove(hass.config.path(device_tracker.YAML_DEVICES))
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
2014-11-29 06:49:29 +00:00
|
|
|
|
|
|
|
|
2017-07-22 04:38:53 +00:00
|
|
|
@asyncio.coroutine
|
|
|
|
def test_if_demo_state_shows_by_default(hass, minimize_demo_platforms):
|
|
|
|
"""Test if demo state shows if we give no configuration."""
|
|
|
|
yield from async_setup_component(hass, demo.DOMAIN, {demo.DOMAIN: {}})
|
2014-11-29 06:49:29 +00:00
|
|
|
|
2017-07-22 04:38:53 +00:00
|
|
|
assert hass.states.get('a.Demo_Mode') is not None
|
2016-02-14 23:08:23 +00:00
|
|
|
|
2015-03-17 05:20:31 +00:00
|
|
|
|
2017-07-22 04:38:53 +00:00
|
|
|
@asyncio.coroutine
|
|
|
|
def test_hiding_demo_state(hass, minimize_demo_platforms):
|
|
|
|
"""Test if you can hide the demo card."""
|
|
|
|
yield from async_setup_component(hass, demo.DOMAIN, {
|
|
|
|
demo.DOMAIN: {'hide_demo_state': 1}})
|
2015-03-17 05:20:31 +00:00
|
|
|
|
2017-07-22 04:38:53 +00:00
|
|
|
assert hass.states.get('a.Demo_Mode') is None
|
2014-11-29 06:49:29 +00:00
|
|
|
|
2015-09-13 15:08:46 +00:00
|
|
|
|
2017-07-22 04:38:53 +00:00
|
|
|
@asyncio.coroutine
|
|
|
|
def test_all_entities_can_be_loaded_over_json(hass):
|
|
|
|
"""Test if you can hide the demo card."""
|
|
|
|
yield from async_setup_component(hass, demo.DOMAIN, {
|
|
|
|
demo.DOMAIN: {'hide_demo_state': 1}})
|
2015-09-13 15:08:46 +00:00
|
|
|
|
2017-07-22 04:38:53 +00:00
|
|
|
try:
|
|
|
|
json.dumps(hass.states.async_all(), cls=JSONEncoder)
|
|
|
|
except Exception:
|
|
|
|
pytest.fail('Unable to convert all demo entities to JSON. '
|
|
|
|
'Wrong data in state machine!')
|