2016-03-09 10:25:50 +01:00
|
|
|
"""The tests for the Demo component."""
|
2024-03-08 19:16:21 +01:00
|
|
|
|
2015-09-13 08:08:46 -07:00
|
|
|
import json
|
2023-01-10 17:31:47 +01:00
|
|
|
from unittest.mock import patch
|
2014-11-28 22:49:29 -08:00
|
|
|
|
2017-07-21 21:38:53 -07:00
|
|
|
import pytest
|
|
|
|
|
2020-04-10 00:40:51 +02:00
|
|
|
from homeassistant.components.demo import DOMAIN
|
2023-02-11 08:26:13 +01:00
|
|
|
from homeassistant.core import HomeAssistant
|
2018-08-21 15:49:58 +02:00
|
|
|
from homeassistant.helpers.json import JSONEncoder
|
2022-03-21 23:49:18 +01:00
|
|
|
from homeassistant.setup import async_setup_component
|
2014-11-28 22:49:29 -08:00
|
|
|
|
2017-07-21 21:38:53 -07:00
|
|
|
|
2022-10-19 07:58:47 +02:00
|
|
|
@pytest.fixture
|
2018-02-26 00:28:25 -08:00
|
|
|
def mock_history(hass):
|
|
|
|
"""Mock history component loaded."""
|
|
|
|
hass.config.components.add("history")
|
|
|
|
|
|
|
|
|
2017-07-21 21:38:53 -07:00
|
|
|
@pytest.fixture(autouse=True)
|
2022-10-19 07:58:47 +02:00
|
|
|
def mock_device_tracker_update_config():
|
2022-07-02 21:20:40 +03:00
|
|
|
"""Prevent device tracker from creating known devices file."""
|
|
|
|
with patch("homeassistant.components.device_tracker.legacy.update_config"):
|
|
|
|
yield
|
2014-11-28 22:49:29 -08:00
|
|
|
|
|
|
|
|
2023-02-11 08:26:13 +01:00
|
|
|
async def test_setting_up_demo(mock_history, hass: HomeAssistant) -> None:
|
2019-04-14 16:59:06 -07:00
|
|
|
"""Test if we can set up the demo and dump it to JSON."""
|
2020-04-10 00:40:51 +02:00
|
|
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
2020-04-13 00:10:05 +03:00
|
|
|
await hass.async_block_till_done()
|
2019-04-14 16:59:06 -07:00
|
|
|
await hass.async_start()
|
2015-09-13 08:08:46 -07:00
|
|
|
|
2019-04-14 16:59:06 -07:00
|
|
|
# This is done to make sure entity components don't accidentally store
|
|
|
|
# non-JSON-serializable data in the state machine.
|
2017-07-21 21:38:53 -07:00
|
|
|
try:
|
|
|
|
json.dumps(hass.states.async_all(), cls=JSONEncoder)
|
2024-05-07 14:00:27 +02:00
|
|
|
except Exception: # noqa: BLE001
|
2017-07-21 21:38:53 -07:00
|
|
|
pytest.fail(
|
2023-01-20 13:52:46 +01:00
|
|
|
"Unable to convert all demo entities to JSON. Wrong data in state machine!"
|
2017-07-21 21:38:53 -07:00
|
|
|
)
|