core/tests/components/wled/__init__.py

59 lines
1.5 KiB
Python
Raw Normal View History

"""Tests for the WLED integration."""
2020-06-03 00:29:49 +00:00
import json
from homeassistant.components.wled.const import DOMAIN
from homeassistant.const import CONF_HOST, CONF_MAC, CONTENT_TYPE_JSON
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, load_fixture
from tests.test_util.aiohttp import AiohttpClientMocker
async def init_integration(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
rgbw: bool = False,
skip_setup: bool = False,
) -> MockConfigEntry:
"""Set up the WLED integration in Home Assistant."""
fixture = "wled/rgb.json" if not rgbw else "wled/rgbw.json"
2020-06-03 00:29:49 +00:00
data = json.loads(load_fixture(fixture))
aioclient_mock.get(
"http://192.168.1.123:80/json/",
2020-06-03 00:29:49 +00:00
json=data,
headers={"Content-Type": CONTENT_TYPE_JSON},
)
aioclient_mock.post(
"http://192.168.1.123:80/json/state",
2020-06-03 00:29:49 +00:00
json=data["state"],
headers={"Content-Type": CONTENT_TYPE_JSON},
)
aioclient_mock.get(
"http://192.168.1.123:80/json/info",
2020-06-03 00:29:49 +00:00
json=data["info"],
headers={"Content-Type": CONTENT_TYPE_JSON},
)
aioclient_mock.get(
"http://192.168.1.123:80/json/state",
2020-06-03 00:29:49 +00:00
json=data["state"],
headers={"Content-Type": CONTENT_TYPE_JSON},
)
entry = MockConfigEntry(
domain=DOMAIN, data={CONF_HOST: "192.168.1.123", CONF_MAC: "aabbccddeeff"}
)
entry.add_to_hass(hass)
if not skip_setup:
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
return entry