* Move setup time logging into the context manager We were fetching the time twice but since the context manager already has the timing, move it there * remove log setup assertions from integration test * tweak logging to give us better data for tracking issues * redundant * adjust * preen * fixes * adjust * make api change internal so nobody uses it * coverage * fix test * fix more tests * coverage * more tests assuming internal calls * fix more * adjust * adjust * fix axis tests * fix broadlink -- it does not call async_forward_entry_setup * missed some * remove useless patch * rename, detect it both ways * clear * debug * try to fix * handle phase finishing out while paused * where its set does not need to know its late as that is an implemenation detail of setup * where its set does not need to know its late as that is an implemenation detail of setup * tweak * simplify * reduce complexity * revert order change as it makes review harder * revert naming changes as it makes review harder * improve comment * improve debug * late dispatch test * test the other way as well * Update setup.py * Update setup.py * Update setup.py * simplify * reduce
88 lines
3 KiB
Python
88 lines
3 KiB
Python
"""Tests for the init module."""
|
|
|
|
from unittest.mock import Mock, patch
|
|
|
|
import pytest
|
|
from pyvesync import VeSync
|
|
|
|
from homeassistant.components.vesync import async_setup_entry
|
|
from homeassistant.components.vesync.const import (
|
|
DOMAIN,
|
|
VS_FANS,
|
|
VS_LIGHTS,
|
|
VS_MANAGER,
|
|
VS_SENSORS,
|
|
VS_SWITCHES,
|
|
)
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import Platform
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
|
async def test_async_setup_entry__not_login(
|
|
hass: HomeAssistant,
|
|
config_entry: ConfigEntry,
|
|
manager: VeSync,
|
|
caplog: pytest.LogCaptureFixture,
|
|
) -> None:
|
|
"""Test setup does not create config entry when not logged in."""
|
|
manager.login = Mock(return_value=False)
|
|
|
|
with patch.object(
|
|
hass.config_entries, "async_forward_entry_setups"
|
|
) as setups_mock, patch(
|
|
"homeassistant.components.vesync.async_process_devices"
|
|
) as process_mock:
|
|
assert not await async_setup_entry(hass, config_entry)
|
|
await hass.async_block_till_done()
|
|
assert setups_mock.call_count == 0
|
|
assert process_mock.call_count == 0
|
|
|
|
assert manager.login.call_count == 1
|
|
assert DOMAIN not in hass.data
|
|
assert "Unable to login to the VeSync server" in caplog.text
|
|
|
|
|
|
async def test_async_setup_entry__no_devices(
|
|
hass: HomeAssistant, config_entry: ConfigEntry, manager: VeSync
|
|
) -> None:
|
|
"""Test setup connects to vesync and creates empty config when no devices."""
|
|
with patch.object(hass.config_entries, "async_forward_entry_setups") as setups_mock:
|
|
assert await async_setup_entry(hass, config_entry)
|
|
# Assert platforms loaded
|
|
await hass.async_block_till_done()
|
|
assert setups_mock.call_count == 1
|
|
assert setups_mock.call_args.args[0] == config_entry
|
|
assert setups_mock.call_args.args[1] == []
|
|
|
|
assert manager.login.call_count == 1
|
|
assert hass.data[DOMAIN][VS_MANAGER] == manager
|
|
assert not hass.data[DOMAIN][VS_SWITCHES]
|
|
assert not hass.data[DOMAIN][VS_FANS]
|
|
assert not hass.data[DOMAIN][VS_LIGHTS]
|
|
assert not hass.data[DOMAIN][VS_SENSORS]
|
|
|
|
|
|
async def test_async_setup_entry__loads_fans(
|
|
hass: HomeAssistant, config_entry: ConfigEntry, manager: VeSync, fan
|
|
) -> None:
|
|
"""Test setup connects to vesync and loads fan platform."""
|
|
fans = [fan]
|
|
manager.fans = fans
|
|
manager._dev_list = {
|
|
"fans": fans,
|
|
}
|
|
|
|
with patch.object(hass.config_entries, "async_forward_entry_setups") as setups_mock:
|
|
assert await async_setup_entry(hass, config_entry)
|
|
# Assert platforms loaded
|
|
await hass.async_block_till_done()
|
|
assert setups_mock.call_count == 1
|
|
assert setups_mock.call_args.args[0] == config_entry
|
|
assert setups_mock.call_args.args[1] == [Platform.FAN, Platform.SENSOR]
|
|
assert manager.login.call_count == 1
|
|
assert hass.data[DOMAIN][VS_MANAGER] == manager
|
|
assert not hass.data[DOMAIN][VS_SWITCHES]
|
|
assert hass.data[DOMAIN][VS_FANS] == [fan]
|
|
assert not hass.data[DOMAIN][VS_LIGHTS]
|
|
assert hass.data[DOMAIN][VS_SENSORS] == [fan]
|