Add diagnostics to VeSync (#86350)
* Add diagnostics to VeSync * Create unit tests for diagnostics and init * Improved diagnostic test coverage * Peer review fixes * Fixed Peer Review comments * Updated based on Peer Review * Additional diagnostic redactions * Removed account_id from diagnostic output
This commit is contained in:
parent
5b49648846
commit
09d0128601
13 changed files with 905 additions and 1 deletions
103
tests/components/vesync/test_init.py
Normal file
103
tests/components/vesync/test_init.py
Normal file
|
@ -0,0 +1,103 @@
|
|||
"""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.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
) as setup_mock, patch(
|
||||
"homeassistant.components.vesync.async_process_devices"
|
||||
) as process_mock, patch.object(
|
||||
hass.services, "async_register"
|
||||
) as register_mock:
|
||||
assert not await async_setup_entry(hass, config_entry)
|
||||
await hass.async_block_till_done()
|
||||
assert setups_mock.call_count == 0
|
||||
assert setup_mock.call_count == 0
|
||||
assert process_mock.call_count == 0
|
||||
assert register_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, patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
) as setup_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 setup_mock.call_count == 0
|
||||
|
||||
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, patch.object(
|
||||
hass.config_entries, "async_forward_entry_setup"
|
||||
) as setup_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 setup_mock.call_count == 0
|
||||
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]
|
Loading…
Add table
Add a link
Reference in a new issue