mirror of https://github.com/home-assistant/core
101 lines
3.2 KiB
Python
101 lines
3.2 KiB
Python
"""Tests of the initialization of the venstar integration."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
from homeassistant.components.venstar.const import DOMAIN as VENSTAR_DOMAIN
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
from homeassistant.const import CONF_HOST, CONF_SSL
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from . import VenstarColorTouchMock
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
TEST_HOST = "venstartest.localdomain"
|
|
|
|
|
|
async def test_setup_entry(hass: HomeAssistant) -> None:
|
|
"""Validate that setup entry also configure the client."""
|
|
config_entry = MockConfigEntry(
|
|
domain=VENSTAR_DOMAIN,
|
|
data={
|
|
CONF_HOST: TEST_HOST,
|
|
CONF_SSL: False,
|
|
},
|
|
)
|
|
config_entry.add_to_hass(hass)
|
|
|
|
with (
|
|
patch(
|
|
"homeassistant.components.venstar.VenstarColorTouch._request",
|
|
new=VenstarColorTouchMock._request,
|
|
),
|
|
patch(
|
|
"homeassistant.components.venstar.VenstarColorTouch.update_sensors",
|
|
new=VenstarColorTouchMock.update_sensors,
|
|
),
|
|
patch(
|
|
"homeassistant.components.venstar.VenstarColorTouch.update_info",
|
|
new=VenstarColorTouchMock.update_info,
|
|
),
|
|
patch(
|
|
"homeassistant.components.venstar.VenstarColorTouch.update_alerts",
|
|
new=VenstarColorTouchMock.update_alerts,
|
|
),
|
|
patch(
|
|
"homeassistant.components.venstar.VenstarColorTouch.get_runtimes",
|
|
new=VenstarColorTouchMock.get_runtimes,
|
|
),
|
|
patch(
|
|
"homeassistant.components.venstar.coordinator.VENSTAR_SLEEP",
|
|
new=0,
|
|
),
|
|
):
|
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert config_entry.state is ConfigEntryState.LOADED
|
|
|
|
await hass.config_entries.async_unload(config_entry.entry_id)
|
|
|
|
assert config_entry.state is ConfigEntryState.NOT_LOADED
|
|
|
|
|
|
async def test_setup_entry_exception(hass: HomeAssistant) -> None:
|
|
"""Validate that setup entry also configure the client."""
|
|
config_entry = MockConfigEntry(
|
|
domain=VENSTAR_DOMAIN,
|
|
data={
|
|
CONF_HOST: TEST_HOST,
|
|
CONF_SSL: False,
|
|
},
|
|
)
|
|
config_entry.add_to_hass(hass)
|
|
|
|
with (
|
|
patch(
|
|
"homeassistant.components.venstar.VenstarColorTouch._request",
|
|
new=VenstarColorTouchMock._request,
|
|
),
|
|
patch(
|
|
"homeassistant.components.venstar.VenstarColorTouch.update_sensors",
|
|
new=VenstarColorTouchMock.update_sensors,
|
|
),
|
|
patch(
|
|
"homeassistant.components.venstar.VenstarColorTouch.update_info",
|
|
new=VenstarColorTouchMock.broken_update_info,
|
|
),
|
|
patch(
|
|
"homeassistant.components.venstar.VenstarColorTouch.update_alerts",
|
|
new=VenstarColorTouchMock.update_alerts,
|
|
),
|
|
patch(
|
|
"homeassistant.components.venstar.VenstarColorTouch.get_runtimes",
|
|
new=VenstarColorTouchMock.get_runtimes,
|
|
),
|
|
):
|
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|