2019-11-06 22:55:39 +00:00
|
|
|
"""Tests for the WLED integration."""
|
|
|
|
|
2020-06-03 00:29:49 +00:00
|
|
|
import json
|
|
|
|
|
2019-11-06 22:55:39 +00:00
|
|
|
from homeassistant.components.wled.const import DOMAIN
|
|
|
|
from homeassistant.const import CONF_HOST, CONF_MAC
|
|
|
|
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))
|
|
|
|
|
2019-11-06 22:55:39 +00:00
|
|
|
aioclient_mock.get(
|
2020-04-04 05:41:08 +00:00
|
|
|
"http://192.168.1.123:80/json/",
|
2020-06-03 00:29:49 +00:00
|
|
|
json=data,
|
2019-11-06 22:55:39 +00:00
|
|
|
headers={"Content-Type": "application/json"},
|
|
|
|
)
|
|
|
|
|
|
|
|
aioclient_mock.post(
|
2020-04-04 05:41:08 +00:00
|
|
|
"http://192.168.1.123:80/json/state",
|
2020-06-03 00:29:49 +00:00
|
|
|
json=data["state"],
|
2020-03-17 19:17:59 +00:00
|
|
|
headers={"Content-Type": "application/json"},
|
|
|
|
)
|
|
|
|
|
|
|
|
aioclient_mock.get(
|
2020-04-04 05:41:08 +00:00
|
|
|
"http://192.168.1.123:80/json/info",
|
2020-06-03 00:29:49 +00:00
|
|
|
json=data["info"],
|
2020-03-17 19:17:59 +00:00
|
|
|
headers={"Content-Type": "application/json"},
|
|
|
|
)
|
|
|
|
|
|
|
|
aioclient_mock.get(
|
2020-04-04 05:41:08 +00:00
|
|
|
"http://192.168.1.123:80/json/state",
|
2020-06-03 00:29:49 +00:00
|
|
|
json=data["state"],
|
2019-11-06 22:55:39 +00:00
|
|
|
headers={"Content-Type": "application/json"},
|
|
|
|
)
|
|
|
|
|
|
|
|
entry = MockConfigEntry(
|
2020-04-04 05:41:08 +00:00
|
|
|
domain=DOMAIN, data={CONF_HOST: "192.168.1.123", CONF_MAC: "aabbccddeeff"}
|
2019-11-06 22:55:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|