Add type hints to integration tests (h-i) (#87703)
This commit is contained in:
parent
807c69f621
commit
37a2040d7b
91 changed files with 674 additions and 425 deletions
|
@ -5,11 +5,12 @@ from aiohttp import ClientResponseError
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.habitica.const import DEFAULT_URL, DOMAIN
|
from homeassistant.components.habitica.const import DEFAULT_URL, DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_form(hass):
|
async def test_form(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -47,7 +48,7 @@ async def test_form(hass):
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_form_invalid_credentials(hass):
|
async def test_form_invalid_credentials(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle invalid credentials error."""
|
"""Test we handle invalid credentials error."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -73,7 +74,7 @@ async def test_form_invalid_credentials(hass):
|
||||||
assert result2["errors"] == {"base": "invalid_credentials"}
|
assert result2["errors"] == {"base": "invalid_credentials"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_unexpected_exception(hass):
|
async def test_form_unexpected_exception(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle unexpected exception error."""
|
"""Test we handle unexpected exception error."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -99,7 +100,7 @@ async def test_form_unexpected_exception(hass):
|
||||||
assert result2["errors"] == {"base": "unknown"}
|
assert result2["errors"] == {"base": "unknown"}
|
||||||
|
|
||||||
|
|
||||||
async def test_manual_flow_config_exist(hass):
|
async def test_manual_flow_config_exist(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow discovers only already configured config."""
|
"""Test config flow discovers only already configured config."""
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
|
|
@ -8,6 +8,7 @@ from homeassistant.components import ssdp
|
||||||
from homeassistant.components.harmony.config_flow import CannotConnect
|
from homeassistant.components.harmony.config_flow import CannotConnect
|
||||||
from homeassistant.components.harmony.const import DOMAIN, PREVIOUS_ACTIVE_ACTIVITY
|
from homeassistant.components.harmony.const import DOMAIN, PREVIOUS_ACTIVE_ACTIVITY
|
||||||
from homeassistant.const import CONF_HOST, CONF_NAME
|
from homeassistant.const import CONF_HOST, CONF_NAME
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ def _get_mock_harmonyapi(connect=None, close=None):
|
||||||
return harmonyapi_mock
|
return harmonyapi_mock
|
||||||
|
|
||||||
|
|
||||||
async def test_user_form(hass):
|
async def test_user_form(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the user form."""
|
"""Test we get the user form."""
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -49,7 +50,7 @@ async def test_user_form(hass):
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_form_ssdp(hass):
|
async def test_form_ssdp(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the form with ssdp source."""
|
"""Test we get the form with ssdp source."""
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -101,7 +102,7 @@ async def test_form_ssdp(hass):
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_form_ssdp_fails_to_get_remote_id(hass):
|
async def test_form_ssdp_fails_to_get_remote_id(hass: HomeAssistant) -> None:
|
||||||
"""Test we abort if we cannot get the remote id."""
|
"""Test we abort if we cannot get the remote id."""
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -124,7 +125,9 @@ async def test_form_ssdp_fails_to_get_remote_id(hass):
|
||||||
assert result["reason"] == "cannot_connect"
|
assert result["reason"] == "cannot_connect"
|
||||||
|
|
||||||
|
|
||||||
async def test_form_ssdp_aborts_before_checking_remoteid_if_host_known(hass):
|
async def test_form_ssdp_aborts_before_checking_remoteid_if_host_known(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
) -> None:
|
||||||
"""Test we abort without connecting if the host is already known."""
|
"""Test we abort without connecting if the host is already known."""
|
||||||
|
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
|
@ -160,7 +163,7 @@ async def test_form_ssdp_aborts_before_checking_remoteid_if_host_known(hass):
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == "abort"
|
||||||
|
|
||||||
|
|
||||||
async def test_form_cannot_connect(hass):
|
async def test_form_cannot_connect(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle cannot connect error."""
|
"""Test we handle cannot connect error."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""Test the HarmonySubscriberMixin class."""
|
"""Test the HarmonySubscriberMixin class."""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from unittest.mock import AsyncMock, MagicMock
|
from unittest.mock import AsyncMock, MagicMock
|
||||||
|
|
||||||
|
@ -7,6 +6,7 @@ from homeassistant.components.harmony.subscriber import (
|
||||||
HarmonyCallback,
|
HarmonyCallback,
|
||||||
HarmonySubscriberMixin,
|
HarmonySubscriberMixin,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
_NO_PARAM_CALLBACKS = {
|
_NO_PARAM_CALLBACKS = {
|
||||||
"connected": "_connected",
|
"connected": "_connected",
|
||||||
|
@ -26,14 +26,14 @@ _ALL_CALLBACK_NAMES = list(_NO_PARAM_CALLBACKS.keys()) + list(
|
||||||
_ACTIVITY_TUPLE = ("not", "used")
|
_ACTIVITY_TUPLE = ("not", "used")
|
||||||
|
|
||||||
|
|
||||||
async def test_no_callbacks(hass):
|
async def test_no_callbacks(hass: HomeAssistant) -> None:
|
||||||
"""Ensure we handle no subscriptions."""
|
"""Ensure we handle no subscriptions."""
|
||||||
subscriber = HarmonySubscriberMixin(hass)
|
subscriber = HarmonySubscriberMixin(hass)
|
||||||
_call_all_callbacks(subscriber)
|
_call_all_callbacks(subscriber)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
async def test_empty_callbacks(hass):
|
async def test_empty_callbacks(hass: HomeAssistant) -> None:
|
||||||
"""Ensure we handle a missing callback in a subscription."""
|
"""Ensure we handle a missing callback in a subscription."""
|
||||||
subscriber = HarmonySubscriberMixin(hass)
|
subscriber = HarmonySubscriberMixin(hass)
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ async def test_empty_callbacks(hass):
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
async def test_async_callbacks(hass):
|
async def test_async_callbacks(hass: HomeAssistant) -> None:
|
||||||
"""Ensure we handle async callbacks."""
|
"""Ensure we handle async callbacks."""
|
||||||
subscriber = HarmonySubscriberMixin(hass)
|
subscriber = HarmonySubscriberMixin(hass)
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ async def test_async_callbacks(hass):
|
||||||
callback_mock.assert_awaited_once_with(_ACTIVITY_TUPLE)
|
callback_mock.assert_awaited_once_with(_ACTIVITY_TUPLE)
|
||||||
|
|
||||||
|
|
||||||
async def test_long_async_callbacks(hass):
|
async def test_long_async_callbacks(hass: HomeAssistant) -> None:
|
||||||
"""Ensure we handle async callbacks that may have sleeps."""
|
"""Ensure we handle async callbacks that may have sleeps."""
|
||||||
subscriber = HarmonySubscriberMixin(hass)
|
subscriber = HarmonySubscriberMixin(hass)
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ async def test_long_async_callbacks(hass):
|
||||||
await notifier_event_one.wait()
|
await notifier_event_one.wait()
|
||||||
|
|
||||||
|
|
||||||
async def test_callbacks(hass):
|
async def test_callbacks(hass: HomeAssistant) -> None:
|
||||||
"""Ensure we handle non-async callbacks."""
|
"""Ensure we handle non-async callbacks."""
|
||||||
subscriber = HarmonySubscriberMixin(hass)
|
subscriber = HarmonySubscriberMixin(hass)
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ async def test_callbacks(hass):
|
||||||
callback_mock.assert_called_once_with(_ACTIVITY_TUPLE)
|
callback_mock.assert_called_once_with(_ACTIVITY_TUPLE)
|
||||||
|
|
||||||
|
|
||||||
async def test_subscribe_unsubscribe(hass):
|
async def test_subscribe_unsubscribe(hass: HomeAssistant) -> None:
|
||||||
"""Ensure we handle subscriptions and unsubscriptions correctly."""
|
"""Ensure we handle subscriptions and unsubscriptions correctly."""
|
||||||
subscriber = HarmonySubscriberMixin(hass)
|
subscriber = HarmonySubscriberMixin(hass)
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.components.hassio import DOMAIN
|
from homeassistant.components.hassio import DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
|
||||||
async def test_config_flow(hass):
|
async def test_config_flow(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -25,7 +26,7 @@ async def test_config_flow(hass):
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_multiple_entries(hass):
|
async def test_multiple_entries(hass: HomeAssistant) -> None:
|
||||||
"""Test creating multiple hassio entries."""
|
"""Test creating multiple hassio entries."""
|
||||||
await test_config_flow(hass)
|
await test_config_flow(hass)
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
|
|
@ -16,11 +16,13 @@ from homeassistant.components.hassio import (
|
||||||
)
|
)
|
||||||
from homeassistant.components.hassio.handler import HassioAPIError
|
from homeassistant.components.hassio.handler import HassioAPIError
|
||||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import async_get
|
from homeassistant.helpers.device_registry import async_get
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||||
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"}
|
MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"}
|
||||||
|
|
||||||
|
@ -198,7 +200,9 @@ def mock_all(aioclient_mock, request, os_info):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_api_ping(hass, aioclient_mock):
|
async def test_setup_api_ping(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test setup with API ping."""
|
"""Test setup with API ping."""
|
||||||
with patch.dict(os.environ, MOCK_ENVIRON):
|
with patch.dict(os.environ, MOCK_ENVIRON):
|
||||||
result = await async_setup_component(hass, "hassio", {})
|
result = await async_setup_component(hass, "hassio", {})
|
||||||
|
@ -210,7 +214,9 @@ async def test_setup_api_ping(hass, aioclient_mock):
|
||||||
assert hass.components.hassio.is_hassio()
|
assert hass.components.hassio.is_hassio()
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_api_panel(hass, aioclient_mock):
|
async def test_setup_api_panel(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test setup with API ping."""
|
"""Test setup with API ping."""
|
||||||
assert await async_setup_component(hass, "frontend", {})
|
assert await async_setup_component(hass, "frontend", {})
|
||||||
with patch.dict(os.environ, MOCK_ENVIRON):
|
with patch.dict(os.environ, MOCK_ENVIRON):
|
||||||
|
@ -236,7 +242,9 @@ async def test_setup_api_panel(hass, aioclient_mock):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_api_push_api_data(hass, aioclient_mock):
|
async def test_setup_api_push_api_data(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test setup with API push."""
|
"""Test setup with API push."""
|
||||||
with patch.dict(os.environ, MOCK_ENVIRON):
|
with patch.dict(os.environ, MOCK_ENVIRON):
|
||||||
result = await async_setup_component(
|
result = await async_setup_component(
|
||||||
|
@ -251,7 +259,9 @@ async def test_setup_api_push_api_data(hass, aioclient_mock):
|
||||||
assert aioclient_mock.mock_calls[1][2]["watchdog"]
|
assert aioclient_mock.mock_calls[1][2]["watchdog"]
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_api_push_api_data_server_host(hass, aioclient_mock):
|
async def test_setup_api_push_api_data_server_host(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test setup with API push with active server host."""
|
"""Test setup with API push with active server host."""
|
||||||
with patch.dict(os.environ, MOCK_ENVIRON):
|
with patch.dict(os.environ, MOCK_ENVIRON):
|
||||||
result = await async_setup_component(
|
result = await async_setup_component(
|
||||||
|
@ -349,7 +359,9 @@ async def test_setup_api_existing_hassio_user(hass, aioclient_mock, hass_storage
|
||||||
assert aioclient_mock.mock_calls[1][2]["refresh_token"] == token.token
|
assert aioclient_mock.mock_calls[1][2]["refresh_token"] == token.token
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_core_push_timezone(hass, aioclient_mock):
|
async def test_setup_core_push_timezone(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test setup with API push default data."""
|
"""Test setup with API push default data."""
|
||||||
hass.config.time_zone = "testzone"
|
hass.config.time_zone = "testzone"
|
||||||
|
|
||||||
|
@ -367,7 +379,9 @@ async def test_setup_core_push_timezone(hass, aioclient_mock):
|
||||||
assert aioclient_mock.mock_calls[-1][2]["timezone"] == "America/New_York"
|
assert aioclient_mock.mock_calls[-1][2]["timezone"] == "America/New_York"
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_hassio_no_additional_data(hass, aioclient_mock):
|
async def test_setup_hassio_no_additional_data(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test setup with API push default data."""
|
"""Test setup with API push default data."""
|
||||||
with patch.dict(os.environ, MOCK_ENVIRON), patch.dict(
|
with patch.dict(os.environ, MOCK_ENVIRON), patch.dict(
|
||||||
os.environ, {"SUPERVISOR_TOKEN": "123456"}
|
os.environ, {"SUPERVISOR_TOKEN": "123456"}
|
||||||
|
@ -380,14 +394,16 @@ async def test_setup_hassio_no_additional_data(hass, aioclient_mock):
|
||||||
assert aioclient_mock.mock_calls[-1][3]["Authorization"] == "Bearer 123456"
|
assert aioclient_mock.mock_calls[-1][3]["Authorization"] == "Bearer 123456"
|
||||||
|
|
||||||
|
|
||||||
async def test_fail_setup_without_environ_var(hass):
|
async def test_fail_setup_without_environ_var(hass: HomeAssistant) -> None:
|
||||||
"""Fail setup if no environ variable set."""
|
"""Fail setup if no environ variable set."""
|
||||||
with patch.dict(os.environ, {}, clear=True):
|
with patch.dict(os.environ, {}, clear=True):
|
||||||
result = await async_setup_component(hass, "hassio", {})
|
result = await async_setup_component(hass, "hassio", {})
|
||||||
assert not result
|
assert not result
|
||||||
|
|
||||||
|
|
||||||
async def test_warn_when_cannot_connect(hass, caplog):
|
async def test_warn_when_cannot_connect(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Fail warn when we cannot connect."""
|
"""Fail warn when we cannot connect."""
|
||||||
with patch.dict(os.environ, MOCK_ENVIRON), patch(
|
with patch.dict(os.environ, MOCK_ENVIRON), patch(
|
||||||
"homeassistant.components.hassio.HassIO.is_connected",
|
"homeassistant.components.hassio.HassIO.is_connected",
|
||||||
|
@ -528,7 +544,7 @@ async def test_service_calls_core(hassio_env, hass, aioclient_mock):
|
||||||
assert aioclient_mock.call_count == 7
|
assert aioclient_mock.call_count == 7
|
||||||
|
|
||||||
|
|
||||||
async def test_entry_load_and_unload(hass):
|
async def test_entry_load_and_unload(hass: HomeAssistant) -> None:
|
||||||
"""Test loading and unloading config entry."""
|
"""Test loading and unloading config entry."""
|
||||||
with patch.dict(os.environ, MOCK_ENVIRON):
|
with patch.dict(os.environ, MOCK_ENVIRON):
|
||||||
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
||||||
|
@ -545,7 +561,7 @@ async def test_entry_load_and_unload(hass):
|
||||||
assert ADDONS_COORDINATOR not in hass.data
|
assert ADDONS_COORDINATOR not in hass.data
|
||||||
|
|
||||||
|
|
||||||
async def test_migration_off_hassio(hass):
|
async def test_migration_off_hassio(hass: HomeAssistant) -> None:
|
||||||
"""Test that when a user moves instance off Hass.io, config entry gets cleaned up."""
|
"""Test that when a user moves instance off Hass.io, config entry gets cleaned up."""
|
||||||
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -554,7 +570,7 @@ async def test_migration_off_hassio(hass):
|
||||||
assert hass.config_entries.async_entries(DOMAIN) == []
|
assert hass.config_entries.async_entries(DOMAIN) == []
|
||||||
|
|
||||||
|
|
||||||
async def test_device_registry_calls(hass):
|
async def test_device_registry_calls(hass: HomeAssistant) -> None:
|
||||||
"""Test device registry entries for hassio."""
|
"""Test device registry entries for hassio."""
|
||||||
dev_reg = async_get(hass)
|
dev_reg = async_get(hass)
|
||||||
supervisor_mock_data = {
|
supervisor_mock_data = {
|
||||||
|
@ -694,7 +710,9 @@ async def test_device_registry_calls(hass):
|
||||||
assert len(dev_reg.devices) == 4
|
assert len(dev_reg.devices) == 4
|
||||||
|
|
||||||
|
|
||||||
async def test_coordinator_updates(hass, caplog):
|
async def test_coordinator_updates(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test coordinator updates."""
|
"""Test coordinator updates."""
|
||||||
await async_setup_component(hass, "homeassistant", {})
|
await async_setup_component(hass, "homeassistant", {})
|
||||||
with patch.dict(os.environ, MOCK_ENVIRON), patch(
|
with patch.dict(os.environ, MOCK_ENVIRON), patch(
|
||||||
|
|
|
@ -5,14 +5,18 @@ from unittest.mock import patch
|
||||||
|
|
||||||
from aiohttp import ClientError
|
from aiohttp import ClientError
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .test_init import MOCK_ENVIRON
|
from .test_init import MOCK_ENVIRON
|
||||||
|
|
||||||
from tests.common import get_system_health_info
|
from tests.common import get_system_health_info
|
||||||
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
|
|
||||||
async def test_hassio_system_health(hass, aioclient_mock):
|
async def test_hassio_system_health(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test hassio system health."""
|
"""Test hassio system health."""
|
||||||
aioclient_mock.get("http://127.0.0.1/info", json={"result": "ok", "data": {}})
|
aioclient_mock.get("http://127.0.0.1/info", json={"result": "ok", "data": {}})
|
||||||
aioclient_mock.get("http://127.0.0.1/host/info", json={"result": "ok", "data": {}})
|
aioclient_mock.get("http://127.0.0.1/host/info", json={"result": "ok", "data": {}})
|
||||||
|
@ -69,7 +73,9 @@ async def test_hassio_system_health(hass, aioclient_mock):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_hassio_system_health_with_issues(hass, aioclient_mock):
|
async def test_hassio_system_health_with_issues(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test hassio system health."""
|
"""Test hassio system health."""
|
||||||
aioclient_mock.get("http://127.0.0.1/info", json={"result": "ok", "data": {}})
|
aioclient_mock.get("http://127.0.0.1/info", json={"result": "ok", "data": {}})
|
||||||
aioclient_mock.get("http://127.0.0.1/host/info", json={"result": "ok", "data": {}})
|
aioclient_mock.get("http://127.0.0.1/host/info", json={"result": "ok", "data": {}})
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The tests for the hassio update entities."""
|
"""The tests for the hassio update entities."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
@ -7,10 +6,12 @@ import pytest
|
||||||
|
|
||||||
from homeassistant.components.hassio import DOMAIN
|
from homeassistant.components.hassio import DOMAIN
|
||||||
from homeassistant.components.hassio.handler import HassioAPIError
|
from homeassistant.components.hassio.handler import HassioAPIError
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"}
|
MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"}
|
||||||
|
|
||||||
|
@ -192,7 +193,9 @@ async def test_update_entities(
|
||||||
assert state.attributes["auto_update"] is auto_update
|
assert state.attributes["auto_update"] is auto_update
|
||||||
|
|
||||||
|
|
||||||
async def test_update_addon(hass, aioclient_mock):
|
async def test_update_addon(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test updating addon update entity."""
|
"""Test updating addon update entity."""
|
||||||
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -219,7 +222,9 @@ async def test_update_addon(hass, aioclient_mock):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_update_os(hass, aioclient_mock):
|
async def test_update_os(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test updating OS update entity."""
|
"""Test updating OS update entity."""
|
||||||
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -246,7 +251,9 @@ async def test_update_os(hass, aioclient_mock):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_update_core(hass, aioclient_mock):
|
async def test_update_core(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test updating core update entity."""
|
"""Test updating core update entity."""
|
||||||
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -273,7 +280,9 @@ async def test_update_core(hass, aioclient_mock):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_update_supervisor(hass, aioclient_mock):
|
async def test_update_supervisor(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test updating supervisor update entity."""
|
"""Test updating supervisor update entity."""
|
||||||
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -300,7 +309,9 @@ async def test_update_supervisor(hass, aioclient_mock):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_update_addon_with_error(hass, aioclient_mock):
|
async def test_update_addon_with_error(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test updating addon update entity with error."""
|
"""Test updating addon update entity with error."""
|
||||||
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -327,7 +338,9 @@ async def test_update_addon_with_error(hass, aioclient_mock):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_update_os_with_error(hass, aioclient_mock):
|
async def test_update_os_with_error(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test updating OS update entity with error."""
|
"""Test updating OS update entity with error."""
|
||||||
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -354,7 +367,9 @@ async def test_update_os_with_error(hass, aioclient_mock):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_update_supervisor_with_error(hass, aioclient_mock):
|
async def test_update_supervisor_with_error(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test updating supervisor update entity with error."""
|
"""Test updating supervisor update entity with error."""
|
||||||
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -381,7 +396,9 @@ async def test_update_supervisor_with_error(hass, aioclient_mock):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_update_core_with_error(hass, aioclient_mock):
|
async def test_update_core_with_error(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test updating core update entity with error."""
|
"""Test updating core update entity with error."""
|
||||||
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=DOMAIN)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -503,7 +520,7 @@ async def test_not_release_notes(hass, aioclient_mock, hass_ws_client):
|
||||||
assert result["result"] is None
|
assert result["result"] is None
|
||||||
|
|
||||||
|
|
||||||
async def test_no_os_entity(hass):
|
async def test_no_os_entity(hass: HomeAssistant) -> None:
|
||||||
"""Test handling where there is no os entity."""
|
"""Test handling where there is no os entity."""
|
||||||
with patch.dict(os.environ, MOCK_ENVIRON), patch(
|
with patch.dict(os.environ, MOCK_ENVIRON), patch(
|
||||||
"homeassistant.components.hassio.HassIO.get_info",
|
"homeassistant.components.hassio.HassIO.get_info",
|
||||||
|
@ -525,7 +542,9 @@ async def test_no_os_entity(hass):
|
||||||
assert not hass.states.get("update.home_assistant_operating_system_update")
|
assert not hass.states.get("update.home_assistant_operating_system_update")
|
||||||
|
|
||||||
|
|
||||||
async def test_setting_up_core_update_when_addon_fails(hass, caplog):
|
async def test_setting_up_core_update_when_addon_fails(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test setting up core update when single addon fails."""
|
"""Test setting up core update when single addon fails."""
|
||||||
with patch.dict(os.environ, MOCK_ENVIRON), patch(
|
with patch.dict(os.environ, MOCK_ENVIRON), patch(
|
||||||
"homeassistant.components.hassio.HassIO.get_addon_stats",
|
"homeassistant.components.hassio.HassIO.get_addon_stats",
|
||||||
|
|
|
@ -10,6 +10,7 @@ from homeassistant.components.heos.config_flow import HeosFlowHandler
|
||||||
from homeassistant.components.heos.const import DATA_DISCOVERED_HOSTS, DOMAIN
|
from homeassistant.components.heos.const import DATA_DISCOVERED_HOSTS, DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_SSDP, SOURCE_USER
|
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_SSDP, SOURCE_USER
|
||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_aborts_already_setup(hass, config_entry):
|
async def test_flow_aborts_already_setup(hass, config_entry):
|
||||||
|
@ -22,7 +23,7 @@ async def test_flow_aborts_already_setup(hass, config_entry):
|
||||||
assert result["reason"] == "single_instance_allowed"
|
assert result["reason"] == "single_instance_allowed"
|
||||||
|
|
||||||
|
|
||||||
async def test_no_host_shows_form(hass):
|
async def test_no_host_shows_form(hass: HomeAssistant) -> None:
|
||||||
"""Test form is shown when host not provided."""
|
"""Test form is shown when host not provided."""
|
||||||
flow = HeosFlowHandler()
|
flow = HeosFlowHandler()
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
|
|
@ -471,7 +471,7 @@ async def test_route_not_found(hass: HomeAssistant, caplog):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("valid_response")
|
@pytest.mark.usefixtures("valid_response")
|
||||||
async def test_restore_state(hass):
|
async def test_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Test sensor restore state."""
|
"""Test sensor restore state."""
|
||||||
# Home assistant is not running yet
|
# Home assistant is not running yet
|
||||||
hass.state = CoreState.not_running
|
hass.state = CoreState.not_running
|
||||||
|
|
|
@ -5,10 +5,11 @@ from pyaehw4a1 import exceptions
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow
|
from homeassistant import config_entries, data_entry_flow
|
||||||
from homeassistant.components import hisense_aehw4a1
|
from homeassistant.components import hisense_aehw4a1
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
|
||||||
async def test_creating_entry_sets_up_climate_discovery(hass):
|
async def test_creating_entry_sets_up_climate_discovery(hass: HomeAssistant) -> None:
|
||||||
"""Test setting up Hisense AEH-W4A1 loads the climate component."""
|
"""Test setting up Hisense AEH-W4A1 loads the climate component."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.hisense_aehw4a1.config_flow.AehW4a1.discovery",
|
"homeassistant.components.hisense_aehw4a1.config_flow.AehW4a1.discovery",
|
||||||
|
@ -32,7 +33,7 @@ async def test_creating_entry_sets_up_climate_discovery(hass):
|
||||||
assert len(mock_setup.mock_calls) == 1
|
assert len(mock_setup.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_configuring_hisense_w4a1_create_entry(hass):
|
async def test_configuring_hisense_w4a1_create_entry(hass: HomeAssistant) -> None:
|
||||||
"""Test that specifying config will create an entry."""
|
"""Test that specifying config will create an entry."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.hisense_aehw4a1.config_flow.AehW4a1.check",
|
"homeassistant.components.hisense_aehw4a1.config_flow.AehW4a1.check",
|
||||||
|
@ -51,7 +52,9 @@ async def test_configuring_hisense_w4a1_create_entry(hass):
|
||||||
assert len(mock_setup.mock_calls) == 1
|
assert len(mock_setup.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_configuring_hisense_w4a1_not_creates_entry_for_device_not_found(hass):
|
async def test_configuring_hisense_w4a1_not_creates_entry_for_device_not_found(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
) -> None:
|
||||||
"""Test that specifying config will not create an entry."""
|
"""Test that specifying config will not create an entry."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.hisense_aehw4a1.config_flow.AehW4a1.check",
|
"homeassistant.components.hisense_aehw4a1.config_flow.AehW4a1.check",
|
||||||
|
@ -70,7 +73,9 @@ async def test_configuring_hisense_w4a1_not_creates_entry_for_device_not_found(h
|
||||||
assert len(mock_setup.mock_calls) == 0
|
assert len(mock_setup.mock_calls) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_configuring_hisense_w4a1_not_creates_entry_for_empty_import(hass):
|
async def test_configuring_hisense_w4a1_not_creates_entry_for_empty_import(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
) -> None:
|
||||||
"""Test that specifying config will not create an entry."""
|
"""Test that specifying config will not create an entry."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.hisense_aehw4a1.async_setup_entry",
|
"homeassistant.components.hisense_aehw4a1.async_setup_entry",
|
||||||
|
|
|
@ -6,6 +6,7 @@ from apyhiveapi.helper import hive_exceptions
|
||||||
from homeassistant import config_entries, data_entry_flow
|
from homeassistant import config_entries, data_entry_flow
|
||||||
from homeassistant.components.hive.const import CONF_CODE, CONF_DEVICE_NAME, DOMAIN
|
from homeassistant.components.hive.const import CONF_CODE, CONF_DEVICE_NAME, DOMAIN
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ MFA_RESEND_CODE = "0000"
|
||||||
MFA_INVALID_CODE = "HIVE"
|
MFA_INVALID_CODE = "HIVE"
|
||||||
|
|
||||||
|
|
||||||
async def test_import_flow(hass):
|
async def test_import_flow(hass: HomeAssistant) -> None:
|
||||||
"""Check import flow."""
|
"""Check import flow."""
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -64,7 +65,7 @@ async def test_import_flow(hass):
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow(hass):
|
async def test_user_flow(hass: HomeAssistant) -> None:
|
||||||
"""Test the user flow."""
|
"""Test the user flow."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -113,7 +114,7 @@ async def test_user_flow(hass):
|
||||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_2fa(hass):
|
async def test_user_flow_2fa(hass: HomeAssistant) -> None:
|
||||||
"""Test user flow with 2FA."""
|
"""Test user flow with 2FA."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -209,7 +210,7 @@ async def test_user_flow_2fa(hass):
|
||||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_reauth_flow(hass):
|
async def test_reauth_flow(hass: HomeAssistant) -> None:
|
||||||
"""Test the reauth flow."""
|
"""Test the reauth flow."""
|
||||||
|
|
||||||
mock_config = MockConfigEntry(
|
mock_config = MockConfigEntry(
|
||||||
|
@ -268,7 +269,7 @@ async def test_reauth_flow(hass):
|
||||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_reauth_2fa_flow(hass):
|
async def test_reauth_2fa_flow(hass: HomeAssistant) -> None:
|
||||||
"""Test the reauth flow."""
|
"""Test the reauth flow."""
|
||||||
|
|
||||||
mock_config = MockConfigEntry(
|
mock_config = MockConfigEntry(
|
||||||
|
@ -344,7 +345,7 @@ async def test_reauth_2fa_flow(hass):
|
||||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_option_flow(hass):
|
async def test_option_flow(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow options."""
|
"""Test config flow options."""
|
||||||
|
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
|
@ -381,7 +382,7 @@ async def test_option_flow(hass):
|
||||||
assert result["data"][CONF_SCAN_INTERVAL] == UPDATED_SCAN_INTERVAL
|
assert result["data"][CONF_SCAN_INTERVAL] == UPDATED_SCAN_INTERVAL
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_2fa_send_new_code(hass):
|
async def test_user_flow_2fa_send_new_code(hass: HomeAssistant) -> None:
|
||||||
"""Resend a 2FA code if it didn't arrive."""
|
"""Resend a 2FA code if it didn't arrive."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -488,7 +489,7 @@ async def test_user_flow_2fa_send_new_code(hass):
|
||||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_abort_if_existing_entry(hass):
|
async def test_abort_if_existing_entry(hass: HomeAssistant) -> None:
|
||||||
"""Check flow abort when an entry already exist."""
|
"""Check flow abort when an entry already exist."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -511,7 +512,7 @@ async def test_abort_if_existing_entry(hass):
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_invalid_username(hass):
|
async def test_user_flow_invalid_username(hass: HomeAssistant) -> None:
|
||||||
"""Test user flow with invalid username."""
|
"""Test user flow with invalid username."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -534,7 +535,7 @@ async def test_user_flow_invalid_username(hass):
|
||||||
assert result2["errors"] == {"base": "invalid_username"}
|
assert result2["errors"] == {"base": "invalid_username"}
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_invalid_password(hass):
|
async def test_user_flow_invalid_password(hass: HomeAssistant) -> None:
|
||||||
"""Test user flow with invalid password."""
|
"""Test user flow with invalid password."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -557,7 +558,7 @@ async def test_user_flow_invalid_password(hass):
|
||||||
assert result2["errors"] == {"base": "invalid_password"}
|
assert result2["errors"] == {"base": "invalid_password"}
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_no_internet_connection(hass):
|
async def test_user_flow_no_internet_connection(hass: HomeAssistant) -> None:
|
||||||
"""Test user flow with no internet connection."""
|
"""Test user flow with no internet connection."""
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -581,7 +582,7 @@ async def test_user_flow_no_internet_connection(hass):
|
||||||
assert result2["errors"] == {"base": "no_internet_available"}
|
assert result2["errors"] == {"base": "no_internet_available"}
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_2fa_no_internet_connection(hass):
|
async def test_user_flow_2fa_no_internet_connection(hass: HomeAssistant) -> None:
|
||||||
"""Test user flow with no internet connection."""
|
"""Test user flow with no internet connection."""
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -620,7 +621,7 @@ async def test_user_flow_2fa_no_internet_connection(hass):
|
||||||
assert result3["errors"] == {"base": "no_internet_available"}
|
assert result3["errors"] == {"base": "no_internet_available"}
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_2fa_invalid_code(hass):
|
async def test_user_flow_2fa_invalid_code(hass: HomeAssistant) -> None:
|
||||||
"""Test user flow with 2FA."""
|
"""Test user flow with 2FA."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -657,7 +658,7 @@ async def test_user_flow_2fa_invalid_code(hass):
|
||||||
assert result3["errors"] == {"base": "invalid_code"}
|
assert result3["errors"] == {"base": "invalid_code"}
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_unknown_error(hass):
|
async def test_user_flow_unknown_error(hass: HomeAssistant) -> None:
|
||||||
"""Test user flow when unknown error occurs."""
|
"""Test user flow when unknown error occurs."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -680,7 +681,7 @@ async def test_user_flow_unknown_error(hass):
|
||||||
assert result2["errors"] == {"base": "unknown"}
|
assert result2["errors"] == {"base": "unknown"}
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_2fa_unknown_error(hass):
|
async def test_user_flow_2fa_unknown_error(hass: HomeAssistant) -> None:
|
||||||
"""Test 2fa flow when unknown error occurs."""
|
"""Test 2fa flow when unknown error occurs."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
|
|
@ -4,6 +4,7 @@ from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.hlk_sw16.const import DOMAIN
|
from homeassistant.components.hlk_sw16.const import DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
|
||||||
class MockSW16Client:
|
class MockSW16Client:
|
||||||
|
@ -47,7 +48,7 @@ async def create_mock_hlk_sw16_connection(fail):
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
|
||||||
async def test_form(hass):
|
async def test_form(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -108,7 +109,7 @@ async def test_form(hass):
|
||||||
assert result4["reason"] == "already_configured"
|
assert result4["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_import(hass):
|
async def test_import(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -149,7 +150,7 @@ async def test_import(hass):
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_form_invalid_data(hass):
|
async def test_form_invalid_data(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle invalid auth."""
|
"""Test we handle invalid auth."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -175,7 +176,7 @@ async def test_form_invalid_data(hass):
|
||||||
assert result2["errors"] == {"base": "cannot_connect"}
|
assert result2["errors"] == {"base": "cannot_connect"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_cannot_connect(hass):
|
async def test_form_cannot_connect(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle cannot connect error."""
|
"""Test we handle cannot connect error."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The tests for Core components."""
|
"""The tests for Core components."""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
@ -31,6 +30,7 @@ from homeassistant.const import (
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
)
|
)
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError, Unauthorized
|
from homeassistant.exceptions import HomeAssistantError, Unauthorized
|
||||||
from homeassistant.helpers import entity
|
from homeassistant.helpers import entity
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -236,7 +236,9 @@ class TestComponentsCore(unittest.TestCase):
|
||||||
assert not mock_stop.called
|
assert not mock_stop.called
|
||||||
|
|
||||||
|
|
||||||
async def test_turn_on_skips_domains_without_service(hass, caplog):
|
async def test_turn_on_skips_domains_without_service(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test if turn_on is blocking domain with no service."""
|
"""Test if turn_on is blocking domain with no service."""
|
||||||
await async_setup_component(hass, "homeassistant", {})
|
await async_setup_component(hass, "homeassistant", {})
|
||||||
async_mock_service(hass, "light", SERVICE_TURN_ON)
|
async_mock_service(hass, "light", SERVICE_TURN_ON)
|
||||||
|
@ -275,7 +277,7 @@ async def test_turn_on_skips_domains_without_service(hass, caplog):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_update(hass):
|
async def test_entity_update(hass: HomeAssistant) -> None:
|
||||||
"""Test being able to call entity update."""
|
"""Test being able to call entity update."""
|
||||||
await async_setup_component(hass, "homeassistant", {})
|
await async_setup_component(hass, "homeassistant", {})
|
||||||
|
|
||||||
|
@ -294,7 +296,7 @@ async def test_entity_update(hass):
|
||||||
assert mock_update.mock_calls[0][1][1] == "light.kitchen"
|
assert mock_update.mock_calls[0][1][1] == "light.kitchen"
|
||||||
|
|
||||||
|
|
||||||
async def test_setting_location(hass):
|
async def test_setting_location(hass: HomeAssistant) -> None:
|
||||||
"""Test setting the location."""
|
"""Test setting the location."""
|
||||||
await async_setup_component(hass, "homeassistant", {})
|
await async_setup_component(hass, "homeassistant", {})
|
||||||
events = async_capture_events(hass, EVENT_CORE_CONFIG_UPDATE)
|
events = async_capture_events(hass, EVENT_CORE_CONFIG_UPDATE)
|
||||||
|
@ -358,7 +360,9 @@ async def test_turn_on_off_toggle_schema(hass, hass_read_only_user):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_not_allowing_recursion(hass, caplog):
|
async def test_not_allowing_recursion(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test we do not allow recursion."""
|
"""Test we do not allow recursion."""
|
||||||
await async_setup_component(hass, "homeassistant", {})
|
await async_setup_component(hass, "homeassistant", {})
|
||||||
|
|
||||||
|
@ -375,7 +379,7 @@ async def test_not_allowing_recursion(hass, caplog):
|
||||||
), service
|
), service
|
||||||
|
|
||||||
|
|
||||||
async def test_reload_config_entry_by_entity_id(hass):
|
async def test_reload_config_entry_by_entity_id(hass: HomeAssistant) -> None:
|
||||||
"""Test being able to reload a config entry by entity_id."""
|
"""Test being able to reload a config entry by entity_id."""
|
||||||
await async_setup_component(hass, "homeassistant", {})
|
await async_setup_component(hass, "homeassistant", {})
|
||||||
entity_reg = mock_registry(hass)
|
entity_reg = mock_registry(hass)
|
||||||
|
@ -415,7 +419,7 @@ async def test_reload_config_entry_by_entity_id(hass):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_reload_config_entry_by_entry_id(hass):
|
async def test_reload_config_entry_by_entry_id(hass: HomeAssistant) -> None:
|
||||||
"""Test being able to reload a config entry by config entry id."""
|
"""Test being able to reload a config entry by config entry id."""
|
||||||
await async_setup_component(hass, "homeassistant", {})
|
await async_setup_component(hass, "homeassistant", {})
|
||||||
|
|
||||||
|
@ -473,7 +477,9 @@ async def test_raises_when_db_upgrade_in_progress(hass, service, caplog):
|
||||||
assert mock_async_migration_in_progress.called
|
assert mock_async_migration_in_progress.called
|
||||||
|
|
||||||
|
|
||||||
async def test_raises_when_config_is_invalid(hass, caplog):
|
async def test_raises_when_config_is_invalid(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test an exception is raised when the configuration is invalid."""
|
"""Test an exception is raised when the configuration is invalid."""
|
||||||
await async_setup_component(hass, "homeassistant", {})
|
await async_setup_component(hass, "homeassistant", {})
|
||||||
|
|
||||||
|
@ -510,7 +516,7 @@ async def test_raises_when_config_is_invalid(hass, caplog):
|
||||||
assert mock_async_check_ha_config_file.called
|
assert mock_async_check_ha_config_file.called
|
||||||
|
|
||||||
|
|
||||||
async def test_restart_homeassistant(hass):
|
async def test_restart_homeassistant(hass: HomeAssistant) -> None:
|
||||||
"""Test we can restart when there is no configuration error."""
|
"""Test we can restart when there is no configuration error."""
|
||||||
await async_setup_component(hass, "homeassistant", {})
|
await async_setup_component(hass, "homeassistant", {})
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -528,7 +534,7 @@ async def test_restart_homeassistant(hass):
|
||||||
assert mock_restart.called
|
assert mock_restart.called
|
||||||
|
|
||||||
|
|
||||||
async def test_stop_homeassistant(hass):
|
async def test_stop_homeassistant(hass: HomeAssistant) -> None:
|
||||||
"""Test we can stop when there is a configuration error."""
|
"""Test we can stop when there is a configuration error."""
|
||||||
await async_setup_component(hass, "homeassistant", {})
|
await async_setup_component(hass, "homeassistant", {})
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -546,7 +552,7 @@ async def test_stop_homeassistant(hass):
|
||||||
assert mock_restart.called
|
assert mock_restart.called
|
||||||
|
|
||||||
|
|
||||||
async def test_save_persistent_states(hass):
|
async def test_save_persistent_states(hass: HomeAssistant) -> None:
|
||||||
"""Test we can call save_persistent_states."""
|
"""Test we can call save_persistent_states."""
|
||||||
await async_setup_component(hass, "homeassistant", {})
|
await async_setup_component(hass, "homeassistant", {})
|
||||||
with patch(
|
with patch(
|
||||||
|
|
|
@ -7,12 +7,13 @@ import voluptuous as vol
|
||||||
from homeassistant.components.homeassistant import scene as ha_scene
|
from homeassistant.components.homeassistant import scene as ha_scene
|
||||||
from homeassistant.components.homeassistant.scene import EVENT_SCENE_RELOADED
|
from homeassistant.components.homeassistant.scene import EVENT_SCENE_RELOADED
|
||||||
from homeassistant.const import STATE_UNKNOWN
|
from homeassistant.const import STATE_UNKNOWN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import async_capture_events, async_mock_service
|
from tests.common import async_capture_events, async_mock_service
|
||||||
|
|
||||||
|
|
||||||
async def test_reload_config_service(hass):
|
async def test_reload_config_service(hass: HomeAssistant) -> None:
|
||||||
"""Test the reload config service."""
|
"""Test the reload config service."""
|
||||||
assert await async_setup_component(hass, "scene", {})
|
assert await async_setup_component(hass, "scene", {})
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ async def test_reload_config_service(hass):
|
||||||
assert hass.states.get("scene.bye") is not None
|
assert hass.states.get("scene.bye") is not None
|
||||||
|
|
||||||
|
|
||||||
async def test_apply_service(hass):
|
async def test_apply_service(hass: HomeAssistant) -> None:
|
||||||
"""Test the apply service."""
|
"""Test the apply service."""
|
||||||
assert await async_setup_component(hass, "scene", {})
|
assert await async_setup_component(hass, "scene", {})
|
||||||
assert await async_setup_component(hass, "light", {"light": {"platform": "demo"}})
|
assert await async_setup_component(hass, "light", {"light": {"platform": "demo"}})
|
||||||
|
@ -84,7 +85,9 @@ async def test_apply_service(hass):
|
||||||
assert turn_on_calls[0].data.get("brightness") == 50
|
assert turn_on_calls[0].data.get("brightness") == 50
|
||||||
|
|
||||||
|
|
||||||
async def test_create_service(hass, caplog):
|
async def test_create_service(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test the create service."""
|
"""Test the create service."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -161,7 +164,9 @@ async def test_create_service(hass, caplog):
|
||||||
assert scene.attributes.get("entity_id") == ["light.kitchen"]
|
assert scene.attributes.get("entity_id") == ["light.kitchen"]
|
||||||
|
|
||||||
|
|
||||||
async def test_snapshot_service(hass, caplog):
|
async def test_snapshot_service(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test the snapshot option."""
|
"""Test the snapshot option."""
|
||||||
assert await async_setup_component(hass, "scene", {"scene": {}})
|
assert await async_setup_component(hass, "scene", {"scene": {}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -219,7 +224,7 @@ async def test_snapshot_service(hass, caplog):
|
||||||
assert "light.bed_light" in scene.attributes.get("entity_id")
|
assert "light.bed_light" in scene.attributes.get("entity_id")
|
||||||
|
|
||||||
|
|
||||||
async def test_ensure_no_intersection(hass):
|
async def test_ensure_no_intersection(hass: HomeAssistant) -> None:
|
||||||
"""Test that entities and snapshot_entities do not overlap."""
|
"""Test that entities and snapshot_entities do not overlap."""
|
||||||
assert await async_setup_component(hass, "scene", {"scene": {}})
|
assert await async_setup_component(hass, "scene", {"scene": {}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -240,7 +245,7 @@ async def test_ensure_no_intersection(hass):
|
||||||
assert hass.states.get("scene.hallo") is None
|
assert hass.states.get("scene.hallo") is None
|
||||||
|
|
||||||
|
|
||||||
async def test_scenes_with_entity(hass):
|
async def test_scenes_with_entity(hass: HomeAssistant) -> None:
|
||||||
"""Test finding scenes with a specific entity."""
|
"""Test finding scenes with a specific entity."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -264,7 +269,7 @@ async def test_scenes_with_entity(hass):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
async def test_entities_in_scene(hass):
|
async def test_entities_in_scene(hass: HomeAssistant) -> None:
|
||||||
"""Test finding entities in a scene."""
|
"""Test finding entities in a scene."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -290,7 +295,7 @@ async def test_entities_in_scene(hass):
|
||||||
assert ha_scene.entities_in_scene(hass, scene_id) == entities
|
assert ha_scene.entities_in_scene(hass, scene_id) == entities
|
||||||
|
|
||||||
|
|
||||||
async def test_config(hass):
|
async def test_config(hass: HomeAssistant) -> None:
|
||||||
"""Test passing config in YAML."""
|
"""Test passing config in YAML."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -47,7 +47,7 @@ from homeassistant.const import (
|
||||||
SERVICE_RELOAD,
|
SERVICE_RELOAD,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistantError, State
|
from homeassistant.core import HomeAssistant, HomeAssistantError, State
|
||||||
from homeassistant.helpers import device_registry, entity_registry as er, instance_id
|
from homeassistant.helpers import device_registry, entity_registry as er, instance_id
|
||||||
from homeassistant.helpers.entityfilter import (
|
from homeassistant.helpers.entityfilter import (
|
||||||
CONF_EXCLUDE_DOMAINS,
|
CONF_EXCLUDE_DOMAINS,
|
||||||
|
@ -744,7 +744,7 @@ async def test_homekit_start_with_a_device(
|
||||||
await homekit.async_stop()
|
await homekit.async_stop()
|
||||||
|
|
||||||
|
|
||||||
async def test_homekit_stop(hass):
|
async def test_homekit_stop(hass: HomeAssistant) -> None:
|
||||||
"""Test HomeKit stop method."""
|
"""Test HomeKit stop method."""
|
||||||
entry = await async_init_integration(hass)
|
entry = await async_init_integration(hass)
|
||||||
homekit = _mock_homekit(hass, entry, HOMEKIT_MODE_BRIDGE)
|
homekit = _mock_homekit(hass, entry, HOMEKIT_MODE_BRIDGE)
|
||||||
|
|
|
@ -50,7 +50,7 @@ from homeassistant.const import (
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
UnitOfTemperature,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import State
|
from homeassistant.core import HomeAssistant, State
|
||||||
|
|
||||||
from .util import async_init_integration
|
from .util import async_init_integration
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ async def test_async_show_setup_msg(hass, hk_driver, mock_get_source_ip):
|
||||||
assert pincode.decode() in mock_create.mock_calls[0][1][1]
|
assert pincode.decode() in mock_create.mock_calls[0][1][1]
|
||||||
|
|
||||||
|
|
||||||
async def test_async_dismiss_setup_msg(hass):
|
async def test_async_dismiss_setup_msg(hass: HomeAssistant) -> None:
|
||||||
"""Test dismiss setup message."""
|
"""Test dismiss setup message."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.persistent_notification.async_dismiss",
|
"homeassistant.components.persistent_notification.async_dismiss",
|
||||||
|
@ -270,7 +270,7 @@ async def test_async_dismiss_setup_msg(hass):
|
||||||
assert mock_dismiss.mock_calls[0][1][1] == "entry_id"
|
assert mock_dismiss.mock_calls[0][1][1] == "entry_id"
|
||||||
|
|
||||||
|
|
||||||
async def test_port_is_available(hass):
|
async def test_port_is_available(hass: HomeAssistant) -> None:
|
||||||
"""Test we can get an available port and it is actually available."""
|
"""Test we can get an available port and it is actually available."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.homekit.util.socket.socket",
|
"homeassistant.components.homekit.util.socket.socket",
|
||||||
|
@ -303,7 +303,7 @@ async def test_port_is_available(hass):
|
||||||
assert not async_port_is_available(next_port)
|
assert not async_port_is_available(next_port)
|
||||||
|
|
||||||
|
|
||||||
async def test_port_is_available_skips_existing_entries(hass):
|
async def test_port_is_available_skips_existing_entries(hass: HomeAssistant) -> None:
|
||||||
"""Test we can get an available port and it is actually available."""
|
"""Test we can get an available port and it is actually available."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -380,7 +380,7 @@ async def test_accessory_friendly_name() -> None:
|
||||||
assert accessory_friendly_name("hass title", accessory) == "Hass title 123"
|
assert accessory_friendly_name("hass title", accessory) == "Hass title 123"
|
||||||
|
|
||||||
|
|
||||||
async def test_lock_state_needs_accessory_mode(hass):
|
async def test_lock_state_needs_accessory_mode(hass: HomeAssistant) -> None:
|
||||||
"""Test that locks are setup as accessories."""
|
"""Test that locks are setup as accessories."""
|
||||||
hass.states.async_set("lock.mine", "locked")
|
hass.states.async_set("lock.mine", "locked")
|
||||||
assert state_needs_accessory_mode(hass.states.get("lock.mine")) is True
|
assert state_needs_accessory_mode(hass.states.get("lock.mine")) is True
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
from aiohomekit.model.characteristics import CharacteristicsTypes
|
||||||
from aiohomekit.model.services import ServicesTypes
|
from aiohomekit.model.services import ServicesTypes
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from .common import Helper, get_next_aid, setup_test_component
|
from .common import Helper, get_next_aid, setup_test_component
|
||||||
|
@ -37,7 +38,7 @@ def create_switch_with_ecobee_clear_hold_button(accessory):
|
||||||
return service
|
return service
|
||||||
|
|
||||||
|
|
||||||
async def test_press_button(hass):
|
async def test_press_button(hass: HomeAssistant) -> None:
|
||||||
"""Test a switch service that has a button characteristic is correctly handled."""
|
"""Test a switch service that has a button characteristic is correctly handled."""
|
||||||
helper = await setup_test_component(hass, create_switch_with_setup_button)
|
helper = await setup_test_component(hass, create_switch_with_setup_button)
|
||||||
|
|
||||||
|
@ -64,7 +65,7 @@ async def test_press_button(hass):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_ecobee_clear_hold_press_button(hass):
|
async def test_ecobee_clear_hold_press_button(hass: HomeAssistant) -> None:
|
||||||
"""Test ecobee clear hold button characteristic is correctly handled."""
|
"""Test ecobee clear hold button characteristic is correctly handled."""
|
||||||
helper = await setup_test_component(
|
helper = await setup_test_component(
|
||||||
hass, create_switch_with_ecobee_clear_hold_button
|
hass, create_switch_with_ecobee_clear_hold_button
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""Tests for homekit_controller init."""
|
"""Tests for homekit_controller init."""
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
@ -26,6 +25,7 @@ from .common import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed
|
from tests.common import async_fire_time_changed
|
||||||
|
from tests.typing import WebSocketGenerator
|
||||||
|
|
||||||
ALIVE_DEVICE_NAME = "testdevice"
|
ALIVE_DEVICE_NAME = "testdevice"
|
||||||
ALIVE_DEVICE_ENTITY_ID = "light.testdevice"
|
ALIVE_DEVICE_ENTITY_ID = "light.testdevice"
|
||||||
|
@ -75,7 +75,9 @@ def create_alive_service(accessory):
|
||||||
return service
|
return service
|
||||||
|
|
||||||
|
|
||||||
async def test_device_remove_devices(hass, hass_ws_client):
|
async def test_device_remove_devices(
|
||||||
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
|
) -> None:
|
||||||
"""Test we can only remove a device that no longer exists."""
|
"""Test we can only remove a device that no longer exists."""
|
||||||
assert await async_setup_component(hass, "config", {})
|
assert await async_setup_component(hass, "config", {})
|
||||||
helper: Helper = await setup_test_component(hass, create_alive_service)
|
helper: Helper = await setup_test_component(hass, create_alive_service)
|
||||||
|
|
|
@ -4,6 +4,7 @@ from aiohomekit.model.services import ServicesTypes
|
||||||
|
|
||||||
from homeassistant.components.homekit_controller.const import ENTITY_MAP
|
from homeassistant.components.homekit_controller.const import ENTITY_MAP
|
||||||
from homeassistant.components.homekit_controller.storage import EntityMapStorage
|
from homeassistant.components.homekit_controller.storage import EntityMapStorage
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .common import setup_platform, setup_test_component
|
from .common import setup_platform, setup_test_component
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ async def test_storage_is_removed(hass, hass_storage):
|
||||||
assert hass_storage[ENTITY_MAP]["data"]["pairings"] == {}
|
assert hass_storage[ENTITY_MAP]["data"]["pairings"] == {}
|
||||||
|
|
||||||
|
|
||||||
async def test_storage_is_removed_idempotent(hass):
|
async def test_storage_is_removed_idempotent(hass: HomeAssistant) -> None:
|
||||||
"""Test entity map storage removal is idempotent."""
|
"""Test entity map storage removal is idempotent."""
|
||||||
await setup_platform(hass)
|
await setup_platform(hass)
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
"""The tests for the Homematic notification platform."""
|
"""The tests for the Homematic notification platform."""
|
||||||
|
|
||||||
import homeassistant.components.notify as notify_comp
|
import homeassistant.components.notify as notify_comp
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import assert_setup_component
|
from tests.common import assert_setup_component
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_full(hass):
|
async def test_setup_full(hass: HomeAssistant) -> None:
|
||||||
"""Test valid configuration."""
|
"""Test valid configuration."""
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -32,7 +32,7 @@ async def test_setup_full(hass):
|
||||||
assert handle_config[notify_comp.DOMAIN]
|
assert handle_config[notify_comp.DOMAIN]
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_without_optional(hass):
|
async def test_setup_without_optional(hass: HomeAssistant) -> None:
|
||||||
"""Test valid configuration without optional."""
|
"""Test valid configuration without optional."""
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -57,7 +57,7 @@ async def test_setup_without_optional(hass):
|
||||||
assert handle_config[notify_comp.DOMAIN]
|
assert handle_config[notify_comp.DOMAIN]
|
||||||
|
|
||||||
|
|
||||||
async def test_bad_config(hass):
|
async def test_bad_config(hass: HomeAssistant) -> None:
|
||||||
"""Test invalid configuration."""
|
"""Test invalid configuration."""
|
||||||
config = {notify_comp.DOMAIN: {"name": "test", "platform": "homematic"}}
|
config = {notify_comp.DOMAIN: {"name": "test", "platform": "homematic"}}
|
||||||
with assert_setup_component(0) as handle_config:
|
with assert_setup_component(0) as handle_config:
|
||||||
|
|
|
@ -9,6 +9,7 @@ from homeassistant.const import (
|
||||||
STATE_ALARM_DISARMED,
|
STATE_ALARM_DISARMED,
|
||||||
STATE_ALARM_TRIGGERED,
|
STATE_ALARM_TRIGGERED,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .helper import get_and_check_entity_basics
|
from .helper import get_and_check_entity_basics
|
||||||
|
@ -36,7 +37,7 @@ async def _async_manipulate_security_zones(
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
async def test_manually_configured_platform(hass):
|
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
|
||||||
"""Test that we do not set up an access point."""
|
"""Test that we do not set up an access point."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -23,12 +23,13 @@ from homeassistant.components.homematicip_cloud.generic_entity import (
|
||||||
ATTR_SABOTAGE,
|
ATTR_SABOTAGE,
|
||||||
)
|
)
|
||||||
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNKNOWN
|
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNKNOWN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .helper import async_manipulate_test_data, get_and_check_entity_basics
|
from .helper import async_manipulate_test_data, get_and_check_entity_basics
|
||||||
|
|
||||||
|
|
||||||
async def test_manually_configured_platform(hass):
|
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
|
||||||
"""Test that we do not set up an access point."""
|
"""Test that we do not set up an access point."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -22,12 +22,13 @@ from homeassistant.components.homematicip_cloud.climate import (
|
||||||
ATTR_PRESET_END_TIME,
|
ATTR_PRESET_END_TIME,
|
||||||
PERMANENT_END_TIME,
|
PERMANENT_END_TIME,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .helper import HAPID, async_manipulate_test_data, get_and_check_entity_basics
|
from .helper import HAPID, async_manipulate_test_data, get_and_check_entity_basics
|
||||||
|
|
||||||
|
|
||||||
async def test_manually_configured_platform(hass):
|
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
|
||||||
"""Test that we do not set up an access point."""
|
"""Test that we do not set up an access point."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, CLIMATE_DOMAIN, {CLIMATE_DOMAIN: {"platform": HMIPC_DOMAIN}}
|
hass, CLIMATE_DOMAIN, {CLIMATE_DOMAIN: {"platform": HMIPC_DOMAIN}}
|
||||||
|
|
|
@ -9,6 +9,7 @@ from homeassistant.components.homematicip_cloud.const import (
|
||||||
HMIPC_NAME,
|
HMIPC_NAME,
|
||||||
HMIPC_PIN,
|
HMIPC_PIN,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ async def test_flow_works(hass, simple_mock_home):
|
||||||
assert result["result"].unique_id == "ABC123"
|
assert result["result"].unique_id == "ABC123"
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_init_connection_error(hass):
|
async def test_flow_init_connection_error(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow with accesspoint connection error."""
|
"""Test config flow with accesspoint connection error."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_setup",
|
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_setup",
|
||||||
|
@ -82,7 +83,7 @@ async def test_flow_init_connection_error(hass):
|
||||||
assert result["step_id"] == "init"
|
assert result["step_id"] == "init"
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_link_connection_error(hass):
|
async def test_flow_link_connection_error(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow client registration connection error."""
|
"""Test config flow client registration connection error."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_checkbutton",
|
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_checkbutton",
|
||||||
|
@ -104,7 +105,7 @@ async def test_flow_link_connection_error(hass):
|
||||||
assert result["reason"] == "connection_aborted"
|
assert result["reason"] == "connection_aborted"
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_link_press_button(hass):
|
async def test_flow_link_press_button(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow ask for pressing the blue button."""
|
"""Test config flow ask for pressing the blue button."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_checkbutton",
|
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_checkbutton",
|
||||||
|
@ -124,7 +125,7 @@ async def test_flow_link_press_button(hass):
|
||||||
assert result["errors"] == {"base": "press_the_button"}
|
assert result["errors"] == {"base": "press_the_button"}
|
||||||
|
|
||||||
|
|
||||||
async def test_init_flow_show_form(hass):
|
async def test_init_flow_show_form(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow shows up with a form."""
|
"""Test config flow shows up with a form."""
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -134,7 +135,7 @@ async def test_init_flow_show_form(hass):
|
||||||
assert result["step_id"] == "init"
|
assert result["step_id"] == "init"
|
||||||
|
|
||||||
|
|
||||||
async def test_init_already_configured(hass):
|
async def test_init_already_configured(hass: HomeAssistant) -> None:
|
||||||
"""Test accesspoint is already configured."""
|
"""Test accesspoint is already configured."""
|
||||||
MockConfigEntry(domain=HMIPC_DOMAIN, unique_id="ABC123").add_to_hass(hass)
|
MockConfigEntry(domain=HMIPC_DOMAIN, unique_id="ABC123").add_to_hass(hass)
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -177,7 +178,7 @@ async def test_import_config(hass, simple_mock_home):
|
||||||
assert result["result"].unique_id == "ABC123"
|
assert result["result"].unique_id == "ABC123"
|
||||||
|
|
||||||
|
|
||||||
async def test_import_existing_config(hass):
|
async def test_import_existing_config(hass: HomeAssistant) -> None:
|
||||||
"""Test abort of an existing accesspoint from config."""
|
"""Test abort of an existing accesspoint from config."""
|
||||||
MockConfigEntry(domain=HMIPC_DOMAIN, unique_id="ABC123").add_to_hass(hass)
|
MockConfigEntry(domain=HMIPC_DOMAIN, unique_id="ABC123").add_to_hass(hass)
|
||||||
with patch(
|
with patch(
|
||||||
|
|
|
@ -8,12 +8,13 @@ from homeassistant.components.cover import (
|
||||||
)
|
)
|
||||||
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
|
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
|
||||||
from homeassistant.const import STATE_CLOSED, STATE_OPEN, STATE_UNKNOWN
|
from homeassistant.const import STATE_CLOSED, STATE_OPEN, STATE_UNKNOWN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .helper import async_manipulate_test_data, get_and_check_entity_basics
|
from .helper import async_manipulate_test_data, get_and_check_entity_basics
|
||||||
|
|
||||||
|
|
||||||
async def test_manually_configured_platform(hass):
|
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
|
||||||
"""Test that we do not set up an access point."""
|
"""Test that we do not set up an access point."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, COVER_DOMAIN, {COVER_DOMAIN: {"platform": HMIPC_DOMAIN}}
|
hass, COVER_DOMAIN, {COVER_DOMAIN: {"platform": HMIPC_DOMAIN}}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""Test HomematicIP Cloud accesspoint."""
|
"""Test HomematicIP Cloud accesspoint."""
|
||||||
|
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
from homematicip.aio.auth import AsyncAuth
|
from homematicip.aio.auth import AsyncAuth
|
||||||
|
@ -19,6 +18,7 @@ from homeassistant.components.homematicip_cloud.hap import (
|
||||||
HomematicipHAP,
|
HomematicipHAP,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
|
|
||||||
from .helper import HAPID, HAPPIN
|
from .helper import HAPID, HAPPIN
|
||||||
|
@ -26,7 +26,7 @@ from .helper import HAPID, HAPPIN
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_auth_setup(hass):
|
async def test_auth_setup(hass: HomeAssistant) -> None:
|
||||||
"""Test auth setup for client registration."""
|
"""Test auth setup for client registration."""
|
||||||
config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"}
|
config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"}
|
||||||
hmip_auth = HomematicipAuth(hass, config)
|
hmip_auth = HomematicipAuth(hass, config)
|
||||||
|
@ -34,7 +34,7 @@ async def test_auth_setup(hass):
|
||||||
assert await hmip_auth.async_setup()
|
assert await hmip_auth.async_setup()
|
||||||
|
|
||||||
|
|
||||||
async def test_auth_setup_connection_error(hass):
|
async def test_auth_setup_connection_error(hass: HomeAssistant) -> None:
|
||||||
"""Test auth setup connection error behaviour."""
|
"""Test auth setup connection error behaviour."""
|
||||||
config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"}
|
config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"}
|
||||||
hmip_auth = HomematicipAuth(hass, config)
|
hmip_auth = HomematicipAuth(hass, config)
|
||||||
|
@ -42,7 +42,7 @@ async def test_auth_setup_connection_error(hass):
|
||||||
assert not await hmip_auth.async_setup()
|
assert not await hmip_auth.async_setup()
|
||||||
|
|
||||||
|
|
||||||
async def test_auth_auth_check_and_register(hass):
|
async def test_auth_auth_check_and_register(hass: HomeAssistant) -> None:
|
||||||
"""Test auth client registration."""
|
"""Test auth client registration."""
|
||||||
config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"}
|
config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ async def test_auth_auth_check_and_register(hass):
|
||||||
assert await hmip_auth.async_register() == "ABC"
|
assert await hmip_auth.async_register() == "ABC"
|
||||||
|
|
||||||
|
|
||||||
async def test_auth_auth_check_and_register_with_exception(hass):
|
async def test_auth_auth_check_and_register_with_exception(hass: HomeAssistant) -> None:
|
||||||
"""Test auth client registration."""
|
"""Test auth client registration."""
|
||||||
config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"}
|
config = {HMIPC_HAPID: "ABC123", HMIPC_PIN: "123", HMIPC_NAME: "hmip"}
|
||||||
hmip_auth = HomematicipAuth(hass, config)
|
hmip_auth = HomematicipAuth(hass, config)
|
||||||
|
@ -73,7 +73,7 @@ async def test_auth_auth_check_and_register_with_exception(hass):
|
||||||
assert await hmip_auth.async_register() is False
|
assert await hmip_auth.async_register() is False
|
||||||
|
|
||||||
|
|
||||||
async def test_hap_setup_works(hass):
|
async def test_hap_setup_works(hass: HomeAssistant) -> None:
|
||||||
"""Test a successful setup of a accesspoint."""
|
"""Test a successful setup of a accesspoint."""
|
||||||
# This test should not be accessing the integration internals
|
# This test should not be accessing the integration internals
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""Test HomematicIP Cloud setup process."""
|
"""Test HomematicIP Cloud setup process."""
|
||||||
|
|
||||||
from unittest.mock import AsyncMock, Mock, patch
|
from unittest.mock import AsyncMock, Mock, patch
|
||||||
|
|
||||||
from homematicip.base.base_connection import HmipConnectionError
|
from homematicip.base.base_connection import HmipConnectionError
|
||||||
|
@ -15,6 +14,7 @@ from homeassistant.components.homematicip_cloud.const import (
|
||||||
from homeassistant.components.homematicip_cloud.hap import HomematicipHAP
|
from homeassistant.components.homematicip_cloud.hap import HomematicipHAP
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.const import CONF_NAME
|
from homeassistant.const import CONF_NAME
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
@ -130,7 +130,7 @@ async def test_load_entry_fails_due_to_generic_exception(hass, hmip_config_entry
|
||||||
assert hmip_config_entry.state is ConfigEntryState.SETUP_ERROR
|
assert hmip_config_entry.state is ConfigEntryState.SETUP_ERROR
|
||||||
|
|
||||||
|
|
||||||
async def test_unload_entry(hass):
|
async def test_unload_entry(hass: HomeAssistant) -> None:
|
||||||
"""Test being able to unload an entry."""
|
"""Test being able to unload an entry."""
|
||||||
mock_config = {HMIPC_AUTHTOKEN: "123", HMIPC_HAPID: "ABC123", HMIPC_NAME: "name"}
|
mock_config = {HMIPC_AUTHTOKEN: "123", HMIPC_HAPID: "ABC123", HMIPC_NAME: "name"}
|
||||||
MockConfigEntry(domain=HMIPC_DOMAIN, data=mock_config).add_to_hass(hass)
|
MockConfigEntry(domain=HMIPC_DOMAIN, data=mock_config).add_to_hass(hass)
|
||||||
|
@ -173,7 +173,7 @@ async def test_hmip_dump_hap_config_services(hass, mock_hap_with_service):
|
||||||
assert write_mock.mock_calls
|
assert write_mock.mock_calls
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_services_and_unload_services(hass):
|
async def test_setup_services_and_unload_services(hass: HomeAssistant) -> None:
|
||||||
"""Test setup services and unload services."""
|
"""Test setup services and unload services."""
|
||||||
mock_config = {HMIPC_AUTHTOKEN: "123", HMIPC_HAPID: "ABC123", HMIPC_NAME: "name"}
|
mock_config = {HMIPC_AUTHTOKEN: "123", HMIPC_HAPID: "ABC123", HMIPC_NAME: "name"}
|
||||||
MockConfigEntry(domain=HMIPC_DOMAIN, data=mock_config).add_to_hass(hass)
|
MockConfigEntry(domain=HMIPC_DOMAIN, data=mock_config).add_to_hass(hass)
|
||||||
|
@ -202,7 +202,7 @@ async def test_setup_services_and_unload_services(hass):
|
||||||
assert not hass.services.async_services().get(HMIPC_DOMAIN)
|
assert not hass.services.async_services().get(HMIPC_DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_two_haps_unload_one_by_one(hass):
|
async def test_setup_two_haps_unload_one_by_one(hass: HomeAssistant) -> None:
|
||||||
"""Test setup two access points and unload one by one and check services."""
|
"""Test setup two access points and unload one by one and check services."""
|
||||||
|
|
||||||
# Setup AP1
|
# Setup AP1
|
||||||
|
|
|
@ -12,12 +12,13 @@ from homeassistant.components.light import (
|
||||||
LightEntityFeature,
|
LightEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON
|
from homeassistant.const import ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .helper import async_manipulate_test_data, get_and_check_entity_basics
|
from .helper import async_manipulate_test_data, get_and_check_entity_basics
|
||||||
|
|
||||||
|
|
||||||
async def test_manually_configured_platform(hass):
|
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
|
||||||
"""Test that we do not set up an access point."""
|
"""Test that we do not set up an access point."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, LIGHT_DOMAIN, {LIGHT_DOMAIN: {"platform": HMIPC_DOMAIN}}
|
hass, LIGHT_DOMAIN, {LIGHT_DOMAIN: {"platform": HMIPC_DOMAIN}}
|
||||||
|
|
|
@ -32,12 +32,13 @@ from homeassistant.const import (
|
||||||
UnitOfSpeed,
|
UnitOfSpeed,
|
||||||
UnitOfTemperature,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .helper import async_manipulate_test_data, get_and_check_entity_basics
|
from .helper import async_manipulate_test_data, get_and_check_entity_basics
|
||||||
|
|
||||||
|
|
||||||
async def test_manually_configured_platform(hass):
|
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
|
||||||
"""Test that we do not set up an access point."""
|
"""Test that we do not set up an access point."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, SENSOR_DOMAIN, {SENSOR_DOMAIN: {"platform": HMIPC_DOMAIN}}
|
hass, SENSOR_DOMAIN, {SENSOR_DOMAIN: {"platform": HMIPC_DOMAIN}}
|
||||||
|
|
|
@ -5,12 +5,13 @@ from homeassistant.components.homematicip_cloud.generic_entity import (
|
||||||
)
|
)
|
||||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||||
from homeassistant.const import STATE_OFF, STATE_ON
|
from homeassistant.const import STATE_OFF, STATE_ON
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .helper import async_manipulate_test_data, get_and_check_entity_basics
|
from .helper import async_manipulate_test_data, get_and_check_entity_basics
|
||||||
|
|
||||||
|
|
||||||
async def test_manually_configured_platform(hass):
|
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
|
||||||
"""Test that we do not set up an access point."""
|
"""Test that we do not set up an access point."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, SWITCH_DOMAIN, {SWITCH_DOMAIN: {"platform": HMIPC_DOMAIN}}
|
hass, SWITCH_DOMAIN, {SWITCH_DOMAIN: {"platform": HMIPC_DOMAIN}}
|
||||||
|
|
|
@ -8,12 +8,13 @@ from homeassistant.components.weather import (
|
||||||
DOMAIN as WEATHER_DOMAIN,
|
DOMAIN as WEATHER_DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_ATTRIBUTION
|
from homeassistant.const import ATTR_ATTRIBUTION
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .helper import async_manipulate_test_data, get_and_check_entity_basics
|
from .helper import async_manipulate_test_data, get_and_check_entity_basics
|
||||||
|
|
||||||
|
|
||||||
async def test_manually_configured_platform(hass):
|
async def test_manually_configured_platform(hass: HomeAssistant) -> None:
|
||||||
"""Test that we do not set up an access point."""
|
"""Test that we do not set up an access point."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, WEATHER_DOMAIN, {WEATHER_DOMAIN: {"platform": HMIPC_DOMAIN}}
|
hass, WEATHER_DOMAIN, {WEATHER_DOMAIN: {"platform": HMIPC_DOMAIN}}
|
||||||
|
|
|
@ -7,6 +7,7 @@ from homeassistant import config_entries
|
||||||
from homeassistant.components import zeroconf
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.components.homewizard.const import DOMAIN
|
from homeassistant.components.homewizard.const import DOMAIN
|
||||||
from homeassistant.const import CONF_IP_ADDRESS
|
from homeassistant.const import CONF_IP_ADDRESS
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
|
|
||||||
from .generator import get_mock_device
|
from .generator import get_mock_device
|
||||||
|
@ -15,7 +16,9 @@ from tests.common import MockConfigEntry
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
|
|
||||||
async def test_manual_flow_works(hass, aioclient_mock):
|
async def test_manual_flow_works(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test config flow accepts user configuration."""
|
"""Test config flow accepts user configuration."""
|
||||||
|
|
||||||
device = get_mock_device()
|
device = get_mock_device()
|
||||||
|
@ -49,7 +52,9 @@ async def test_manual_flow_works(hass, aioclient_mock):
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_flow_works(hass, aioclient_mock):
|
async def test_discovery_flow_works(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test discovery setup flow works."""
|
"""Test discovery setup flow works."""
|
||||||
|
|
||||||
service_info = zeroconf.ZeroconfServiceInfo(
|
service_info = zeroconf.ZeroconfServiceInfo(
|
||||||
|
@ -218,7 +223,9 @@ async def test_discovery_flow_during_onboarding_disabled_api(
|
||||||
assert len(mock_onboarding.mock_calls) == 1
|
assert len(mock_onboarding.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_disabled_api(hass, aioclient_mock):
|
async def test_discovery_disabled_api(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test discovery detecting disabled api."""
|
"""Test discovery detecting disabled api."""
|
||||||
|
|
||||||
service_info = zeroconf.ZeroconfServiceInfo(
|
service_info = zeroconf.ZeroconfServiceInfo(
|
||||||
|
@ -266,7 +273,9 @@ async def test_discovery_disabled_api(hass, aioclient_mock):
|
||||||
assert result["errors"] == {"base": "api_not_enabled"}
|
assert result["errors"] == {"base": "api_not_enabled"}
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_missing_data_in_service_info(hass, aioclient_mock):
|
async def test_discovery_missing_data_in_service_info(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test discovery detecting missing discovery info."""
|
"""Test discovery detecting missing discovery info."""
|
||||||
|
|
||||||
service_info = zeroconf.ZeroconfServiceInfo(
|
service_info = zeroconf.ZeroconfServiceInfo(
|
||||||
|
@ -295,7 +304,9 @@ async def test_discovery_missing_data_in_service_info(hass, aioclient_mock):
|
||||||
assert result["reason"] == "invalid_discovery_parameters"
|
assert result["reason"] == "invalid_discovery_parameters"
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_invalid_api(hass, aioclient_mock):
|
async def test_discovery_invalid_api(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test discovery detecting invalid_api."""
|
"""Test discovery detecting invalid_api."""
|
||||||
|
|
||||||
service_info = zeroconf.ZeroconfServiceInfo(
|
service_info = zeroconf.ZeroconfServiceInfo(
|
||||||
|
@ -324,7 +335,9 @@ async def test_discovery_invalid_api(hass, aioclient_mock):
|
||||||
assert result["reason"] == "unsupported_api_version"
|
assert result["reason"] == "unsupported_api_version"
|
||||||
|
|
||||||
|
|
||||||
async def test_check_disabled_api(hass, aioclient_mock):
|
async def test_check_disabled_api(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test check detecting disabled api."""
|
"""Test check detecting disabled api."""
|
||||||
|
|
||||||
def mock_initialize():
|
def mock_initialize():
|
||||||
|
@ -352,7 +365,9 @@ async def test_check_disabled_api(hass, aioclient_mock):
|
||||||
assert result["errors"] == {"base": "api_not_enabled"}
|
assert result["errors"] == {"base": "api_not_enabled"}
|
||||||
|
|
||||||
|
|
||||||
async def test_check_error_handling_api(hass, aioclient_mock):
|
async def test_check_error_handling_api(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test check detecting error with api."""
|
"""Test check detecting error with api."""
|
||||||
|
|
||||||
def mock_initialize():
|
def mock_initialize():
|
||||||
|
@ -380,7 +395,9 @@ async def test_check_error_handling_api(hass, aioclient_mock):
|
||||||
assert result["reason"] == "unknown_error"
|
assert result["reason"] == "unknown_error"
|
||||||
|
|
||||||
|
|
||||||
async def test_check_detects_invalid_api(hass, aioclient_mock):
|
async def test_check_detects_invalid_api(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test check detecting device endpoint failed fetching data."""
|
"""Test check detecting device endpoint failed fetching data."""
|
||||||
|
|
||||||
def mock_initialize():
|
def mock_initialize():
|
||||||
|
@ -408,7 +425,9 @@ async def test_check_detects_invalid_api(hass, aioclient_mock):
|
||||||
assert result["reason"] == "unsupported_api_version"
|
assert result["reason"] == "unsupported_api_version"
|
||||||
|
|
||||||
|
|
||||||
async def test_check_requesterror(hass, aioclient_mock):
|
async def test_check_requesterror(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test check detecting device endpoint failed fetching data due to a requesterror."""
|
"""Test check detecting device endpoint failed fetching data due to a requesterror."""
|
||||||
|
|
||||||
def mock_initialize():
|
def mock_initialize():
|
||||||
|
@ -436,7 +455,9 @@ async def test_check_requesterror(hass, aioclient_mock):
|
||||||
assert result["errors"] == {"base": "network_error"}
|
assert result["errors"] == {"base": "network_error"}
|
||||||
|
|
||||||
|
|
||||||
async def test_reauth_flow(hass, aioclient_mock):
|
async def test_reauth_flow(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test reauth flow while API is enabled."""
|
"""Test reauth flow while API is enabled."""
|
||||||
|
|
||||||
mock_entry = MockConfigEntry(
|
mock_entry = MockConfigEntry(
|
||||||
|
@ -470,7 +491,9 @@ async def test_reauth_flow(hass, aioclient_mock):
|
||||||
assert result["reason"] == "reauth_successful"
|
assert result["reason"] == "reauth_successful"
|
||||||
|
|
||||||
|
|
||||||
async def test_reauth_error(hass, aioclient_mock):
|
async def test_reauth_error(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test reauth flow while API is still disabled."""
|
"""Test reauth flow while API is still disabled."""
|
||||||
|
|
||||||
def mock_initialize():
|
def mock_initialize():
|
||||||
|
|
|
@ -6,9 +6,12 @@ from unittest.mock import MagicMock, mock_open, patch
|
||||||
from aiohttp.hdrs import AUTHORIZATION
|
from aiohttp.hdrs import AUTHORIZATION
|
||||||
|
|
||||||
import homeassistant.components.html5.notify as html5
|
import homeassistant.components.html5.notify as html5
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
CONFIG_FILE = "file.conf"
|
CONFIG_FILE = "file.conf"
|
||||||
|
|
||||||
VAPID_CONF = {
|
VAPID_CONF = {
|
||||||
|
@ -239,7 +242,9 @@ class TestHtml5Notify:
|
||||||
assert mock_wp.mock_calls[3][2]["headers"]["priority"] == "normal"
|
assert mock_wp.mock_calls[3][2]["headers"]["priority"] == "normal"
|
||||||
|
|
||||||
|
|
||||||
async def test_registering_new_device_view(hass, hass_client):
|
async def test_registering_new_device_view(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test that the HTML view works."""
|
"""Test that the HTML view works."""
|
||||||
client = await mock_client(hass, hass_client)
|
client = await mock_client(hass, hass_client)
|
||||||
|
|
||||||
|
@ -251,7 +256,9 @@ async def test_registering_new_device_view(hass, hass_client):
|
||||||
assert mock_save.mock_calls[0][1][1] == {"unnamed device": SUBSCRIPTION_1}
|
assert mock_save.mock_calls[0][1][1] == {"unnamed device": SUBSCRIPTION_1}
|
||||||
|
|
||||||
|
|
||||||
async def test_registering_new_device_view_with_name(hass, hass_client):
|
async def test_registering_new_device_view_with_name(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test that the HTML view works with name attribute."""
|
"""Test that the HTML view works with name attribute."""
|
||||||
client = await mock_client(hass, hass_client)
|
client = await mock_client(hass, hass_client)
|
||||||
|
|
||||||
|
@ -266,7 +273,9 @@ async def test_registering_new_device_view_with_name(hass, hass_client):
|
||||||
assert mock_save.mock_calls[0][1][1] == {"test device": SUBSCRIPTION_1}
|
assert mock_save.mock_calls[0][1][1] == {"test device": SUBSCRIPTION_1}
|
||||||
|
|
||||||
|
|
||||||
async def test_registering_new_device_expiration_view(hass, hass_client):
|
async def test_registering_new_device_expiration_view(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test that the HTML view works."""
|
"""Test that the HTML view works."""
|
||||||
client = await mock_client(hass, hass_client)
|
client = await mock_client(hass, hass_client)
|
||||||
|
|
||||||
|
@ -277,7 +286,9 @@ async def test_registering_new_device_expiration_view(hass, hass_client):
|
||||||
assert mock_save.mock_calls[0][1][1] == {"unnamed device": SUBSCRIPTION_4}
|
assert mock_save.mock_calls[0][1][1] == {"unnamed device": SUBSCRIPTION_4}
|
||||||
|
|
||||||
|
|
||||||
async def test_registering_new_device_fails_view(hass, hass_client):
|
async def test_registering_new_device_fails_view(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test subs. are not altered when registering a new device fails."""
|
"""Test subs. are not altered when registering a new device fails."""
|
||||||
registrations = {}
|
registrations = {}
|
||||||
client = await mock_client(hass, hass_client, registrations)
|
client = await mock_client(hass, hass_client, registrations)
|
||||||
|
@ -292,7 +303,9 @@ async def test_registering_new_device_fails_view(hass, hass_client):
|
||||||
assert registrations == {}
|
assert registrations == {}
|
||||||
|
|
||||||
|
|
||||||
async def test_registering_existing_device_view(hass, hass_client):
|
async def test_registering_existing_device_view(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test subscription is updated when registering existing device."""
|
"""Test subscription is updated when registering existing device."""
|
||||||
registrations = {}
|
registrations = {}
|
||||||
client = await mock_client(hass, hass_client, registrations)
|
client = await mock_client(hass, hass_client, registrations)
|
||||||
|
@ -306,7 +319,9 @@ async def test_registering_existing_device_view(hass, hass_client):
|
||||||
assert registrations == {"unnamed device": SUBSCRIPTION_4}
|
assert registrations == {"unnamed device": SUBSCRIPTION_4}
|
||||||
|
|
||||||
|
|
||||||
async def test_registering_existing_device_view_with_name(hass, hass_client):
|
async def test_registering_existing_device_view_with_name(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test subscription is updated when reg'ing existing device with name."""
|
"""Test subscription is updated when reg'ing existing device with name."""
|
||||||
registrations = {}
|
registrations = {}
|
||||||
client = await mock_client(hass, hass_client, registrations)
|
client = await mock_client(hass, hass_client, registrations)
|
||||||
|
@ -323,7 +338,9 @@ async def test_registering_existing_device_view_with_name(hass, hass_client):
|
||||||
assert registrations == {"test device": SUBSCRIPTION_4}
|
assert registrations == {"test device": SUBSCRIPTION_4}
|
||||||
|
|
||||||
|
|
||||||
async def test_registering_existing_device_fails_view(hass, hass_client):
|
async def test_registering_existing_device_fails_view(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test sub. is not updated when registering existing device fails."""
|
"""Test sub. is not updated when registering existing device fails."""
|
||||||
registrations = {}
|
registrations = {}
|
||||||
client = await mock_client(hass, hass_client, registrations)
|
client = await mock_client(hass, hass_client, registrations)
|
||||||
|
@ -337,7 +354,9 @@ async def test_registering_existing_device_fails_view(hass, hass_client):
|
||||||
assert registrations == {"unnamed device": SUBSCRIPTION_1}
|
assert registrations == {"unnamed device": SUBSCRIPTION_1}
|
||||||
|
|
||||||
|
|
||||||
async def test_registering_new_device_validation(hass, hass_client):
|
async def test_registering_new_device_validation(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test various errors when registering a new device."""
|
"""Test various errors when registering a new device."""
|
||||||
client = await mock_client(hass, hass_client)
|
client = await mock_client(hass, hass_client)
|
||||||
|
|
||||||
|
@ -358,7 +377,9 @@ async def test_registering_new_device_validation(hass, hass_client):
|
||||||
assert resp.status == HTTPStatus.BAD_REQUEST
|
assert resp.status == HTTPStatus.BAD_REQUEST
|
||||||
|
|
||||||
|
|
||||||
async def test_unregistering_device_view(hass, hass_client):
|
async def test_unregistering_device_view(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test that the HTML unregister view works."""
|
"""Test that the HTML unregister view works."""
|
||||||
registrations = {"some device": SUBSCRIPTION_1, "other device": SUBSCRIPTION_2}
|
registrations = {"some device": SUBSCRIPTION_1, "other device": SUBSCRIPTION_2}
|
||||||
client = await mock_client(hass, hass_client, registrations)
|
client = await mock_client(hass, hass_client, registrations)
|
||||||
|
@ -374,7 +395,9 @@ async def test_unregistering_device_view(hass, hass_client):
|
||||||
assert registrations == {"other device": SUBSCRIPTION_2}
|
assert registrations == {"other device": SUBSCRIPTION_2}
|
||||||
|
|
||||||
|
|
||||||
async def test_unregister_device_view_handle_unknown_subscription(hass, hass_client):
|
async def test_unregister_device_view_handle_unknown_subscription(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test that the HTML unregister view handles unknown subscriptions."""
|
"""Test that the HTML unregister view handles unknown subscriptions."""
|
||||||
registrations = {}
|
registrations = {}
|
||||||
client = await mock_client(hass, hass_client, registrations)
|
client = await mock_client(hass, hass_client, registrations)
|
||||||
|
@ -390,7 +413,9 @@ async def test_unregister_device_view_handle_unknown_subscription(hass, hass_cli
|
||||||
assert len(mock_save.mock_calls) == 0
|
assert len(mock_save.mock_calls) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_unregistering_device_view_handles_save_error(hass, hass_client):
|
async def test_unregistering_device_view_handles_save_error(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test that the HTML unregister view handles save errors."""
|
"""Test that the HTML unregister view handles save errors."""
|
||||||
registrations = {"some device": SUBSCRIPTION_1, "other device": SUBSCRIPTION_2}
|
registrations = {"some device": SUBSCRIPTION_1, "other device": SUBSCRIPTION_2}
|
||||||
client = await mock_client(hass, hass_client, registrations)
|
client = await mock_client(hass, hass_client, registrations)
|
||||||
|
@ -411,7 +436,9 @@ async def test_unregistering_device_view_handles_save_error(hass, hass_client):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_callback_view_no_jwt(hass, hass_client):
|
async def test_callback_view_no_jwt(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test that the notification callback view works without JWT."""
|
"""Test that the notification callback view works without JWT."""
|
||||||
client = await mock_client(hass, hass_client)
|
client = await mock_client(hass, hass_client)
|
||||||
resp = await client.post(
|
resp = await client.post(
|
||||||
|
@ -424,7 +451,9 @@ async def test_callback_view_no_jwt(hass, hass_client):
|
||||||
assert resp.status == HTTPStatus.UNAUTHORIZED
|
assert resp.status == HTTPStatus.UNAUTHORIZED
|
||||||
|
|
||||||
|
|
||||||
async def test_callback_view_with_jwt(hass, hass_client):
|
async def test_callback_view_with_jwt(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test that the notification callback view works with JWT."""
|
"""Test that the notification callback view works with JWT."""
|
||||||
registrations = {"device": SUBSCRIPTION_1}
|
registrations = {"device": SUBSCRIPTION_1}
|
||||||
client = await mock_client(hass, hass_client, registrations)
|
client = await mock_client(hass, hass_client, registrations)
|
||||||
|
@ -460,7 +489,9 @@ async def test_callback_view_with_jwt(hass, hass_client):
|
||||||
assert body == {"event": "push", "status": "ok"}
|
assert body == {"event": "push", "status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
async def test_send_fcm_without_targets(hass, hass_client):
|
async def test_send_fcm_without_targets(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test that the notification is send with FCM without targets."""
|
"""Test that the notification is send with FCM without targets."""
|
||||||
registrations = {"device": SUBSCRIPTION_5}
|
registrations = {"device": SUBSCRIPTION_5}
|
||||||
await mock_client(hass, hass_client, registrations)
|
await mock_client(hass, hass_client, registrations)
|
||||||
|
@ -479,7 +510,9 @@ async def test_send_fcm_without_targets(hass, hass_client):
|
||||||
assert mock_wp.mock_calls[2][1][0] == SUBSCRIPTION_5["subscription"]
|
assert mock_wp.mock_calls[2][1][0] == SUBSCRIPTION_5["subscription"]
|
||||||
|
|
||||||
|
|
||||||
async def test_send_fcm_expired(hass, hass_client):
|
async def test_send_fcm_expired(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test that the FCM target is removed when expired."""
|
"""Test that the FCM target is removed when expired."""
|
||||||
registrations = {"device": SUBSCRIPTION_5}
|
registrations = {"device": SUBSCRIPTION_5}
|
||||||
await mock_client(hass, hass_client, registrations)
|
await mock_client(hass, hass_client, registrations)
|
||||||
|
@ -499,7 +532,9 @@ async def test_send_fcm_expired(hass, hass_client):
|
||||||
assert "device" not in registrations
|
assert "device" not in registrations
|
||||||
|
|
||||||
|
|
||||||
async def test_send_fcm_expired_save_fails(hass, hass_client):
|
async def test_send_fcm_expired_save_fails(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test that the FCM target remains after expiry if save_json fails."""
|
"""Test that the FCM target remains after expiry if save_json fails."""
|
||||||
registrations = {"device": SUBSCRIPTION_5}
|
registrations = {"device": SUBSCRIPTION_5}
|
||||||
await mock_client(hass, hass_client, registrations)
|
await mock_client(hass, hass_client, registrations)
|
||||||
|
|
|
@ -29,7 +29,7 @@ from homeassistant.components.http.request_context import (
|
||||||
current_request,
|
current_request,
|
||||||
setup_request_context,
|
setup_request_context,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import HTTP_HEADER_HA_AUTH, mock_real_ip
|
from . import HTTP_HEADER_HA_AUTH, mock_real_ip
|
||||||
|
@ -98,7 +98,7 @@ def trusted_networks_auth(hass):
|
||||||
return prv
|
return prv
|
||||||
|
|
||||||
|
|
||||||
async def test_auth_middleware_loaded_by_default(hass):
|
async def test_auth_middleware_loaded_by_default(hass: HomeAssistant) -> None:
|
||||||
"""Test accessing to server from banned IP when feature is off."""
|
"""Test accessing to server from banned IP when feature is off."""
|
||||||
with patch("homeassistant.components.http.async_setup_auth") as mock_setup:
|
with patch("homeassistant.components.http.async_setup_auth") as mock_setup:
|
||||||
await async_setup_component(hass, "http", {"http": {}})
|
await async_setup_component(hass, "http", {"http": {}})
|
||||||
|
@ -546,7 +546,7 @@ async def test_async_user_not_allowed_do_auth(hass, app):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_create_user_once(hass):
|
async def test_create_user_once(hass: HomeAssistant) -> None:
|
||||||
"""Test that we reuse the user."""
|
"""Test that we reuse the user."""
|
||||||
cur_users = len(await hass.auth.async_get_users())
|
cur_users = len(await hass.auth.async_get_users())
|
||||||
app = web.Application()
|
app = web.Application()
|
||||||
|
|
|
@ -19,11 +19,14 @@ from homeassistant.components.http.ban import (
|
||||||
setup_bans,
|
setup_bans,
|
||||||
)
|
)
|
||||||
from homeassistant.components.http.view import request_handler_factory
|
from homeassistant.components.http.view import request_handler_factory
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import mock_real_ip
|
from . import mock_real_ip
|
||||||
|
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
SUPERVISOR_IP = "1.2.3.4"
|
SUPERVISOR_IP = "1.2.3.4"
|
||||||
BANNED_IPS = ["200.201.202.203", "100.64.0.2"]
|
BANNED_IPS = ["200.201.202.203", "100.64.0.2"]
|
||||||
BANNED_IPS_WITH_SUPERVISOR = BANNED_IPS + [SUPERVISOR_IP]
|
BANNED_IPS_WITH_SUPERVISOR = BANNED_IPS + [SUPERVISOR_IP]
|
||||||
|
@ -49,7 +52,9 @@ def gethostbyaddr_mock():
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
async def test_access_from_banned_ip(hass, aiohttp_client):
|
async def test_access_from_banned_ip(
|
||||||
|
hass: HomeAssistant, aiohttp_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test accessing to server from banned IP. Both trusted and not."""
|
"""Test accessing to server from banned IP. Both trusted and not."""
|
||||||
app = web.Application()
|
app = web.Application()
|
||||||
app["hass"] = hass
|
app["hass"] = hass
|
||||||
|
@ -105,7 +110,9 @@ async def test_access_from_banned_ip_with_partially_broken_yaml_file(
|
||||||
assert "Failed to load IP ban" in caplog.text
|
assert "Failed to load IP ban" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_no_ip_bans_file(hass, aiohttp_client):
|
async def test_no_ip_bans_file(
|
||||||
|
hass: HomeAssistant, aiohttp_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test no ip bans file."""
|
"""Test no ip bans file."""
|
||||||
app = web.Application()
|
app = web.Application()
|
||||||
app["hass"] = hass
|
app["hass"] = hass
|
||||||
|
@ -123,7 +130,9 @@ async def test_no_ip_bans_file(hass, aiohttp_client):
|
||||||
assert resp.status == HTTPStatus.NOT_FOUND
|
assert resp.status == HTTPStatus.NOT_FOUND
|
||||||
|
|
||||||
|
|
||||||
async def test_failure_loading_ip_bans_file(hass, aiohttp_client):
|
async def test_failure_loading_ip_bans_file(
|
||||||
|
hass: HomeAssistant, aiohttp_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test failure loading ip bans file."""
|
"""Test failure loading ip bans file."""
|
||||||
app = web.Application()
|
app = web.Application()
|
||||||
app["hass"] = hass
|
app["hass"] = hass
|
||||||
|
@ -224,7 +233,7 @@ async def test_access_from_supervisor_ip(
|
||||||
assert len(manager.ip_bans_lookup) == bans
|
assert len(manager.ip_bans_lookup) == bans
|
||||||
|
|
||||||
|
|
||||||
async def test_ban_middleware_not_loaded_by_config(hass):
|
async def test_ban_middleware_not_loaded_by_config(hass: HomeAssistant) -> None:
|
||||||
"""Test accessing to server from banned IP when feature is off."""
|
"""Test accessing to server from banned IP when feature is off."""
|
||||||
with patch("homeassistant.components.http.setup_bans") as mock_setup:
|
with patch("homeassistant.components.http.setup_bans") as mock_setup:
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
|
@ -234,7 +243,7 @@ async def test_ban_middleware_not_loaded_by_config(hass):
|
||||||
assert len(mock_setup.mock_calls) == 0
|
assert len(mock_setup.mock_calls) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_ban_middleware_loaded_by_default(hass):
|
async def test_ban_middleware_loaded_by_default(hass: HomeAssistant) -> None:
|
||||||
"""Test accessing to server from banned IP when feature is off."""
|
"""Test accessing to server from banned IP when feature is off."""
|
||||||
with patch("homeassistant.components.http.setup_bans") as mock_setup:
|
with patch("homeassistant.components.http.setup_bans") as mock_setup:
|
||||||
await async_setup_component(hass, "http", {"http": {}})
|
await async_setup_component(hass, "http", {"http": {}})
|
||||||
|
@ -297,7 +306,9 @@ async def test_ip_bans_file_creation(hass, aiohttp_client, caplog):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_failed_login_attempts_counter(hass, aiohttp_client):
|
async def test_failed_login_attempts_counter(
|
||||||
|
hass: HomeAssistant, aiohttp_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Testing if failed login attempts counter increased."""
|
"""Testing if failed login attempts counter increased."""
|
||||||
app = web.Application()
|
app = web.Application()
|
||||||
app["hass"] = hass
|
app["hass"] = hass
|
||||||
|
|
|
@ -16,14 +16,17 @@ import pytest
|
||||||
|
|
||||||
from homeassistant.components.http.cors import setup_cors
|
from homeassistant.components.http.cors import setup_cors
|
||||||
from homeassistant.components.http.view import HomeAssistantView
|
from homeassistant.components.http.view import HomeAssistantView
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import HTTP_HEADER_HA_AUTH
|
from . import HTTP_HEADER_HA_AUTH
|
||||||
|
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
TRUSTED_ORIGIN = "https://home-assistant.io"
|
TRUSTED_ORIGIN = "https://home-assistant.io"
|
||||||
|
|
||||||
|
|
||||||
async def test_cors_middleware_loaded_by_default(hass):
|
async def test_cors_middleware_loaded_by_default(hass: HomeAssistant) -> None:
|
||||||
"""Test accessing to server from banned IP when feature is off."""
|
"""Test accessing to server from banned IP when feature is off."""
|
||||||
with patch("homeassistant.components.http.setup_cors") as mock_setup:
|
with patch("homeassistant.components.http.setup_cors") as mock_setup:
|
||||||
await async_setup_component(hass, "http", {"http": {}})
|
await async_setup_component(hass, "http", {"http": {}})
|
||||||
|
@ -31,7 +34,7 @@ async def test_cors_middleware_loaded_by_default(hass):
|
||||||
assert len(mock_setup.mock_calls) == 1
|
assert len(mock_setup.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_cors_middleware_loaded_from_config(hass):
|
async def test_cors_middleware_loaded_from_config(hass: HomeAssistant) -> None:
|
||||||
"""Test accessing to server from banned IP when feature is off."""
|
"""Test accessing to server from banned IP when feature is off."""
|
||||||
with patch("homeassistant.components.http.setup_cors") as mock_setup:
|
with patch("homeassistant.components.http.setup_cors") as mock_setup:
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
|
@ -101,7 +104,7 @@ async def test_cors_preflight_allowed(client):
|
||||||
assert req.headers[ACCESS_CONTROL_ALLOW_HEADERS] == "X-REQUESTED-WITH"
|
assert req.headers[ACCESS_CONTROL_ALLOW_HEADERS] == "X-REQUESTED-WITH"
|
||||||
|
|
||||||
|
|
||||||
async def test_cors_middleware_with_cors_allowed_view(hass):
|
async def test_cors_middleware_with_cors_allowed_view(hass: HomeAssistant) -> None:
|
||||||
"""Test that we can configure cors and have a cors_allowed view."""
|
"""Test that we can configure cors and have a cors_allowed view."""
|
||||||
|
|
||||||
class MyView(HomeAssistantView):
|
class MyView(HomeAssistantView):
|
||||||
|
@ -131,7 +134,9 @@ async def test_cors_middleware_with_cors_allowed_view(hass):
|
||||||
await hass.http.app.startup()
|
await hass.http.app.startup()
|
||||||
|
|
||||||
|
|
||||||
async def test_cors_works_with_frontend(hass, hass_client):
|
async def test_cors_works_with_frontend(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test CORS works with the frontend."""
|
"""Test CORS works with the frontend."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -143,7 +148,9 @@ async def test_cors_works_with_frontend(hass, hass_client):
|
||||||
assert resp.status == HTTPStatus.OK
|
assert resp.status == HTTPStatus.OK
|
||||||
|
|
||||||
|
|
||||||
async def test_cors_on_static_files(hass, hass_client):
|
async def test_cors_on_static_files(
|
||||||
|
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test that we enable CORS for static files."""
|
"""Test that we enable CORS for static files."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, "frontend", {"http": {"cors_allowed_origins": ["http://www.example.com"]}}
|
hass, "frontend", {"http": {"cors_allowed_origins": ["http://www.example.com"]}}
|
||||||
|
|
|
@ -9,6 +9,7 @@ from unittest.mock import Mock, patch
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import homeassistant.components.http as http
|
import homeassistant.components.http as http
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.network import NoURLAvailableError
|
from homeassistant.helpers.network import NoURLAvailableError
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
@ -103,7 +104,7 @@ async def test_not_log_password(hass, hass_client_no_auth, caplog, legacy_auth):
|
||||||
assert "some-pass" not in logs
|
assert "some-pass" not in logs
|
||||||
|
|
||||||
|
|
||||||
async def test_proxy_config(hass):
|
async def test_proxy_config(hass: HomeAssistant) -> None:
|
||||||
"""Test use_x_forwarded_for must config together with trusted_proxies."""
|
"""Test use_x_forwarded_for must config together with trusted_proxies."""
|
||||||
assert (
|
assert (
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
|
@ -120,7 +121,7 @@ async def test_proxy_config(hass):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_proxy_config_only_use_xff(hass):
|
async def test_proxy_config_only_use_xff(hass: HomeAssistant) -> None:
|
||||||
"""Test use_x_forwarded_for must config together with trusted_proxies."""
|
"""Test use_x_forwarded_for must config together with trusted_proxies."""
|
||||||
assert (
|
assert (
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
|
@ -130,7 +131,7 @@ async def test_proxy_config_only_use_xff(hass):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_proxy_config_only_trust_proxies(hass):
|
async def test_proxy_config_only_trust_proxies(hass: HomeAssistant) -> None:
|
||||||
"""Test use_x_forwarded_for must config together with trusted_proxies."""
|
"""Test use_x_forwarded_for must config together with trusted_proxies."""
|
||||||
assert (
|
assert (
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
|
@ -412,7 +413,7 @@ async def test_invalid_ssl_and_cannot_create_emergency_cert_with_ssl_peer_cert(
|
||||||
assert len(mock_builder.mock_calls) == 1
|
assert len(mock_builder.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_cors_defaults(hass):
|
async def test_cors_defaults(hass: HomeAssistant) -> None:
|
||||||
"""Test the CORS default settings."""
|
"""Test the CORS default settings."""
|
||||||
with patch("homeassistant.components.http.setup_cors") as mock_setup:
|
with patch("homeassistant.components.http.setup_cors") as mock_setup:
|
||||||
assert await async_setup_component(hass, "http", {})
|
assert await async_setup_component(hass, "http", {})
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""Tests for the Huawei LTE config flow."""
|
"""Tests for the Huawei LTE config flow."""
|
||||||
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from huawei_lte_api.enums.client import ResponseCodeEnum
|
from huawei_lte_api.enums.client import ResponseCodeEnum
|
||||||
|
@ -19,6 +18,7 @@ from homeassistant.const import (
|
||||||
CONF_URL,
|
CONF_URL,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ FIXTURE_USER_INPUT_OPTIONS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_show_set_form(hass):
|
async def test_show_set_form(hass: HomeAssistant) -> None:
|
||||||
"""Test that the setup form is served."""
|
"""Test that the setup form is served."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=None
|
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=None
|
||||||
|
@ -366,7 +366,7 @@ async def test_reauth(
|
||||||
assert entry.data[k] == v
|
assert entry.data[k] == v
|
||||||
|
|
||||||
|
|
||||||
async def test_options(hass):
|
async def test_options(hass: HomeAssistant) -> None:
|
||||||
"""Test options produce expected data."""
|
"""Test options produce expected data."""
|
||||||
|
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
|
|
|
@ -13,6 +13,7 @@ from homeassistant.components.hue.const import (
|
||||||
CONF_ALLOW_HUE_GROUPS,
|
CONF_ALLOW_HUE_GROUPS,
|
||||||
CONF_ALLOW_UNREACHABLE,
|
CONF_ALLOW_UNREACHABLE,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ async def test_bridge_setup_v2(hass, mock_api_v2):
|
||||||
assert forward_entries == {"light", "binary_sensor", "sensor", "switch", "scene"}
|
assert forward_entries == {"light", "binary_sensor", "sensor", "switch", "scene"}
|
||||||
|
|
||||||
|
|
||||||
async def test_bridge_setup_invalid_api_key(hass):
|
async def test_bridge_setup_invalid_api_key(hass: HomeAssistant) -> None:
|
||||||
"""Test we start config flow if username is no longer whitelisted."""
|
"""Test we start config flow if username is no longer whitelisted."""
|
||||||
entry = Mock()
|
entry = Mock()
|
||||||
entry.data = {"host": "1.2.3.4", "api_key": "mock-api-key", "api_version": 1}
|
entry.data = {"host": "1.2.3.4", "api_key": "mock-api-key", "api_version": 1}
|
||||||
|
@ -71,7 +72,7 @@ async def test_bridge_setup_invalid_api_key(hass):
|
||||||
assert mock_init.mock_calls[0][2]["data"] == {"host": "1.2.3.4"}
|
assert mock_init.mock_calls[0][2]["data"] == {"host": "1.2.3.4"}
|
||||||
|
|
||||||
|
|
||||||
async def test_bridge_setup_timeout(hass):
|
async def test_bridge_setup_timeout(hass: HomeAssistant) -> None:
|
||||||
"""Test we retry to connect if we cannot connect."""
|
"""Test we retry to connect if we cannot connect."""
|
||||||
entry = Mock()
|
entry = Mock()
|
||||||
entry.data = {"host": "1.2.3.4", "api_key": "mock-api-key", "api_version": 1}
|
entry.data = {"host": "1.2.3.4", "api_key": "mock-api-key", "api_version": 1}
|
||||||
|
|
|
@ -11,9 +11,11 @@ from homeassistant import config_entries
|
||||||
from homeassistant.components import zeroconf
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.components.hue import config_flow, const
|
from homeassistant.components.hue import config_flow, const
|
||||||
from homeassistant.components.hue.errors import CannotConnect
|
from homeassistant.components.hue.errors import CannotConnect
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="hue_setup", autouse=True)
|
@pytest.fixture(name="hue_setup", autouse=True)
|
||||||
|
@ -46,7 +48,7 @@ def create_mock_api_discovery(aioclient_mock, bridges):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_works(hass):
|
async def test_flow_works(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow ."""
|
"""Test config flow ."""
|
||||||
disc_bridge = get_discovered_bridge(supports_v2=True)
|
disc_bridge = get_discovered_bridge(supports_v2=True)
|
||||||
|
|
||||||
|
@ -89,7 +91,7 @@ async def test_flow_works(hass):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_manual_flow_works(hass):
|
async def test_manual_flow_works(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow discovers only already configured bridges."""
|
"""Test config flow discovers only already configured bridges."""
|
||||||
disc_bridge = get_discovered_bridge(bridge_id="id-1234", host="2.2.2.2")
|
disc_bridge = get_discovered_bridge(bridge_id="id-1234", host="2.2.2.2")
|
||||||
|
|
||||||
|
@ -141,7 +143,7 @@ async def test_manual_flow_works(hass):
|
||||||
assert entry.unique_id == "id-1234"
|
assert entry.unique_id == "id-1234"
|
||||||
|
|
||||||
|
|
||||||
async def test_manual_flow_bridge_exist(hass):
|
async def test_manual_flow_bridge_exist(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow aborts on already configured bridges."""
|
"""Test config flow aborts on already configured bridges."""
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
domain="hue", unique_id="id-1234", data={"host": "2.2.2.2"}
|
domain="hue", unique_id="id-1234", data={"host": "2.2.2.2"}
|
||||||
|
@ -166,7 +168,9 @@ async def test_manual_flow_bridge_exist(hass):
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_manual_flow_no_discovered_bridges(hass, aioclient_mock):
|
async def test_manual_flow_no_discovered_bridges(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test config flow discovers no bridges."""
|
"""Test config flow discovers no bridges."""
|
||||||
create_mock_api_discovery(aioclient_mock, [])
|
create_mock_api_discovery(aioclient_mock, [])
|
||||||
|
|
||||||
|
@ -177,7 +181,9 @@ async def test_manual_flow_no_discovered_bridges(hass, aioclient_mock):
|
||||||
assert result["step_id"] == "manual"
|
assert result["step_id"] == "manual"
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_all_discovered_bridges_exist(hass, aioclient_mock):
|
async def test_flow_all_discovered_bridges_exist(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test config flow discovers only already configured bridges."""
|
"""Test config flow discovers only already configured bridges."""
|
||||||
mock_host = "1.2.3.4"
|
mock_host = "1.2.3.4"
|
||||||
mock_id = "bla"
|
mock_id = "bla"
|
||||||
|
@ -195,7 +201,9 @@ async def test_flow_all_discovered_bridges_exist(hass, aioclient_mock):
|
||||||
assert result["step_id"] == "manual"
|
assert result["step_id"] == "manual"
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_bridges_discovered(hass, aioclient_mock):
|
async def test_flow_bridges_discovered(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test config flow discovers two bridges."""
|
"""Test config flow discovers two bridges."""
|
||||||
# Add ignored config entry. Should still show up as option.
|
# Add ignored config entry. Should still show up as option.
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
|
@ -220,7 +228,9 @@ async def test_flow_bridges_discovered(hass, aioclient_mock):
|
||||||
result["data_schema"]({"id": "manual"})
|
result["data_schema"]({"id": "manual"})
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_two_bridges_discovered_one_new(hass, aioclient_mock):
|
async def test_flow_two_bridges_discovered_one_new(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test config flow discovers two bridges."""
|
"""Test config flow discovers two bridges."""
|
||||||
create_mock_api_discovery(aioclient_mock, [("1.2.3.4", "bla"), ("5.6.7.8", "beer")])
|
create_mock_api_discovery(aioclient_mock, [("1.2.3.4", "bla"), ("5.6.7.8", "beer")])
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
|
@ -239,7 +249,7 @@ async def test_flow_two_bridges_discovered_one_new(hass, aioclient_mock):
|
||||||
assert not result["data_schema"]({"id": "bla"})
|
assert not result["data_schema"]({"id": "bla"})
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_timeout_discovery(hass):
|
async def test_flow_timeout_discovery(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow ."""
|
"""Test config flow ."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.hue.config_flow.discover_nupnp",
|
"homeassistant.components.hue.config_flow.discover_nupnp",
|
||||||
|
@ -253,7 +263,7 @@ async def test_flow_timeout_discovery(hass):
|
||||||
assert result["reason"] == "discover_timeout"
|
assert result["reason"] == "discover_timeout"
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_link_unknown_error(hass):
|
async def test_flow_link_unknown_error(hass: HomeAssistant) -> None:
|
||||||
"""Test if a unknown error happened during the linking processes."""
|
"""Test if a unknown error happened during the linking processes."""
|
||||||
disc_bridge = get_discovered_bridge()
|
disc_bridge = get_discovered_bridge()
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -278,7 +288,7 @@ async def test_flow_link_unknown_error(hass):
|
||||||
assert result["errors"] == {"base": "linking"}
|
assert result["errors"] == {"base": "linking"}
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_link_button_not_pressed(hass):
|
async def test_flow_link_button_not_pressed(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow ."""
|
"""Test config flow ."""
|
||||||
disc_bridge = get_discovered_bridge()
|
disc_bridge = get_discovered_bridge()
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -303,7 +313,7 @@ async def test_flow_link_button_not_pressed(hass):
|
||||||
assert result["errors"] == {"base": "register_failed"}
|
assert result["errors"] == {"base": "register_failed"}
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_link_cannot_connect(hass):
|
async def test_flow_link_cannot_connect(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow ."""
|
"""Test config flow ."""
|
||||||
disc_bridge = get_discovered_bridge()
|
disc_bridge = get_discovered_bridge()
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -327,7 +337,9 @@ async def test_flow_link_cannot_connect(hass):
|
||||||
assert result["reason"] == "cannot_connect"
|
assert result["reason"] == "cannot_connect"
|
||||||
|
|
||||||
|
|
||||||
async def test_import_with_no_config(hass, aioclient_mock):
|
async def test_import_with_no_config(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test importing a host without an existing config file."""
|
"""Test importing a host without an existing config file."""
|
||||||
create_mock_api_discovery(aioclient_mock, [("0.0.0.0", "1234")])
|
create_mock_api_discovery(aioclient_mock, [("0.0.0.0", "1234")])
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -394,7 +406,9 @@ async def test_creating_entry_removes_entries_for_same_host_or_bridge(
|
||||||
assert new_entry.unique_id == "id-1234"
|
assert new_entry.unique_id == "id-1234"
|
||||||
|
|
||||||
|
|
||||||
async def test_bridge_homekit(hass, aioclient_mock):
|
async def test_bridge_homekit(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test a bridge being discovered via HomeKit."""
|
"""Test a bridge being discovered via HomeKit."""
|
||||||
create_mock_api_discovery(aioclient_mock, [("0.0.0.0", "bla")])
|
create_mock_api_discovery(aioclient_mock, [("0.0.0.0", "bla")])
|
||||||
|
|
||||||
|
@ -423,7 +437,7 @@ async def test_bridge_homekit(hass, aioclient_mock):
|
||||||
assert flow["context"]["unique_id"] == config_entries.DEFAULT_DISCOVERY_UNIQUE_ID
|
assert flow["context"]["unique_id"] == config_entries.DEFAULT_DISCOVERY_UNIQUE_ID
|
||||||
|
|
||||||
|
|
||||||
async def test_bridge_import_already_configured(hass):
|
async def test_bridge_import_already_configured(hass: HomeAssistant) -> None:
|
||||||
"""Test if a import flow aborts if host is already configured."""
|
"""Test if a import flow aborts if host is already configured."""
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
domain="hue", unique_id="aabbccddeeff", data={"host": "0.0.0.0"}
|
domain="hue", unique_id="aabbccddeeff", data={"host": "0.0.0.0"}
|
||||||
|
@ -439,7 +453,9 @@ async def test_bridge_import_already_configured(hass):
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_bridge_homekit_already_configured(hass, aioclient_mock):
|
async def test_bridge_homekit_already_configured(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test if a HomeKit discovered bridge has already been configured."""
|
"""Test if a HomeKit discovered bridge has already been configured."""
|
||||||
create_mock_api_discovery(aioclient_mock, [("0.0.0.0", "aabbccddeeff")])
|
create_mock_api_discovery(aioclient_mock, [("0.0.0.0", "aabbccddeeff")])
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
|
@ -464,7 +480,7 @@ async def test_bridge_homekit_already_configured(hass, aioclient_mock):
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_options_flow_v1(hass):
|
async def test_options_flow_v1(hass: HomeAssistant) -> None:
|
||||||
"""Test options config flow for a V1 bridge."""
|
"""Test options config flow for a V1 bridge."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain="hue",
|
domain="hue",
|
||||||
|
@ -510,7 +526,7 @@ def _get_schema_default(schema, key_name):
|
||||||
raise KeyError(f"{key_name} not found in schema")
|
raise KeyError(f"{key_name} not found in schema")
|
||||||
|
|
||||||
|
|
||||||
async def test_options_flow_v2(hass):
|
async def test_options_flow_v2(hass: HomeAssistant) -> None:
|
||||||
"""Test options config flow for a V2 bridge."""
|
"""Test options config flow for a V2 bridge."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain="hue",
|
domain="hue",
|
||||||
|
@ -543,7 +559,9 @@ async def test_options_flow_v2(hass):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_bridge_zeroconf(hass, aioclient_mock):
|
async def test_bridge_zeroconf(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test a bridge being discovered."""
|
"""Test a bridge being discovered."""
|
||||||
create_mock_api_discovery(aioclient_mock, [("192.168.1.217", "ecb5fafffeabcabc")])
|
create_mock_api_discovery(aioclient_mock, [("192.168.1.217", "ecb5fafffeabcabc")])
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -568,7 +586,9 @@ async def test_bridge_zeroconf(hass, aioclient_mock):
|
||||||
assert result["step_id"] == "link"
|
assert result["step_id"] == "link"
|
||||||
|
|
||||||
|
|
||||||
async def test_bridge_zeroconf_already_exists(hass, aioclient_mock):
|
async def test_bridge_zeroconf_already_exists(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test a bridge being discovered by zeroconf already exists."""
|
"""Test a bridge being discovered by zeroconf already exists."""
|
||||||
create_mock_api_discovery(
|
create_mock_api_discovery(
|
||||||
aioclient_mock, [("0.0.0.0", "ecb5faabcabc"), ("192.168.1.217", "ecb5faabcabc")]
|
aioclient_mock, [("0.0.0.0", "ecb5faabcabc"), ("192.168.1.217", "ecb5faabcabc")]
|
||||||
|
@ -603,7 +623,7 @@ async def test_bridge_zeroconf_already_exists(hass, aioclient_mock):
|
||||||
assert entry.data["host"] == "192.168.1.217"
|
assert entry.data["host"] == "192.168.1.217"
|
||||||
|
|
||||||
|
|
||||||
async def test_bridge_zeroconf_ipv6(hass):
|
async def test_bridge_zeroconf_ipv6(hass: HomeAssistant) -> None:
|
||||||
"""Test a bridge being discovered by zeroconf and ipv6 address."""
|
"""Test a bridge being discovered by zeroconf and ipv6 address."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
const.DOMAIN,
|
const.DOMAIN,
|
||||||
|
|
|
@ -6,6 +6,7 @@ import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components import hue
|
from homeassistant.components import hue
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
@ -32,7 +33,7 @@ def mock_bridge_setup():
|
||||||
yield mock_bridge.return_value
|
yield mock_bridge.return_value
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_with_no_config(hass):
|
async def test_setup_with_no_config(hass: HomeAssistant) -> None:
|
||||||
"""Test that we do not discover anything or try to set up a bridge."""
|
"""Test that we do not discover anything or try to set up a bridge."""
|
||||||
assert await async_setup_component(hass, hue.DOMAIN, {}) is True
|
assert await async_setup_component(hass, hue.DOMAIN, {}) is True
|
||||||
|
|
||||||
|
@ -125,7 +126,7 @@ async def test_fixing_unique_id_other_correct(hass, mock_bridge_setup):
|
||||||
assert hass.config_entries.async_entries() == [correct_entry]
|
assert hass.config_entries.async_entries() == [correct_entry]
|
||||||
|
|
||||||
|
|
||||||
async def test_security_vuln_check(hass):
|
async def test_security_vuln_check(hass: HomeAssistant) -> None:
|
||||||
"""Test that we report security vulnerabilities."""
|
"""Test that we report security vulnerabilities."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=hue.DOMAIN, data={"host": "0.0.0.0", "api_version": 1}
|
domain=hue.DOMAIN, data={"host": "0.0.0.0", "api_version": 1}
|
||||||
|
|
|
@ -2,12 +2,13 @@
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.components import hue
|
from homeassistant.components import hue
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_migrate_api_key(hass):
|
async def test_migrate_api_key(hass: HomeAssistant) -> None:
|
||||||
"""Test if username gets migrated to api_key."""
|
"""Test if username gets migrated to api_key."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=hue.DOMAIN,
|
domain=hue.DOMAIN,
|
||||||
|
@ -22,7 +23,7 @@ async def test_migrate_api_key(hass):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_auto_switchover(hass):
|
async def test_auto_switchover(hass: HomeAssistant) -> None:
|
||||||
"""Test if config entry from v1 automatically switches to v2."""
|
"""Test if config entry from v1 automatically switches to v2."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=hue.DOMAIN,
|
domain=hue.DOMAIN,
|
||||||
|
|
|
@ -9,11 +9,12 @@ from energyflip import (
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow
|
from homeassistant import config_entries, data_entry_flow
|
||||||
from homeassistant.components.huisbaasje.const import DOMAIN
|
from homeassistant.components.huisbaasje.const import DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_form(hass):
|
async def test_form(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -55,7 +56,7 @@ async def test_form(hass):
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_form_invalid_auth(hass):
|
async def test_form_invalid_auth(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle invalid auth."""
|
"""Test we handle invalid auth."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -77,7 +78,7 @@ async def test_form_invalid_auth(hass):
|
||||||
assert form_result["errors"] == {"base": "invalid_auth"}
|
assert form_result["errors"] == {"base": "invalid_auth"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_authenticate_cannot_connect(hass):
|
async def test_form_authenticate_cannot_connect(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle cannot connect error in authenticate."""
|
"""Test we handle cannot connect error in authenticate."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -99,7 +100,7 @@ async def test_form_authenticate_cannot_connect(hass):
|
||||||
assert form_result["errors"] == {"base": "cannot_connect"}
|
assert form_result["errors"] == {"base": "cannot_connect"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_authenticate_unknown_error(hass):
|
async def test_form_authenticate_unknown_error(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle an unknown error in authenticate."""
|
"""Test we handle an unknown error in authenticate."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -121,7 +122,7 @@ async def test_form_authenticate_unknown_error(hass):
|
||||||
assert form_result["errors"] == {"base": "unknown"}
|
assert form_result["errors"] == {"base": "unknown"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_customer_overview_cannot_connect(hass):
|
async def test_form_customer_overview_cannot_connect(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle cannot connect error in customer_overview."""
|
"""Test we handle cannot connect error in customer_overview."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -143,7 +144,7 @@ async def test_form_customer_overview_cannot_connect(hass):
|
||||||
assert form_result["errors"] == {"base": "cannot_connect"}
|
assert form_result["errors"] == {"base": "cannot_connect"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_customer_overview_authentication_error(hass):
|
async def test_form_customer_overview_authentication_error(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle an unknown error in customer_overview."""
|
"""Test we handle an unknown error in customer_overview."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -165,7 +166,7 @@ async def test_form_customer_overview_authentication_error(hass):
|
||||||
assert form_result["errors"] == {"base": "invalid_auth"}
|
assert form_result["errors"] == {"base": "invalid_auth"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_customer_overview_unknown_error(hass):
|
async def test_form_customer_overview_unknown_error(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle an unknown error in customer_overview."""
|
"""Test we handle an unknown error in customer_overview."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -187,7 +188,7 @@ async def test_form_customer_overview_unknown_error(hass):
|
||||||
assert form_result["errors"] == {"base": "unknown"}
|
assert form_result["errors"] == {"base": "unknown"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_entry_exists(hass):
|
async def test_form_entry_exists(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle an already existing entry."""
|
"""Test we handle an already existing entry."""
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
unique_id="test-id",
|
unique_id="test-id",
|
||||||
|
|
|
@ -6,6 +6,7 @@ import homeassistant.components.automation as automation
|
||||||
from homeassistant.components.device_automation import DeviceAutomationType
|
from homeassistant.components.device_automation import DeviceAutomationType
|
||||||
from homeassistant.components.humidifier import DOMAIN, const, device_action
|
from homeassistant.components.humidifier import DOMAIN, const, device_action
|
||||||
from homeassistant.const import STATE_ON
|
from homeassistant.const import STATE_ON
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv, device_registry
|
from homeassistant.helpers import config_validation as cv, device_registry
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
from homeassistant.helpers.entity_registry import RegistryEntryHider
|
from homeassistant.helpers.entity_registry import RegistryEntryHider
|
||||||
|
@ -147,7 +148,7 @@ async def test_get_actions_hidden_auxiliary(
|
||||||
assert_lists_same(actions, expected_actions)
|
assert_lists_same(actions, expected_actions)
|
||||||
|
|
||||||
|
|
||||||
async def test_action(hass):
|
async def test_action(hass: HomeAssistant) -> None:
|
||||||
"""Test for actions."""
|
"""Test for actions."""
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
"humidifier.entity",
|
"humidifier.entity",
|
||||||
|
|
|
@ -8,6 +8,7 @@ import homeassistant.components.automation as automation
|
||||||
from homeassistant.components.device_automation import DeviceAutomationType
|
from homeassistant.components.device_automation import DeviceAutomationType
|
||||||
from homeassistant.components.humidifier import DOMAIN, const, device_trigger
|
from homeassistant.components.humidifier import DOMAIN, const, device_trigger
|
||||||
from homeassistant.const import ATTR_MODE, ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON
|
from homeassistant.const import ATTR_MODE, ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv, device_registry
|
from homeassistant.helpers import config_validation as cv, device_registry
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
from homeassistant.helpers.entity_registry import RegistryEntryHider
|
from homeassistant.helpers.entity_registry import RegistryEntryHider
|
||||||
|
@ -357,7 +358,7 @@ async def test_invalid_config(hass, calls):
|
||||||
assert len(calls) == 0
|
assert len(calls) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_get_trigger_capabilities_on(hass):
|
async def test_get_trigger_capabilities_on(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the expected capabilities from a humidifier trigger."""
|
"""Test we get the expected capabilities from a humidifier trigger."""
|
||||||
capabilities = await device_trigger.async_get_trigger_capabilities(
|
capabilities = await device_trigger.async_get_trigger_capabilities(
|
||||||
hass,
|
hass,
|
||||||
|
@ -377,7 +378,7 @@ async def test_get_trigger_capabilities_on(hass):
|
||||||
) == [{"name": "for", "optional": True, "type": "positive_time_period_dict"}]
|
) == [{"name": "for", "optional": True, "type": "positive_time_period_dict"}]
|
||||||
|
|
||||||
|
|
||||||
async def test_get_trigger_capabilities_off(hass):
|
async def test_get_trigger_capabilities_off(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the expected capabilities from a humidifier trigger."""
|
"""Test we get the expected capabilities from a humidifier trigger."""
|
||||||
capabilities = await device_trigger.async_get_trigger_capabilities(
|
capabilities = await device_trigger.async_get_trigger_capabilities(
|
||||||
hass,
|
hass,
|
||||||
|
@ -397,7 +398,7 @@ async def test_get_trigger_capabilities_off(hass):
|
||||||
) == [{"name": "for", "optional": True, "type": "positive_time_period_dict"}]
|
) == [{"name": "for", "optional": True, "type": "positive_time_period_dict"}]
|
||||||
|
|
||||||
|
|
||||||
async def test_get_trigger_capabilities_humidity(hass):
|
async def test_get_trigger_capabilities_humidity(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the expected capabilities from a humidifier trigger."""
|
"""Test we get the expected capabilities from a humidifier trigger."""
|
||||||
capabilities = await device_trigger.async_get_trigger_capabilities(
|
capabilities = await device_trigger.async_get_trigger_capabilities(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
from homeassistant.components.humidifier import HumidifierEntity
|
from homeassistant.components.humidifier import HumidifierEntity
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
|
||||||
class MockHumidifierEntity(HumidifierEntity):
|
class MockHumidifierEntity(HumidifierEntity):
|
||||||
|
@ -13,7 +14,7 @@ class MockHumidifierEntity(HumidifierEntity):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
async def test_sync_turn_on(hass):
|
async def test_sync_turn_on(hass: HomeAssistant) -> None:
|
||||||
"""Test if async turn_on calls sync turn_on."""
|
"""Test if async turn_on calls sync turn_on."""
|
||||||
humidifier = MockHumidifierEntity()
|
humidifier = MockHumidifierEntity()
|
||||||
humidifier.hass = hass
|
humidifier.hass = hass
|
||||||
|
@ -24,7 +25,7 @@ async def test_sync_turn_on(hass):
|
||||||
assert humidifier.turn_on.called
|
assert humidifier.turn_on.called
|
||||||
|
|
||||||
|
|
||||||
async def test_sync_turn_off(hass):
|
async def test_sync_turn_off(hass: HomeAssistant) -> None:
|
||||||
"""Test if async turn_off calls sync turn_off."""
|
"""Test if async turn_off calls sync turn_off."""
|
||||||
humidifier = MockHumidifierEntity()
|
humidifier = MockHumidifierEntity()
|
||||||
humidifier.hass = hass
|
humidifier.hass = hass
|
||||||
|
|
|
@ -17,12 +17,13 @@ from homeassistant.const import (
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.intent import IntentHandleError, async_handle
|
from homeassistant.helpers.intent import IntentHandleError, async_handle
|
||||||
|
|
||||||
from tests.common import async_mock_service
|
from tests.common import async_mock_service
|
||||||
|
|
||||||
|
|
||||||
async def test_intent_set_humidity(hass):
|
async def test_intent_set_humidity(hass: HomeAssistant) -> None:
|
||||||
"""Test the set humidity intent."""
|
"""Test the set humidity intent."""
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
"humidifier.bedroom_humidifier", STATE_ON, {ATTR_HUMIDITY: 40}
|
"humidifier.bedroom_humidifier", STATE_ON, {ATTR_HUMIDITY: 40}
|
||||||
|
@ -50,7 +51,7 @@ async def test_intent_set_humidity(hass):
|
||||||
assert call.data.get(ATTR_HUMIDITY) == 50
|
assert call.data.get(ATTR_HUMIDITY) == 50
|
||||||
|
|
||||||
|
|
||||||
async def test_intent_set_humidity_and_turn_on(hass):
|
async def test_intent_set_humidity_and_turn_on(hass: HomeAssistant) -> None:
|
||||||
"""Test the set humidity intent for turned off humidifier."""
|
"""Test the set humidity intent for turned off humidifier."""
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
"humidifier.bedroom_humidifier", STATE_OFF, {ATTR_HUMIDITY: 40}
|
"humidifier.bedroom_humidifier", STATE_OFF, {ATTR_HUMIDITY: 40}
|
||||||
|
@ -85,7 +86,7 @@ async def test_intent_set_humidity_and_turn_on(hass):
|
||||||
assert call.data.get(ATTR_HUMIDITY) == 50
|
assert call.data.get(ATTR_HUMIDITY) == 50
|
||||||
|
|
||||||
|
|
||||||
async def test_intent_set_mode(hass):
|
async def test_intent_set_mode(hass: HomeAssistant) -> None:
|
||||||
"""Test the set mode intent."""
|
"""Test the set mode intent."""
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
"humidifier.bedroom_humidifier",
|
"humidifier.bedroom_humidifier",
|
||||||
|
@ -123,7 +124,7 @@ async def test_intent_set_mode(hass):
|
||||||
assert call.data.get(ATTR_MODE) == "away"
|
assert call.data.get(ATTR_MODE) == "away"
|
||||||
|
|
||||||
|
|
||||||
async def test_intent_set_mode_and_turn_on(hass):
|
async def test_intent_set_mode_and_turn_on(hass: HomeAssistant) -> None:
|
||||||
"""Test the set mode intent."""
|
"""Test the set mode intent."""
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
"humidifier.bedroom_humidifier",
|
"humidifier.bedroom_humidifier",
|
||||||
|
@ -165,7 +166,7 @@ async def test_intent_set_mode_and_turn_on(hass):
|
||||||
assert call.data.get(ATTR_MODE) == "away"
|
assert call.data.get(ATTR_MODE) == "away"
|
||||||
|
|
||||||
|
|
||||||
async def test_intent_set_mode_tests_feature(hass):
|
async def test_intent_set_mode_tests_feature(hass: HomeAssistant) -> None:
|
||||||
"""Test the set mode intent where modes are not supported."""
|
"""Test the set mode intent where modes are not supported."""
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
"humidifier.bedroom_humidifier", STATE_ON, {ATTR_HUMIDITY: 40}
|
"humidifier.bedroom_humidifier", STATE_ON, {ATTR_HUMIDITY: 40}
|
||||||
|
@ -187,7 +188,7 @@ async def test_intent_set_mode_tests_feature(hass):
|
||||||
assert len(mode_calls) == 0
|
assert len(mode_calls) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_intent_set_unknown_mode(hass):
|
async def test_intent_set_unknown_mode(hass: HomeAssistant) -> None:
|
||||||
"""Test the set mode intent for unsupported mode."""
|
"""Test the set mode intent for unsupported mode."""
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
"humidifier.bedroom_humidifier",
|
"humidifier.bedroom_humidifier",
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The tests for reproduction of state."""
|
"""The tests for reproduction of state."""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.humidifier.const import (
|
from homeassistant.components.humidifier.const import (
|
||||||
|
@ -19,7 +18,7 @@ from homeassistant.const import (
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
)
|
)
|
||||||
from homeassistant.core import Context, State
|
from homeassistant.core import Context, HomeAssistant, State
|
||||||
from homeassistant.helpers.state import async_reproduce_state
|
from homeassistant.helpers.state import async_reproduce_state
|
||||||
|
|
||||||
from tests.common import async_mock_service
|
from tests.common import async_mock_service
|
||||||
|
@ -28,7 +27,9 @@ ENTITY_1 = "humidifier.test1"
|
||||||
ENTITY_2 = "humidifier.test2"
|
ENTITY_2 = "humidifier.test2"
|
||||||
|
|
||||||
|
|
||||||
async def test_reproducing_on_off_states(hass, caplog):
|
async def test_reproducing_on_off_states(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test reproducing humidifier states."""
|
"""Test reproducing humidifier states."""
|
||||||
hass.states.async_set(ENTITY_1, "off", {ATTR_MODE: MODE_NORMAL, ATTR_HUMIDITY: 45})
|
hass.states.async_set(ENTITY_1, "off", {ATTR_MODE: MODE_NORMAL, ATTR_HUMIDITY: 45})
|
||||||
hass.states.async_set(ENTITY_2, "on", {ATTR_MODE: MODE_NORMAL, ATTR_HUMIDITY: 45})
|
hass.states.async_set(ENTITY_2, "on", {ATTR_MODE: MODE_NORMAL, ATTR_HUMIDITY: 45})
|
||||||
|
@ -85,7 +86,7 @@ async def test_reproducing_on_off_states(hass, caplog):
|
||||||
assert len(humidity_calls) == 0
|
assert len(humidity_calls) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_multiple_attrs(hass):
|
async def test_multiple_attrs(hass: HomeAssistant) -> None:
|
||||||
"""Test turn on with multiple attributes."""
|
"""Test turn on with multiple attributes."""
|
||||||
hass.states.async_set(ENTITY_1, STATE_OFF, {})
|
hass.states.async_set(ENTITY_1, STATE_OFF, {})
|
||||||
|
|
||||||
|
@ -109,7 +110,7 @@ async def test_multiple_attrs(hass):
|
||||||
assert humidity_calls[0].data == {"entity_id": ENTITY_1, "humidity": 45}
|
assert humidity_calls[0].data == {"entity_id": ENTITY_1, "humidity": 45}
|
||||||
|
|
||||||
|
|
||||||
async def test_turn_off_multiple_attrs(hass):
|
async def test_turn_off_multiple_attrs(hass: HomeAssistant) -> None:
|
||||||
"""Test set mode and humidity for off state."""
|
"""Test set mode and humidity for off state."""
|
||||||
hass.states.async_set(ENTITY_1, STATE_ON, {})
|
hass.states.async_set(ENTITY_1, STATE_ON, {})
|
||||||
|
|
||||||
|
@ -131,7 +132,7 @@ async def test_turn_off_multiple_attrs(hass):
|
||||||
assert len(humidity_calls) == 0
|
assert len(humidity_calls) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_multiple_modes(hass):
|
async def test_multiple_modes(hass: HomeAssistant) -> None:
|
||||||
"""Test that multiple states gets calls."""
|
"""Test that multiple states gets calls."""
|
||||||
hass.states.async_set(ENTITY_1, STATE_OFF, {})
|
hass.states.async_set(ENTITY_1, STATE_OFF, {})
|
||||||
hass.states.async_set(ENTITY_2, STATE_OFF, {})
|
hass.states.async_set(ENTITY_2, STATE_OFF, {})
|
||||||
|
@ -171,7 +172,7 @@ async def test_multiple_modes(hass):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_state_with_none(hass):
|
async def test_state_with_none(hass: HomeAssistant) -> None:
|
||||||
"""Test that none is not a humidifier state."""
|
"""Test that none is not a humidifier state."""
|
||||||
hass.states.async_set(ENTITY_1, STATE_OFF, {})
|
hass.states.async_set(ENTITY_1, STATE_OFF, {})
|
||||||
|
|
||||||
|
@ -190,7 +191,7 @@ async def test_state_with_none(hass):
|
||||||
assert len(humidity_calls) == 0
|
assert len(humidity_calls) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_state_with_context(hass):
|
async def test_state_with_context(hass: HomeAssistant) -> None:
|
||||||
"""Test that context is forwarded."""
|
"""Test that context is forwarded."""
|
||||||
hass.states.async_set(ENTITY_1, STATE_OFF, {})
|
hass.states.async_set(ENTITY_1, STATE_OFF, {})
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import pytest
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components import dhcp, zeroconf
|
from homeassistant.components import dhcp, zeroconf
|
||||||
from homeassistant.components.hunterdouglas_powerview.const import DOMAIN
|
from homeassistant.components.hunterdouglas_powerview.const import DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, load_fixture
|
from tests.common import MockConfigEntry, load_fixture
|
||||||
|
|
||||||
|
@ -85,7 +86,7 @@ def _get_mock_powerview_fwversion(fwversion=None, get_resources=None):
|
||||||
return mock_powerview_fwversion
|
return mock_powerview_fwversion
|
||||||
|
|
||||||
|
|
||||||
async def test_user_form(hass):
|
async def test_user_form(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the user form."""
|
"""Test we get the user form."""
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -128,7 +129,7 @@ async def test_user_form(hass):
|
||||||
assert result4["type"] == "abort"
|
assert result4["type"] == "abort"
|
||||||
|
|
||||||
|
|
||||||
async def test_user_form_legacy(hass):
|
async def test_user_form_legacy(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the user form with a legacy device."""
|
"""Test we get the user form with a legacy device."""
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -254,7 +255,7 @@ async def test_form_homekit_and_dhcp(hass, source, discovery_info):
|
||||||
assert result3["type"] == "abort"
|
assert result3["type"] == "abort"
|
||||||
|
|
||||||
|
|
||||||
async def test_discovered_by_homekit_and_dhcp(hass):
|
async def test_discovered_by_homekit_and_dhcp(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the form with homekit and abort for dhcp source when we get both."""
|
"""Test we get the form with homekit and abort for dhcp source when we get both."""
|
||||||
|
|
||||||
mock_powerview_userdata = _get_mock_powerview_userdata()
|
mock_powerview_userdata = _get_mock_powerview_userdata()
|
||||||
|
@ -285,7 +286,7 @@ async def test_discovered_by_homekit_and_dhcp(hass):
|
||||||
assert result2["reason"] == "already_in_progress"
|
assert result2["reason"] == "already_in_progress"
|
||||||
|
|
||||||
|
|
||||||
async def test_form_cannot_connect(hass):
|
async def test_form_cannot_connect(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle cannot connect error."""
|
"""Test we handle cannot connect error."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -307,7 +308,7 @@ async def test_form_cannot_connect(hass):
|
||||||
assert result2["errors"] == {"base": "cannot_connect"}
|
assert result2["errors"] == {"base": "cannot_connect"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_no_data(hass):
|
async def test_form_no_data(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle no data being returned from the hub."""
|
"""Test we handle no data being returned from the hub."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -327,7 +328,7 @@ async def test_form_no_data(hass):
|
||||||
assert result2["errors"] == {"base": "unknown"}
|
assert result2["errors"] == {"base": "unknown"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_unknown_exception(hass):
|
async def test_form_unknown_exception(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle unknown exception."""
|
"""Test we handle unknown exception."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
|
|
@ -13,6 +13,7 @@ from homeassistant.components.hvv_departures.const import (
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import SOURCE_USER
|
from homeassistant.config_entries import SOURCE_USER
|
||||||
from homeassistant.const import CONF_HOST, CONF_OFFSET, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_OFFSET, CONF_PASSWORD, CONF_USERNAME
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, load_fixture
|
from tests.common import MockConfigEntry, load_fixture
|
||||||
|
|
||||||
|
@ -26,7 +27,7 @@ FIXTURE_OPTIONS = json.loads(load_fixture("hvv_departures/options.json"))
|
||||||
FIXTURE_DEPARTURE_LIST = json.loads(load_fixture("hvv_departures/departure_list.json"))
|
FIXTURE_DEPARTURE_LIST = json.loads(load_fixture("hvv_departures/departure_list.json"))
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow(hass):
|
async def test_user_flow(hass: HomeAssistant) -> None:
|
||||||
"""Test that config flow works."""
|
"""Test that config flow works."""
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -89,7 +90,7 @@ async def test_user_flow(hass):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_no_results(hass):
|
async def test_user_flow_no_results(hass: HomeAssistant) -> None:
|
||||||
"""Test that config flow works when there are no results."""
|
"""Test that config flow works when there are no results."""
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -126,7 +127,7 @@ async def test_user_flow_no_results(hass):
|
||||||
assert result_station["errors"]["base"] == "no_results"
|
assert result_station["errors"]["base"] == "no_results"
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_invalid_auth(hass):
|
async def test_user_flow_invalid_auth(hass: HomeAssistant) -> None:
|
||||||
"""Test that config flow handles invalid auth."""
|
"""Test that config flow handles invalid auth."""
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -152,7 +153,7 @@ async def test_user_flow_invalid_auth(hass):
|
||||||
assert result_user["errors"] == {"base": "invalid_auth"}
|
assert result_user["errors"] == {"base": "invalid_auth"}
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_cannot_connect(hass):
|
async def test_user_flow_cannot_connect(hass: HomeAssistant) -> None:
|
||||||
"""Test that config flow handles connection errors."""
|
"""Test that config flow handles connection errors."""
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -174,7 +175,7 @@ async def test_user_flow_cannot_connect(hass):
|
||||||
assert result_user["errors"] == {"base": "cannot_connect"}
|
assert result_user["errors"] == {"base": "cannot_connect"}
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_station(hass):
|
async def test_user_flow_station(hass: HomeAssistant) -> None:
|
||||||
"""Test that config flow handles empty data on step station."""
|
"""Test that config flow handles empty data on step station."""
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -207,7 +208,7 @@ async def test_user_flow_station(hass):
|
||||||
assert result_station["step_id"] == "station"
|
assert result_station["step_id"] == "station"
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow_station_select(hass):
|
async def test_user_flow_station_select(hass: HomeAssistant) -> None:
|
||||||
"""Test that config flow handles empty data on step station_select."""
|
"""Test that config flow handles empty data on step station_select."""
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -242,7 +243,7 @@ async def test_user_flow_station_select(hass):
|
||||||
assert result_station_select["step_id"] == "station_select"
|
assert result_station_select["step_id"] == "station_select"
|
||||||
|
|
||||||
|
|
||||||
async def test_options_flow(hass):
|
async def test_options_flow(hass: HomeAssistant) -> None:
|
||||||
"""Test that options flow works."""
|
"""Test that options flow works."""
|
||||||
|
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
|
@ -291,7 +292,7 @@ async def test_options_flow(hass):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_options_flow_invalid_auth(hass):
|
async def test_options_flow_invalid_auth(hass: HomeAssistant) -> None:
|
||||||
"""Test that options flow works."""
|
"""Test that options flow works."""
|
||||||
|
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
|
@ -330,7 +331,7 @@ async def test_options_flow_invalid_auth(hass):
|
||||||
assert result["errors"] == {"base": "invalid_auth"}
|
assert result["errors"] == {"base": "invalid_auth"}
|
||||||
|
|
||||||
|
|
||||||
async def test_options_flow_cannot_connect(hass):
|
async def test_options_flow_cannot_connect(hass: HomeAssistant) -> None:
|
||||||
"""Test that options flow works."""
|
"""Test that options flow works."""
|
||||||
|
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
|
|
|
@ -4,6 +4,7 @@ from unittest.mock import patch
|
||||||
from homeassistant import config_entries, data_entry_flow
|
from homeassistant import config_entries, data_entry_flow
|
||||||
from homeassistant.components.ialarm.const import DOMAIN
|
from homeassistant.components.ialarm.const import DOMAIN
|
||||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ TEST_DATA = {CONF_HOST: "1.1.1.1", CONF_PORT: 18034}
|
||||||
TEST_MAC = "00:00:54:12:34:56"
|
TEST_MAC = "00:00:54:12:34:56"
|
||||||
|
|
||||||
|
|
||||||
async def test_form(hass):
|
async def test_form(hass: HomeAssistant) -> None:
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -42,7 +43,7 @@ async def test_form(hass):
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_form_cannot_connect(hass):
|
async def test_form_cannot_connect(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle cannot connect error."""
|
"""Test we handle cannot connect error."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -60,7 +61,7 @@ async def test_form_cannot_connect(hass):
|
||||||
assert result2["errors"] == {"base": "cannot_connect"}
|
assert result2["errors"] == {"base": "cannot_connect"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_exception(hass):
|
async def test_form_exception(hass: HomeAssistant) -> None:
|
||||||
"""Test we handle unknown exception."""
|
"""Test we handle unknown exception."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -78,7 +79,7 @@ async def test_form_exception(hass):
|
||||||
assert result2["errors"] == {"base": "unknown"}
|
assert result2["errors"] == {"base": "unknown"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_already_exists(hass):
|
async def test_form_already_exists(hass: HomeAssistant) -> None:
|
||||||
"""Test that a flow with an existing host aborts."""
|
"""Test that a flow with an existing host aborts."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
|
|
@ -7,6 +7,7 @@ from iaqualink.exception import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.components.iaqualink import config_flow
|
from homeassistant.components.iaqualink import config_flow
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
|
||||||
async def test_already_configured(hass, config_entry, config_data):
|
async def test_already_configured(hass, config_entry, config_data):
|
||||||
|
@ -22,7 +23,7 @@ async def test_already_configured(hass, config_entry, config_data):
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == "abort"
|
||||||
|
|
||||||
|
|
||||||
async def test_without_config(hass):
|
async def test_without_config(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow with no configuration."""
|
"""Test config flow with no configuration."""
|
||||||
flow = config_flow.AqualinkFlowHandler()
|
flow = config_flow.AqualinkFlowHandler()
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
"""Tests for iAqualink integration utility functions."""
|
"""Tests for iAqualink integration utility functions."""
|
||||||
|
|
||||||
from iaqualink.exception import AqualinkServiceException
|
from iaqualink.exception import AqualinkServiceException
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.iaqualink.utils import await_or_reraise
|
from homeassistant.components.iaqualink.utils import await_or_reraise
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
|
|
||||||
from .conftest import async_raises, async_returns
|
from .conftest import async_raises, async_returns
|
||||||
|
|
||||||
|
|
||||||
async def test_await_or_reraise(hass):
|
async def test_await_or_reraise(hass: HomeAssistant) -> None:
|
||||||
"""Test await_or_reraise for all values of awaitable."""
|
"""Test await_or_reraise for all values of awaitable."""
|
||||||
async_noop = async_returns(None)
|
async_noop = async_returns(None)
|
||||||
await await_or_reraise(async_noop())
|
await await_or_reraise(async_noop())
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
"""Test the ibeacon sensors."""
|
"""Test the ibeacon sensors."""
|
||||||
|
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -9,6 +7,7 @@ import pytest
|
||||||
|
|
||||||
from homeassistant.components.ibeacon.const import ATTR_SOURCE, DOMAIN, UPDATE_INTERVAL
|
from homeassistant.components.ibeacon.const import ATTR_SOURCE, DOMAIN, UPDATE_INTERVAL
|
||||||
from homeassistant.const import STATE_HOME
|
from homeassistant.const import STATE_HOME
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.service_info.bluetooth import BluetoothServiceInfo
|
from homeassistant.helpers.service_info.bluetooth import BluetoothServiceInfo
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
|
@ -35,7 +34,7 @@ def mock_bluetooth(enable_bluetooth):
|
||||||
"""Auto mock bluetooth."""
|
"""Auto mock bluetooth."""
|
||||||
|
|
||||||
|
|
||||||
async def test_many_groups_same_address_ignored(hass):
|
async def test_many_groups_same_address_ignored(hass: HomeAssistant) -> None:
|
||||||
"""Test the different uuid, major, minor from many addresses removes all associated entities."""
|
"""Test the different uuid, major, minor from many addresses removes all associated entities."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -70,7 +69,7 @@ async def test_many_groups_same_address_ignored(hass):
|
||||||
assert hass.states.get("sensor.bluecharm_177999_8105_estimated_distance") is None
|
assert hass.states.get("sensor.bluecharm_177999_8105_estimated_distance") is None
|
||||||
|
|
||||||
|
|
||||||
async def test_ignore_not_ibeacons(hass):
|
async def test_ignore_not_ibeacons(hass: HomeAssistant) -> None:
|
||||||
"""Test we ignore non-ibeacon data."""
|
"""Test we ignore non-ibeacon data."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -91,7 +90,7 @@ async def test_ignore_not_ibeacons(hass):
|
||||||
assert len(hass.states.async_entity_ids()) == before_entity_count
|
assert len(hass.states.async_entity_ids()) == before_entity_count
|
||||||
|
|
||||||
|
|
||||||
async def test_ignore_no_name_but_create_if_set_later(hass):
|
async def test_ignore_no_name_but_create_if_set_later(hass: HomeAssistant) -> None:
|
||||||
"""Test we ignore devices with no name but create it if it set set later."""
|
"""Test we ignore devices with no name but create it if it set set later."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -125,7 +124,7 @@ async def test_ignore_no_name_but_create_if_set_later(hass):
|
||||||
assert len(hass.states.async_entity_ids()) > before_entity_count
|
assert len(hass.states.async_entity_ids()) > before_entity_count
|
||||||
|
|
||||||
|
|
||||||
async def test_ignore_default_name(hass):
|
async def test_ignore_default_name(hass: HomeAssistant) -> None:
|
||||||
"""Test we ignore devices with default name."""
|
"""Test we ignore devices with default name."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -147,7 +146,7 @@ async def test_ignore_default_name(hass):
|
||||||
assert len(hass.states.async_entity_ids()) == before_entity_count
|
assert len(hass.states.async_entity_ids()) == before_entity_count
|
||||||
|
|
||||||
|
|
||||||
async def test_rotating_major_minor_and_mac_with_name(hass):
|
async def test_rotating_major_minor_and_mac_with_name(hass: HomeAssistant) -> None:
|
||||||
"""Test the different uuid, major, minor from many addresses removes all associated entities."""
|
"""Test the different uuid, major, minor from many addresses removes all associated entities."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -182,7 +181,7 @@ async def test_rotating_major_minor_and_mac_with_name(hass):
|
||||||
assert len(hass.states.async_entity_ids("device_tracker")) == before_entity_count
|
assert len(hass.states.async_entity_ids("device_tracker")) == before_entity_count
|
||||||
|
|
||||||
|
|
||||||
async def test_rotating_major_minor_and_mac_no_name(hass):
|
async def test_rotating_major_minor_and_mac_no_name(hass: HomeAssistant) -> None:
|
||||||
"""Test no-name devices with different uuid, major, minor from many addresses removes all associated entities."""
|
"""Test no-name devices with different uuid, major, minor from many addresses removes all associated entities."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -217,7 +216,9 @@ async def test_rotating_major_minor_and_mac_no_name(hass):
|
||||||
assert len(hass.states.async_entity_ids("device_tracker")) == before_entity_count
|
assert len(hass.states.async_entity_ids("device_tracker")) == before_entity_count
|
||||||
|
|
||||||
|
|
||||||
async def test_ignore_transient_devices_unless_we_see_them_a_few_times(hass):
|
async def test_ignore_transient_devices_unless_we_see_them_a_few_times(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
) -> None:
|
||||||
"""Test we ignore transient devices unless we see them a few times."""
|
"""Test we ignore transient devices unless we see them a few times."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -263,7 +264,7 @@ async def test_ignore_transient_devices_unless_we_see_them_a_few_times(hass):
|
||||||
assert hass.states.get("device_tracker.s6da7c9389bd5452cc_cccc").state == STATE_HOME
|
assert hass.states.get("device_tracker.s6da7c9389bd5452cc_cccc").state == STATE_HOME
|
||||||
|
|
||||||
|
|
||||||
async def test_changing_source_attribute(hass):
|
async def test_changing_source_attribute(hass: HomeAssistant) -> None:
|
||||||
"""Test update of the source attribute."""
|
"""Test update of the source attribute."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
"""Test the ibeacon device trackers."""
|
"""Test the ibeacon device trackers."""
|
||||||
|
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import time
|
import time
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
@ -24,6 +22,7 @@ from homeassistant.const import (
|
||||||
STATE_NOT_HOME,
|
STATE_NOT_HOME,
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
|
@ -46,7 +45,7 @@ def mock_bluetooth(enable_bluetooth):
|
||||||
"""Auto mock bluetooth."""
|
"""Auto mock bluetooth."""
|
||||||
|
|
||||||
|
|
||||||
async def test_device_tracker_fixed_address(hass):
|
async def test_device_tracker_fixed_address(hass: HomeAssistant) -> None:
|
||||||
"""Test creating and updating device_tracker."""
|
"""Test creating and updating device_tracker."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -79,7 +78,7 @@ async def test_device_tracker_fixed_address(hass):
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
async def test_device_tracker_random_address(hass):
|
async def test_device_tracker_random_address(hass: HomeAssistant) -> None:
|
||||||
"""Test creating and updating device_tracker."""
|
"""Test creating and updating device_tracker."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -142,7 +141,9 @@ async def test_device_tracker_random_address(hass):
|
||||||
assert tracker_attributes[ATTR_FRIENDLY_NAME] == "RandomAddress_1234"
|
assert tracker_attributes[ATTR_FRIENDLY_NAME] == "RandomAddress_1234"
|
||||||
|
|
||||||
|
|
||||||
async def test_device_tracker_random_address_infrequent_changes(hass):
|
async def test_device_tracker_random_address_infrequent_changes(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
) -> None:
|
||||||
"""Test creating and updating device_tracker with a random mac that only changes once per day."""
|
"""Test creating and updating device_tracker with a random mac that only changes once per day."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
"""Test the ibeacon init."""
|
"""Test the ibeacon init."""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.ibeacon.const import DOMAIN
|
from homeassistant.components.ibeacon.const import DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ from . import BLUECHARM_BEACON_SERVICE_INFO
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
from tests.components.bluetooth import inject_bluetooth_service_info
|
from tests.components.bluetooth import inject_bluetooth_service_info
|
||||||
|
from tests.typing import WebSocketGenerator
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
|
@ -31,7 +32,9 @@ async def remove_device(ws_client, device_id, config_entry_id):
|
||||||
return response["success"]
|
return response["success"]
|
||||||
|
|
||||||
|
|
||||||
async def test_device_remove_devices(hass, hass_ws_client):
|
async def test_device_remove_devices(
|
||||||
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
|
) -> None:
|
||||||
"""Test we can only remove a device that no longer exists."""
|
"""Test we can only remove a device that no longer exists."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
"""Test the ibeacon sensors."""
|
"""Test the ibeacon sensors."""
|
||||||
|
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -13,6 +11,7 @@ from homeassistant.const import (
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
|
@ -38,7 +37,7 @@ def mock_bluetooth(enable_bluetooth):
|
||||||
"""Auto mock bluetooth."""
|
"""Auto mock bluetooth."""
|
||||||
|
|
||||||
|
|
||||||
async def test_sensors_updates_fixed_mac_address(hass):
|
async def test_sensors_updates_fixed_mac_address(hass: HomeAssistant) -> None:
|
||||||
"""Test creating and updating sensors with a fixed mac address."""
|
"""Test creating and updating sensors with a fixed mac address."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -117,7 +116,7 @@ async def test_sensors_updates_fixed_mac_address(hass):
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
async def test_sensor_with_no_local_name(hass):
|
async def test_sensor_with_no_local_name(hass: HomeAssistant) -> None:
|
||||||
"""Test creating and updating sensors."""
|
"""Test creating and updating sensors."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -140,7 +139,7 @@ async def test_sensor_with_no_local_name(hass):
|
||||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||||
|
|
||||||
|
|
||||||
async def test_sensor_sees_last_service_info(hass):
|
async def test_sensor_sees_last_service_info(hass: HomeAssistant) -> None:
|
||||||
"""Test sensors are created from recent history."""
|
"""Test sensors are created from recent history."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -159,7 +158,7 @@ async def test_sensor_sees_last_service_info(hass):
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
async def test_can_unload_and_reload(hass):
|
async def test_can_unload_and_reload(hass: HomeAssistant) -> None:
|
||||||
"""Test sensors get recreated on unload/setup."""
|
"""Test sensors get recreated on unload/setup."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -187,7 +186,7 @@ async def test_can_unload_and_reload(hass):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_multiple_uuids_same_beacon(hass):
|
async def test_multiple_uuids_same_beacon(hass: HomeAssistant) -> None:
|
||||||
"""Test a beacon that broadcasts multiple uuids."""
|
"""Test a beacon that broadcasts multiple uuids."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
|
|
@ -2,10 +2,14 @@
|
||||||
from homeassistant import config_entries, data_entry_flow
|
from homeassistant import config_entries, data_entry_flow
|
||||||
from homeassistant.components import ifttt
|
from homeassistant.components import ifttt
|
||||||
from homeassistant.config import async_process_ha_core_config
|
from homeassistant.config import async_process_ha_core_config
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
async def test_config_flow_registers_webhook(hass, hass_client_no_auth):
|
async def test_config_flow_registers_webhook(
|
||||||
|
hass: HomeAssistant, hass_client_no_auth: ClientSessionGenerator
|
||||||
|
) -> None:
|
||||||
"""Test setting up IFTTT and sending webhook."""
|
"""Test setting up IFTTT and sending webhook."""
|
||||||
await async_process_ha_core_config(
|
await async_process_ha_core_config(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -26,6 +26,7 @@ from homeassistant.const import (
|
||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
UnitOfLength,
|
UnitOfLength,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ def _generate_mock_feed_entry(
|
||||||
return feed_entry
|
return feed_entry
|
||||||
|
|
||||||
|
|
||||||
async def test_setup(hass):
|
async def test_setup(hass: HomeAssistant) -> None:
|
||||||
"""Test the general setup of the platform."""
|
"""Test the general setup of the platform."""
|
||||||
# Set up some mock feed entries for this test.
|
# Set up some mock feed entries for this test.
|
||||||
mock_entry_1 = _generate_mock_feed_entry(
|
mock_entry_1 = _generate_mock_feed_entry(
|
||||||
|
@ -196,7 +197,7 @@ async def test_setup(hass):
|
||||||
assert len(all_states) == 0
|
assert len(all_states) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_with_custom_location(hass):
|
async def test_setup_with_custom_location(hass: HomeAssistant) -> None:
|
||||||
"""Test the setup with a custom location."""
|
"""Test the setup with a custom location."""
|
||||||
# Set up some mock feed entries for this test.
|
# Set up some mock feed entries for this test.
|
||||||
mock_entry_1 = _generate_mock_feed_entry("1234", "Title 1", 20.5, (38.1, -3.1))
|
mock_entry_1 = _generate_mock_feed_entry("1234", "Title 1", 20.5, (38.1, -3.1))
|
||||||
|
|
|
@ -6,12 +6,14 @@ import pytest
|
||||||
import homeassistant.components.http as http
|
import homeassistant.components.http as http
|
||||||
import homeassistant.components.image_processing as ip
|
import homeassistant.components.image_processing as ip
|
||||||
from homeassistant.const import ATTR_ENTITY_PICTURE
|
from homeassistant.const import ATTR_ENTITY_PICTURE
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import common
|
from . import common
|
||||||
|
|
||||||
from tests.common import assert_setup_component, async_capture_events
|
from tests.common import assert_setup_component, async_capture_events
|
||||||
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -50,7 +52,7 @@ async def setup_image_processing_face(hass):
|
||||||
return async_capture_events(hass, "image_processing.detect_face")
|
return async_capture_events(hass, "image_processing.detect_face")
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_component(hass):
|
async def test_setup_component(hass: HomeAssistant) -> None:
|
||||||
"""Set up demo platform on image_process component."""
|
"""Set up demo platform on image_process component."""
|
||||||
config = {ip.DOMAIN: {"platform": "demo"}}
|
config = {ip.DOMAIN: {"platform": "demo"}}
|
||||||
|
|
||||||
|
@ -58,7 +60,7 @@ async def test_setup_component(hass):
|
||||||
assert await async_setup_component(hass, ip.DOMAIN, config)
|
assert await async_setup_component(hass, ip.DOMAIN, config)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_component_with_service(hass):
|
async def test_setup_component_with_service(hass: HomeAssistant) -> None:
|
||||||
"""Set up demo platform on image_process component test service."""
|
"""Set up demo platform on image_process component test service."""
|
||||||
config = {ip.DOMAIN: {"platform": "demo"}}
|
config = {ip.DOMAIN: {"platform": "demo"}}
|
||||||
|
|
||||||
|
@ -109,7 +111,9 @@ async def test_get_image_without_exists_camera(
|
||||||
assert state.state == "0"
|
assert state.state == "0"
|
||||||
|
|
||||||
|
|
||||||
async def test_face_event_call(hass, aioclient_mock):
|
async def test_face_event_call(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Set up and scan a picture and test faces from event."""
|
"""Set up and scan a picture and test faces from event."""
|
||||||
face_events = await setup_image_processing_face(hass)
|
face_events = await setup_image_processing_face(hass)
|
||||||
aioclient_mock.get(get_url(hass), content=b"image")
|
aioclient_mock.get(get_url(hass), content=b"image")
|
||||||
|
|
|
@ -6,6 +6,7 @@ from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
|
|
||||||
from homeassistant.components.imap_email_content import sensor as imap_email_content
|
from homeassistant.components.imap_email_content import sensor as imap_email_content
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.event import async_track_state_change
|
from homeassistant.helpers.event import async_track_state_change
|
||||||
from homeassistant.helpers.template import Template
|
from homeassistant.helpers.template import Template
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ class FakeEMailReader:
|
||||||
return self._messages.popleft()
|
return self._messages.popleft()
|
||||||
|
|
||||||
|
|
||||||
async def test_allowed_sender(hass):
|
async def test_allowed_sender(hass: HomeAssistant) -> None:
|
||||||
"""Test emails from allowed sender."""
|
"""Test emails from allowed sender."""
|
||||||
test_message = email.message.Message()
|
test_message = email.message.Message()
|
||||||
test_message["From"] = "sender@test.com"
|
test_message["From"] = "sender@test.com"
|
||||||
|
@ -57,7 +58,7 @@ async def test_allowed_sender(hass):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_multi_part_with_text(hass):
|
async def test_multi_part_with_text(hass: HomeAssistant) -> None:
|
||||||
"""Test multi part emails."""
|
"""Test multi part emails."""
|
||||||
msg = MIMEMultipart("alternative")
|
msg = MIMEMultipart("alternative")
|
||||||
msg["Subject"] = "Link"
|
msg["Subject"] = "Link"
|
||||||
|
@ -87,7 +88,7 @@ async def test_multi_part_with_text(hass):
|
||||||
assert sensor.extra_state_attributes["body"] == "Test Message"
|
assert sensor.extra_state_attributes["body"] == "Test Message"
|
||||||
|
|
||||||
|
|
||||||
async def test_multi_part_only_html(hass):
|
async def test_multi_part_only_html(hass: HomeAssistant) -> None:
|
||||||
"""Test multi part emails with only HTML."""
|
"""Test multi part emails with only HTML."""
|
||||||
msg = MIMEMultipart("alternative")
|
msg = MIMEMultipart("alternative")
|
||||||
msg["Subject"] = "Link"
|
msg["Subject"] = "Link"
|
||||||
|
@ -117,7 +118,7 @@ async def test_multi_part_only_html(hass):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_multi_part_only_other_text(hass):
|
async def test_multi_part_only_other_text(hass: HomeAssistant) -> None:
|
||||||
"""Test multi part emails with only other text."""
|
"""Test multi part emails with only other text."""
|
||||||
msg = MIMEMultipart("alternative")
|
msg = MIMEMultipart("alternative")
|
||||||
msg["Subject"] = "Link"
|
msg["Subject"] = "Link"
|
||||||
|
@ -144,7 +145,7 @@ async def test_multi_part_only_other_text(hass):
|
||||||
assert sensor.extra_state_attributes["body"] == "Test Message"
|
assert sensor.extra_state_attributes["body"] == "Test Message"
|
||||||
|
|
||||||
|
|
||||||
async def test_multiple_emails(hass):
|
async def test_multiple_emails(hass: HomeAssistant) -> None:
|
||||||
"""Test multiple emails."""
|
"""Test multiple emails."""
|
||||||
states = []
|
states = []
|
||||||
|
|
||||||
|
@ -186,7 +187,7 @@ async def test_multiple_emails(hass):
|
||||||
assert sensor.extra_state_attributes["body"] == "Test Message 2"
|
assert sensor.extra_state_attributes["body"] == "Test Message 2"
|
||||||
|
|
||||||
|
|
||||||
async def test_sender_not_allowed(hass):
|
async def test_sender_not_allowed(hass: HomeAssistant) -> None:
|
||||||
"""Test not whitelisted emails."""
|
"""Test not whitelisted emails."""
|
||||||
test_message = email.message.Message()
|
test_message = email.message.Message()
|
||||||
test_message["From"] = "sender@test.com"
|
test_message["From"] = "sender@test.com"
|
||||||
|
@ -208,7 +209,7 @@ async def test_sender_not_allowed(hass):
|
||||||
assert sensor.state is None
|
assert sensor.state is None
|
||||||
|
|
||||||
|
|
||||||
async def test_template(hass):
|
async def test_template(hass: HomeAssistant) -> None:
|
||||||
"""Test value template."""
|
"""Test value template."""
|
||||||
test_message = email.message.Message()
|
test_message = email.message.Message()
|
||||||
test_message["From"] = "sender@test.com"
|
test_message["From"] = "sender@test.com"
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
"""Test the INKBIRD config flow."""
|
"""Test the INKBIRD config flow."""
|
||||||
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.inkbird.const import DOMAIN
|
from homeassistant.components.inkbird.const import DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
|
|
||||||
from . import IBBQ_SERVICE_INFO, NOT_INKBIRD_SERVICE_INFO, SPS_SERVICE_INFO
|
from . import IBBQ_SERVICE_INFO, NOT_INKBIRD_SERVICE_INFO, SPS_SERVICE_INFO
|
||||||
|
@ -11,7 +11,7 @@ from . import IBBQ_SERVICE_INFO, NOT_INKBIRD_SERVICE_INFO, SPS_SERVICE_INFO
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_async_step_bluetooth_valid_device(hass):
|
async def test_async_step_bluetooth_valid_device(hass: HomeAssistant) -> None:
|
||||||
"""Test discovery via bluetooth with a valid device."""
|
"""Test discovery via bluetooth with a valid device."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -30,7 +30,7 @@ async def test_async_step_bluetooth_valid_device(hass):
|
||||||
assert result2["result"].unique_id == "4125DDBA-2774-4851-9889-6AADDD4CAC3D"
|
assert result2["result"].unique_id == "4125DDBA-2774-4851-9889-6AADDD4CAC3D"
|
||||||
|
|
||||||
|
|
||||||
async def test_async_step_bluetooth_not_inkbird(hass):
|
async def test_async_step_bluetooth_not_inkbird(hass: HomeAssistant) -> None:
|
||||||
"""Test discovery via bluetooth not inkbird."""
|
"""Test discovery via bluetooth not inkbird."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -41,7 +41,7 @@ async def test_async_step_bluetooth_not_inkbird(hass):
|
||||||
assert result["reason"] == "not_supported"
|
assert result["reason"] == "not_supported"
|
||||||
|
|
||||||
|
|
||||||
async def test_async_step_user_no_devices_found(hass):
|
async def test_async_step_user_no_devices_found(hass: HomeAssistant) -> None:
|
||||||
"""Test setup from service info cache with no devices found."""
|
"""Test setup from service info cache with no devices found."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -51,7 +51,7 @@ async def test_async_step_user_no_devices_found(hass):
|
||||||
assert result["reason"] == "no_devices_found"
|
assert result["reason"] == "no_devices_found"
|
||||||
|
|
||||||
|
|
||||||
async def test_async_step_user_with_found_devices(hass):
|
async def test_async_step_user_with_found_devices(hass: HomeAssistant) -> None:
|
||||||
"""Test setup from service info cache with devices found."""
|
"""Test setup from service info cache with devices found."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.inkbird.config_flow.async_discovered_service_info",
|
"homeassistant.components.inkbird.config_flow.async_discovered_service_info",
|
||||||
|
@ -74,7 +74,7 @@ async def test_async_step_user_with_found_devices(hass):
|
||||||
assert result2["result"].unique_id == "61DE521B-F0BF-9F44-64D4-75BBE1738105"
|
assert result2["result"].unique_id == "61DE521B-F0BF-9F44-64D4-75BBE1738105"
|
||||||
|
|
||||||
|
|
||||||
async def test_async_step_user_device_added_between_steps(hass):
|
async def test_async_step_user_device_added_between_steps(hass: HomeAssistant) -> None:
|
||||||
"""Test the device gets added via another flow between steps."""
|
"""Test the device gets added via another flow between steps."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.inkbird.config_flow.async_discovered_service_info",
|
"homeassistant.components.inkbird.config_flow.async_discovered_service_info",
|
||||||
|
@ -102,7 +102,9 @@ async def test_async_step_user_device_added_between_steps(hass):
|
||||||
assert result2["reason"] == "already_configured"
|
assert result2["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_async_step_user_with_found_devices_already_setup(hass):
|
async def test_async_step_user_with_found_devices_already_setup(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
) -> None:
|
||||||
"""Test setup from service info cache with devices found."""
|
"""Test setup from service info cache with devices found."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -122,7 +124,7 @@ async def test_async_step_user_with_found_devices_already_setup(hass):
|
||||||
assert result["reason"] == "no_devices_found"
|
assert result["reason"] == "no_devices_found"
|
||||||
|
|
||||||
|
|
||||||
async def test_async_step_bluetooth_devices_already_setup(hass):
|
async def test_async_step_bluetooth_devices_already_setup(hass: HomeAssistant) -> None:
|
||||||
"""Test we can't start a flow if there is already a config entry."""
|
"""Test we can't start a flow if there is already a config entry."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -139,7 +141,7 @@ async def test_async_step_bluetooth_devices_already_setup(hass):
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_async_step_bluetooth_already_in_progress(hass):
|
async def test_async_step_bluetooth_already_in_progress(hass: HomeAssistant) -> None:
|
||||||
"""Test we can't start a flow for the same device twice."""
|
"""Test we can't start a flow for the same device twice."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -158,7 +160,9 @@ async def test_async_step_bluetooth_already_in_progress(hass):
|
||||||
assert result["reason"] == "already_in_progress"
|
assert result["reason"] == "already_in_progress"
|
||||||
|
|
||||||
|
|
||||||
async def test_async_step_user_takes_precedence_over_discovery(hass):
|
async def test_async_step_user_takes_precedence_over_discovery(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
) -> None:
|
||||||
"""Test manual setup takes precedence over discovery."""
|
"""Test manual setup takes precedence over discovery."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
"""Test the INKBIRD config flow."""
|
"""Test the INKBIRD config flow."""
|
||||||
|
|
||||||
|
|
||||||
from homeassistant.components.inkbird.const import DOMAIN
|
from homeassistant.components.inkbird.const import DOMAIN
|
||||||
from homeassistant.components.sensor import ATTR_STATE_CLASS
|
from homeassistant.components.sensor import ATTR_STATE_CLASS
|
||||||
from homeassistant.const import ATTR_FRIENDLY_NAME, ATTR_UNIT_OF_MEASUREMENT
|
from homeassistant.const import ATTR_FRIENDLY_NAME, ATTR_UNIT_OF_MEASUREMENT
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import SPS_SERVICE_INFO
|
from . import SPS_SERVICE_INFO
|
||||||
|
|
||||||
|
@ -11,7 +10,7 @@ from tests.common import MockConfigEntry
|
||||||
from tests.components.bluetooth import inject_bluetooth_service_info
|
from tests.components.bluetooth import inject_bluetooth_service_info
|
||||||
|
|
||||||
|
|
||||||
async def test_sensors(hass):
|
async def test_sensors(hass: HomeAssistant) -> None:
|
||||||
"""Test setting up creates the sensors."""
|
"""Test setting up creates the sensors."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The tests for the input_boolean component."""
|
"""The tests for the input_boolean component."""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
@ -19,7 +18,7 @@ from homeassistant.const import (
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
)
|
)
|
||||||
from homeassistant.core import Context, CoreState, State
|
from homeassistant.core import Context, CoreState, HomeAssistant, State
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -52,7 +51,7 @@ def storage_setup(hass, hass_storage):
|
||||||
return _storage
|
return _storage
|
||||||
|
|
||||||
|
|
||||||
async def test_config(hass):
|
async def test_config(hass: HomeAssistant) -> None:
|
||||||
"""Test config."""
|
"""Test config."""
|
||||||
invalid_configs = [None, 1, {}, {"name with space": None}]
|
invalid_configs = [None, 1, {}, {"name with space": None}]
|
||||||
|
|
||||||
|
@ -60,7 +59,7 @@ async def test_config(hass):
|
||||||
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
|
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
|
||||||
|
|
||||||
|
|
||||||
async def test_methods(hass):
|
async def test_methods(hass: HomeAssistant) -> None:
|
||||||
"""Test is_on, turn_on, turn_off methods."""
|
"""Test is_on, turn_on, turn_off methods."""
|
||||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {"test_1": None}})
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {"test_1": None}})
|
||||||
entity_id = "input_boolean.test_1"
|
entity_id = "input_boolean.test_1"
|
||||||
|
@ -86,7 +85,7 @@ async def test_methods(hass):
|
||||||
assert is_on(hass, entity_id)
|
assert is_on(hass, entity_id)
|
||||||
|
|
||||||
|
|
||||||
async def test_config_options(hass):
|
async def test_config_options(hass: HomeAssistant) -> None:
|
||||||
"""Test configuration options."""
|
"""Test configuration options."""
|
||||||
count_start = len(hass.states.async_entity_ids())
|
count_start = len(hass.states.async_entity_ids())
|
||||||
|
|
||||||
|
@ -122,7 +121,7 @@ async def test_config_options(hass):
|
||||||
assert state_2.attributes.get(ATTR_ICON) == "mdi:work"
|
assert state_2.attributes.get(ATTR_ICON) == "mdi:work"
|
||||||
|
|
||||||
|
|
||||||
async def test_restore_state(hass):
|
async def test_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure states are restored on startup."""
|
"""Ensure states are restored on startup."""
|
||||||
mock_restore_cache(
|
mock_restore_cache(
|
||||||
hass,
|
hass,
|
||||||
|
@ -147,7 +146,7 @@ async def test_restore_state(hass):
|
||||||
assert state.state == "off"
|
assert state.state == "off"
|
||||||
|
|
||||||
|
|
||||||
async def test_initial_state_overrules_restore_state(hass):
|
async def test_initial_state_overrules_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure states are restored on startup."""
|
"""Ensure states are restored on startup."""
|
||||||
mock_restore_cache(
|
mock_restore_cache(
|
||||||
hass, (State("input_boolean.b1", "on"), State("input_boolean.b2", "off"))
|
hass, (State("input_boolean.b1", "on"), State("input_boolean.b2", "off"))
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
"""Test reproduce state for input boolean."""
|
"""Test reproduce state for input boolean."""
|
||||||
from homeassistant.core import State
|
from homeassistant.core import HomeAssistant, State
|
||||||
from homeassistant.helpers.state import async_reproduce_state
|
from homeassistant.helpers.state import async_reproduce_state
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
|
||||||
async def test_reproducing_states(hass):
|
async def test_reproducing_states(hass: HomeAssistant) -> None:
|
||||||
"""Test reproducing input_boolean states."""
|
"""Test reproducing input_boolean states."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -14,7 +14,7 @@ from homeassistant.const import (
|
||||||
SERVICE_RELOAD,
|
SERVICE_RELOAD,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
)
|
)
|
||||||
from homeassistant.core import Context, CoreState, State
|
from homeassistant.core import Context, CoreState, HomeAssistant, State
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.event import async_track_state_change
|
from homeassistant.helpers.event import async_track_state_change
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -44,7 +44,7 @@ def storage_setup(hass, hass_storage):
|
||||||
return _storage
|
return _storage
|
||||||
|
|
||||||
|
|
||||||
async def test_config(hass):
|
async def test_config(hass: HomeAssistant) -> None:
|
||||||
"""Test config."""
|
"""Test config."""
|
||||||
invalid_configs = [None, 1, {}, {"name with space": None}]
|
invalid_configs = [None, 1, {}, {"name with space": None}]
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ async def test_config(hass):
|
||||||
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
|
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
|
||||||
|
|
||||||
|
|
||||||
async def test_config_options(hass):
|
async def test_config_options(hass: HomeAssistant) -> None:
|
||||||
"""Test configuration options."""
|
"""Test configuration options."""
|
||||||
count_start = len(hass.states.async_entity_ids())
|
count_start = len(hass.states.async_entity_ids())
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ async def test_config_options(hass):
|
||||||
assert state_2.attributes.get(ATTR_ICON) == "mdi:work"
|
assert state_2.attributes.get(ATTR_ICON) == "mdi:work"
|
||||||
|
|
||||||
|
|
||||||
async def test_restore_state(hass):
|
async def test_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure states are restored on startup."""
|
"""Ensure states are restored on startup."""
|
||||||
mock_restore_cache(
|
mock_restore_cache(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""Tests for the Input slider component."""
|
"""Tests for the Input slider component."""
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
@ -26,7 +25,7 @@ from homeassistant.components.input_datetime import (
|
||||||
SERVICE_RELOAD,
|
SERVICE_RELOAD,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME, ATTR_NAME
|
from homeassistant.const import ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME, ATTR_NAME
|
||||||
from homeassistant.core import Context, CoreState, State
|
from homeassistant.core import Context, CoreState, HomeAssistant, State
|
||||||
from homeassistant.exceptions import Unauthorized
|
from homeassistant.exceptions import Unauthorized
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -121,7 +120,7 @@ def test_invalid_configs(config):
|
||||||
CONFIG_SCHEMA({DOMAIN: config})
|
CONFIG_SCHEMA({DOMAIN: config})
|
||||||
|
|
||||||
|
|
||||||
async def test_set_datetime(hass):
|
async def test_set_datetime(hass: HomeAssistant) -> None:
|
||||||
"""Test set_datetime method using date & time."""
|
"""Test set_datetime method using date & time."""
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass, DOMAIN, {DOMAIN: {"test_datetime": {"has_time": True, "has_date": True}}}
|
hass, DOMAIN, {DOMAIN: {"test_datetime": {"has_time": True, "has_date": True}}}
|
||||||
|
@ -149,7 +148,7 @@ async def test_set_datetime(hass):
|
||||||
assert state.attributes["timestamp"] == dt_obj.timestamp()
|
assert state.attributes["timestamp"] == dt_obj.timestamp()
|
||||||
|
|
||||||
|
|
||||||
async def test_set_datetime_2(hass):
|
async def test_set_datetime_2(hass: HomeAssistant) -> None:
|
||||||
"""Test set_datetime method using datetime."""
|
"""Test set_datetime method using datetime."""
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass, DOMAIN, {DOMAIN: {"test_datetime": {"has_time": True, "has_date": True}}}
|
hass, DOMAIN, {DOMAIN: {"test_datetime": {"has_time": True, "has_date": True}}}
|
||||||
|
@ -177,7 +176,7 @@ async def test_set_datetime_2(hass):
|
||||||
assert state.attributes["timestamp"] == dt_obj.timestamp()
|
assert state.attributes["timestamp"] == dt_obj.timestamp()
|
||||||
|
|
||||||
|
|
||||||
async def test_set_datetime_3(hass):
|
async def test_set_datetime_3(hass: HomeAssistant) -> None:
|
||||||
"""Test set_datetime method using timestamp."""
|
"""Test set_datetime method using timestamp."""
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass, DOMAIN, {DOMAIN: {"test_datetime": {"has_time": True, "has_date": True}}}
|
hass, DOMAIN, {DOMAIN: {"test_datetime": {"has_time": True, "has_date": True}}}
|
||||||
|
@ -205,7 +204,7 @@ async def test_set_datetime_3(hass):
|
||||||
assert state.attributes["timestamp"] == dt_obj.timestamp()
|
assert state.attributes["timestamp"] == dt_obj.timestamp()
|
||||||
|
|
||||||
|
|
||||||
async def test_set_datetime_time(hass):
|
async def test_set_datetime_time(hass: HomeAssistant) -> None:
|
||||||
"""Test set_datetime method with only time."""
|
"""Test set_datetime method with only time."""
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass, DOMAIN, {DOMAIN: {"test_time": {"has_time": True, "has_date": False}}}
|
hass, DOMAIN, {DOMAIN: {"test_time": {"has_time": True, "has_date": False}}}
|
||||||
|
@ -225,7 +224,7 @@ async def test_set_datetime_time(hass):
|
||||||
assert state.attributes["timestamp"] == (19 * 3600) + (46 * 60) + 30
|
assert state.attributes["timestamp"] == (19 * 3600) + (46 * 60) + 30
|
||||||
|
|
||||||
|
|
||||||
async def test_set_invalid(hass):
|
async def test_set_invalid(hass: HomeAssistant) -> None:
|
||||||
"""Test set_datetime method with only time."""
|
"""Test set_datetime method with only time."""
|
||||||
initial = "2017-01-01"
|
initial = "2017-01-01"
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
|
@ -255,7 +254,7 @@ async def test_set_invalid(hass):
|
||||||
assert state.state == initial
|
assert state.state == initial
|
||||||
|
|
||||||
|
|
||||||
async def test_set_invalid_2(hass):
|
async def test_set_invalid_2(hass: HomeAssistant) -> None:
|
||||||
"""Test set_datetime method with date and datetime."""
|
"""Test set_datetime method with date and datetime."""
|
||||||
initial = "2017-01-01"
|
initial = "2017-01-01"
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
|
@ -285,7 +284,7 @@ async def test_set_invalid_2(hass):
|
||||||
assert state.state == initial
|
assert state.state == initial
|
||||||
|
|
||||||
|
|
||||||
async def test_set_datetime_date(hass):
|
async def test_set_datetime_date(hass: HomeAssistant) -> None:
|
||||||
"""Test set_datetime method with only date."""
|
"""Test set_datetime method with only date."""
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass, DOMAIN, {DOMAIN: {"test_date": {"has_time": False, "has_date": True}}}
|
hass, DOMAIN, {DOMAIN: {"test_date": {"has_time": False, "has_date": True}}}
|
||||||
|
@ -307,7 +306,7 @@ async def test_set_datetime_date(hass):
|
||||||
assert state.attributes["timestamp"] == date_dt_obj.timestamp()
|
assert state.attributes["timestamp"] == date_dt_obj.timestamp()
|
||||||
|
|
||||||
|
|
||||||
async def test_restore_state(hass):
|
async def test_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure states are restored on startup."""
|
"""Ensure states are restored on startup."""
|
||||||
mock_restore_cache(
|
mock_restore_cache(
|
||||||
hass,
|
hass,
|
||||||
|
@ -365,7 +364,7 @@ async def test_restore_state(hass):
|
||||||
assert state_was_date.state == default.strftime(FMT_TIME)
|
assert state_was_date.state == default.strftime(FMT_TIME)
|
||||||
|
|
||||||
|
|
||||||
async def test_default_value(hass):
|
async def test_default_value(hass: HomeAssistant) -> None:
|
||||||
"""Test default value if none has been set via initial or restore state."""
|
"""Test default value if none has been set via initial or restore state."""
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -657,7 +656,7 @@ async def test_setup_no_config(hass, hass_admin_user):
|
||||||
assert count_start == len(hass.states.async_entity_ids())
|
assert count_start == len(hass.states.async_entity_ids())
|
||||||
|
|
||||||
|
|
||||||
async def test_timestamp(hass):
|
async def test_timestamp(hass: HomeAssistant) -> None:
|
||||||
"""Test timestamp."""
|
"""Test timestamp."""
|
||||||
hass.config.set_time_zone("America/Los_Angeles")
|
hass.config.set_time_zone("America/Los_Angeles")
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
"""Test reproduce state for Input datetime."""
|
"""Test reproduce state for Input datetime."""
|
||||||
from homeassistant.core import State
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant, State
|
||||||
from homeassistant.helpers.state import async_reproduce_state
|
from homeassistant.helpers.state import async_reproduce_state
|
||||||
|
|
||||||
from tests.common import async_mock_service
|
from tests.common import async_mock_service
|
||||||
|
|
||||||
|
|
||||||
async def test_reproducing_states(hass, caplog):
|
async def test_reproducing_states(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test reproducing Input datetime states."""
|
"""Test reproducing Input datetime states."""
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
"input_datetime.entity_datetime",
|
"input_datetime.entity_datetime",
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The tests for the Input number component."""
|
"""The tests for the Input number component."""
|
||||||
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -19,7 +18,7 @@ from homeassistant.const import (
|
||||||
ATTR_FRIENDLY_NAME,
|
ATTR_FRIENDLY_NAME,
|
||||||
ATTR_NAME,
|
ATTR_NAME,
|
||||||
)
|
)
|
||||||
from homeassistant.core import Context, CoreState, State
|
from homeassistant.core import Context, CoreState, HomeAssistant, State
|
||||||
from homeassistant.exceptions import Unauthorized
|
from homeassistant.exceptions import Unauthorized
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -96,7 +95,7 @@ async def decrement(hass, entity_id):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_config(hass):
|
async def test_config(hass: HomeAssistant) -> None:
|
||||||
"""Test config."""
|
"""Test config."""
|
||||||
invalid_configs = [
|
invalid_configs = [
|
||||||
None,
|
None,
|
||||||
|
@ -108,7 +107,7 @@ async def test_config(hass):
|
||||||
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
|
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
|
||||||
|
|
||||||
|
|
||||||
async def test_set_value(hass, caplog):
|
async def test_set_value(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -> None:
|
||||||
"""Test set_value method."""
|
"""Test set_value method."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, DOMAIN, {DOMAIN: {"test_1": {"initial": 50, "min": 0, "max": 100}}}
|
hass, DOMAIN, {DOMAIN: {"test_1": {"initial": 50, "min": 0, "max": 100}}}
|
||||||
|
@ -139,7 +138,7 @@ async def test_set_value(hass, caplog):
|
||||||
assert float(state.state) == 70
|
assert float(state.state) == 70
|
||||||
|
|
||||||
|
|
||||||
async def test_increment(hass):
|
async def test_increment(hass: HomeAssistant) -> None:
|
||||||
"""Test increment method."""
|
"""Test increment method."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, DOMAIN, {DOMAIN: {"test_2": {"initial": 50, "min": 0, "max": 51}}}
|
hass, DOMAIN, {DOMAIN: {"test_2": {"initial": 50, "min": 0, "max": 51}}}
|
||||||
|
@ -162,7 +161,7 @@ async def test_increment(hass):
|
||||||
assert float(state.state) == 51
|
assert float(state.state) == 51
|
||||||
|
|
||||||
|
|
||||||
async def test_rounding(hass):
|
async def test_rounding(hass: HomeAssistant) -> None:
|
||||||
"""Test increment introducing floating point error is rounded."""
|
"""Test increment introducing floating point error is rounded."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -182,7 +181,7 @@ async def test_rounding(hass):
|
||||||
assert float(state.state) == 3.6
|
assert float(state.state) == 3.6
|
||||||
|
|
||||||
|
|
||||||
async def test_decrement(hass):
|
async def test_decrement(hass: HomeAssistant) -> None:
|
||||||
"""Test decrement method."""
|
"""Test decrement method."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, DOMAIN, {DOMAIN: {"test_3": {"initial": 50, "min": 49, "max": 100}}}
|
hass, DOMAIN, {DOMAIN: {"test_3": {"initial": 50, "min": 49, "max": 100}}}
|
||||||
|
@ -205,7 +204,7 @@ async def test_decrement(hass):
|
||||||
assert float(state.state) == 49
|
assert float(state.state) == 49
|
||||||
|
|
||||||
|
|
||||||
async def test_mode(hass):
|
async def test_mode(hass: HomeAssistant) -> None:
|
||||||
"""Test mode settings."""
|
"""Test mode settings."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -232,7 +231,7 @@ async def test_mode(hass):
|
||||||
assert state.attributes["mode"] == "slider"
|
assert state.attributes["mode"] == "slider"
|
||||||
|
|
||||||
|
|
||||||
async def test_restore_state(hass):
|
async def test_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure states are restored on startup."""
|
"""Ensure states are restored on startup."""
|
||||||
mock_restore_cache(
|
mock_restore_cache(
|
||||||
hass, (State("input_number.b1", "70"), State("input_number.b2", "200"))
|
hass, (State("input_number.b1", "70"), State("input_number.b2", "200"))
|
||||||
|
@ -255,7 +254,7 @@ async def test_restore_state(hass):
|
||||||
assert float(state.state) == 10
|
assert float(state.state) == 10
|
||||||
|
|
||||||
|
|
||||||
async def test_restore_invalid_state(hass):
|
async def test_restore_invalid_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure an invalid restore state is handled."""
|
"""Ensure an invalid restore state is handled."""
|
||||||
mock_restore_cache(
|
mock_restore_cache(
|
||||||
hass, (State("input_number.b1", "="), State("input_number.b2", "200"))
|
hass, (State("input_number.b1", "="), State("input_number.b2", "200"))
|
||||||
|
@ -278,7 +277,7 @@ async def test_restore_invalid_state(hass):
|
||||||
assert float(state.state) == 10
|
assert float(state.state) == 10
|
||||||
|
|
||||||
|
|
||||||
async def test_initial_state_overrules_restore_state(hass):
|
async def test_initial_state_overrules_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure states are restored on startup."""
|
"""Ensure states are restored on startup."""
|
||||||
mock_restore_cache(
|
mock_restore_cache(
|
||||||
hass, (State("input_number.b1", "70"), State("input_number.b2", "200"))
|
hass, (State("input_number.b1", "70"), State("input_number.b2", "200"))
|
||||||
|
@ -306,7 +305,7 @@ async def test_initial_state_overrules_restore_state(hass):
|
||||||
assert float(state.state) == 60
|
assert float(state.state) == 60
|
||||||
|
|
||||||
|
|
||||||
async def test_no_initial_state_and_no_restore_state(hass):
|
async def test_no_initial_state_and_no_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure that entity is create without initial and restore feature."""
|
"""Ensure that entity is create without initial and restore feature."""
|
||||||
hass.state = CoreState.starting
|
hass.state = CoreState.starting
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
"""Test reproduce state for Input number."""
|
"""Test reproduce state for Input number."""
|
||||||
from homeassistant.core import State
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant, State
|
||||||
from homeassistant.helpers.state import async_reproduce_state
|
from homeassistant.helpers.state import async_reproduce_state
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -7,7 +9,9 @@ VALID_NUMBER1 = "19.0"
|
||||||
VALID_NUMBER2 = "99.9"
|
VALID_NUMBER2 = "99.9"
|
||||||
|
|
||||||
|
|
||||||
async def test_reproducing_states(hass, caplog):
|
async def test_reproducing_states(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test reproducing Input number states."""
|
"""Test reproducing Input number states."""
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The tests for the Input select component."""
|
"""The tests for the Input select component."""
|
||||||
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -26,7 +25,7 @@ from homeassistant.const import (
|
||||||
ATTR_NAME,
|
ATTR_NAME,
|
||||||
SERVICE_RELOAD,
|
SERVICE_RELOAD,
|
||||||
)
|
)
|
||||||
from homeassistant.core import Context, State
|
from homeassistant.core import Context, HomeAssistant, State
|
||||||
from homeassistant.exceptions import HomeAssistantError, Unauthorized
|
from homeassistant.exceptions import HomeAssistantError, Unauthorized
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -68,7 +67,7 @@ def storage_setup(hass, hass_storage):
|
||||||
return _storage
|
return _storage
|
||||||
|
|
||||||
|
|
||||||
async def test_config(hass):
|
async def test_config(hass: HomeAssistant) -> None:
|
||||||
"""Test config."""
|
"""Test config."""
|
||||||
invalid_configs = [
|
invalid_configs = [
|
||||||
None,
|
None,
|
||||||
|
@ -81,7 +80,7 @@ async def test_config(hass):
|
||||||
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
|
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
|
||||||
|
|
||||||
|
|
||||||
async def test_select_option(hass):
|
async def test_select_option(hass: HomeAssistant) -> None:
|
||||||
"""Test select_option methods."""
|
"""Test select_option methods."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -112,7 +111,7 @@ async def test_select_option(hass):
|
||||||
assert state.state == "another option"
|
assert state.state == "another option"
|
||||||
|
|
||||||
|
|
||||||
async def test_select_next(hass):
|
async def test_select_next(hass: HomeAssistant) -> None:
|
||||||
"""Test select_next methods."""
|
"""Test select_next methods."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -150,7 +149,7 @@ async def test_select_next(hass):
|
||||||
assert state.state == "first option"
|
assert state.state == "first option"
|
||||||
|
|
||||||
|
|
||||||
async def test_select_previous(hass):
|
async def test_select_previous(hass: HomeAssistant) -> None:
|
||||||
"""Test select_previous methods."""
|
"""Test select_previous methods."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -188,7 +187,7 @@ async def test_select_previous(hass):
|
||||||
assert state.state == "last option"
|
assert state.state == "last option"
|
||||||
|
|
||||||
|
|
||||||
async def test_select_first_last(hass):
|
async def test_select_first_last(hass: HomeAssistant) -> None:
|
||||||
"""Test select_first and _last methods."""
|
"""Test select_first and _last methods."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -228,7 +227,7 @@ async def test_select_first_last(hass):
|
||||||
assert state.state == "last option"
|
assert state.state == "last option"
|
||||||
|
|
||||||
|
|
||||||
async def test_config_options(hass):
|
async def test_config_options(hass: HomeAssistant) -> None:
|
||||||
"""Test configuration options."""
|
"""Test configuration options."""
|
||||||
count_start = len(hass.states.async_entity_ids())
|
count_start = len(hass.states.async_entity_ids())
|
||||||
|
|
||||||
|
@ -268,7 +267,7 @@ async def test_config_options(hass):
|
||||||
assert state_2.attributes.get(ATTR_ICON) == "mdi:work"
|
assert state_2.attributes.get(ATTR_ICON) == "mdi:work"
|
||||||
|
|
||||||
|
|
||||||
async def test_set_options_service(hass):
|
async def test_set_options_service(hass: HomeAssistant) -> None:
|
||||||
"""Test set_options service."""
|
"""Test set_options service."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -324,7 +323,7 @@ async def test_set_options_service(hass):
|
||||||
assert state.state == "test2"
|
assert state.state == "test2"
|
||||||
|
|
||||||
|
|
||||||
async def test_set_options_service_duplicate(hass):
|
async def test_set_options_service_duplicate(hass: HomeAssistant) -> None:
|
||||||
"""Test set_options service with duplicates."""
|
"""Test set_options service with duplicates."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -364,7 +363,7 @@ async def test_set_options_service_duplicate(hass):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
async def test_restore_state(hass):
|
async def test_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure states are restored on startup."""
|
"""Ensure states are restored on startup."""
|
||||||
mock_restore_cache(
|
mock_restore_cache(
|
||||||
hass,
|
hass,
|
||||||
|
@ -387,7 +386,7 @@ async def test_restore_state(hass):
|
||||||
assert state.state == "first option"
|
assert state.state == "first option"
|
||||||
|
|
||||||
|
|
||||||
async def test_initial_state_overrules_restore_state(hass):
|
async def test_initial_state_overrules_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure states are restored on startup."""
|
"""Ensure states are restored on startup."""
|
||||||
mock_restore_cache(
|
mock_restore_cache(
|
||||||
hass,
|
hass,
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
"""Test reproduce state for Input select."""
|
"""Test reproduce state for Input select."""
|
||||||
from homeassistant.core import State
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant, State
|
||||||
from homeassistant.helpers.state import async_reproduce_state
|
from homeassistant.helpers.state import async_reproduce_state
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -15,7 +17,9 @@ VALID_OPTION_SET2 = [VALID_OPTION4, VALID_OPTION5, VALID_OPTION6]
|
||||||
ENTITY = "input_select.test_select"
|
ENTITY = "input_select.test_select"
|
||||||
|
|
||||||
|
|
||||||
async def test_reproducing_states(hass, caplog):
|
async def test_reproducing_states(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test reproducing Input select states."""
|
"""Test reproducing Input select states."""
|
||||||
|
|
||||||
# Setup entity
|
# Setup entity
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""The tests for the Input text component."""
|
"""The tests for the Input text component."""
|
||||||
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -23,7 +22,7 @@ from homeassistant.const import (
|
||||||
ATTR_NAME,
|
ATTR_NAME,
|
||||||
SERVICE_RELOAD,
|
SERVICE_RELOAD,
|
||||||
)
|
)
|
||||||
from homeassistant.core import Context, CoreState, State
|
from homeassistant.core import Context, CoreState, HomeAssistant, State
|
||||||
from homeassistant.exceptions import Unauthorized
|
from homeassistant.exceptions import Unauthorized
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -79,7 +78,7 @@ async def async_set_value(hass, entity_id, value):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_config(hass):
|
async def test_config(hass: HomeAssistant) -> None:
|
||||||
"""Test config."""
|
"""Test config."""
|
||||||
invalid_configs = [
|
invalid_configs = [
|
||||||
None,
|
None,
|
||||||
|
@ -91,7 +90,7 @@ async def test_config(hass):
|
||||||
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
|
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
|
||||||
|
|
||||||
|
|
||||||
async def test_set_value(hass):
|
async def test_set_value(hass: HomeAssistant) -> None:
|
||||||
"""Test set_value method."""
|
"""Test set_value method."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -121,7 +120,7 @@ async def test_set_value(hass):
|
||||||
assert hass.states.get(entity_id_2).state == ""
|
assert hass.states.get(entity_id_2).state == ""
|
||||||
|
|
||||||
|
|
||||||
async def test_mode(hass):
|
async def test_mode(hass: HomeAssistant) -> None:
|
||||||
"""Test mode settings."""
|
"""Test mode settings."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
|
@ -158,7 +157,7 @@ async def test_mode(hass):
|
||||||
assert state.attributes["mode"] == "password"
|
assert state.attributes["mode"] == "password"
|
||||||
|
|
||||||
|
|
||||||
async def test_restore_state(hass):
|
async def test_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure states are restored on startup."""
|
"""Ensure states are restored on startup."""
|
||||||
mock_restore_cache(
|
mock_restore_cache(
|
||||||
hass,
|
hass,
|
||||||
|
@ -180,7 +179,7 @@ async def test_restore_state(hass):
|
||||||
assert str(state.state) == "unknown"
|
assert str(state.state) == "unknown"
|
||||||
|
|
||||||
|
|
||||||
async def test_initial_state_overrules_restore_state(hass):
|
async def test_initial_state_overrules_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure states are restored on startup."""
|
"""Ensure states are restored on startup."""
|
||||||
mock_restore_cache(
|
mock_restore_cache(
|
||||||
hass,
|
hass,
|
||||||
|
@ -209,7 +208,7 @@ async def test_initial_state_overrules_restore_state(hass):
|
||||||
assert str(state.state) == "test"
|
assert str(state.state) == "test"
|
||||||
|
|
||||||
|
|
||||||
async def test_no_initial_state_and_no_restore_state(hass):
|
async def test_no_initial_state_and_no_restore_state(hass: HomeAssistant) -> None:
|
||||||
"""Ensure that entity is create without initial and restore feature."""
|
"""Ensure that entity is create without initial and restore feature."""
|
||||||
hass.state = CoreState.starting
|
hass.state = CoreState.starting
|
||||||
|
|
||||||
|
@ -243,7 +242,7 @@ async def test_input_text_context(hass, hass_admin_user):
|
||||||
assert state2.context.user_id == hass_admin_user.id
|
assert state2.context.user_id == hass_admin_user.id
|
||||||
|
|
||||||
|
|
||||||
async def test_config_none(hass):
|
async def test_config_none(hass: HomeAssistant) -> None:
|
||||||
"""Set up input_text without any config."""
|
"""Set up input_text without any config."""
|
||||||
await async_setup_component(hass, DOMAIN, {DOMAIN: {"b1": None}})
|
await async_setup_component(hass, DOMAIN, {DOMAIN: {"b1": None}})
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
"""Test reproduce state for Input text."""
|
"""Test reproduce state for Input text."""
|
||||||
from homeassistant.core import State
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant, State
|
||||||
from homeassistant.helpers.state import async_reproduce_state
|
from homeassistant.helpers.state import async_reproduce_state
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -9,7 +11,9 @@ INVALID_TEXT1 = "This text is too long!"
|
||||||
INVALID_TEXT2 = "Short"
|
INVALID_TEXT2 = "Short"
|
||||||
|
|
||||||
|
|
||||||
async def test_reproducing_states(hass, caplog):
|
async def test_reproducing_states(
|
||||||
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
"""Test reproducing Input text states."""
|
"""Test reproducing Input text states."""
|
||||||
|
|
||||||
# Setup entity for testing
|
# Setup entity for testing
|
||||||
|
|
|
@ -17,12 +17,14 @@ from homeassistant.components.insteon.api.device import (
|
||||||
async_device_name,
|
async_device_name,
|
||||||
)
|
)
|
||||||
from homeassistant.components.insteon.const import DOMAIN, MULTIPLE
|
from homeassistant.components.insteon.const import DOMAIN, MULTIPLE
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
from .const import MOCK_USER_INPUT_PLM
|
from .const import MOCK_USER_INPUT_PLM
|
||||||
from .mock_devices import MockDevices
|
from .mock_devices import MockDevices
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
from tests.typing import WebSocketGenerator
|
||||||
|
|
||||||
|
|
||||||
async def _async_setup(hass, hass_ws_client):
|
async def _async_setup(hass, hass_ws_client):
|
||||||
|
@ -50,7 +52,9 @@ async def _async_setup(hass, hass_ws_client):
|
||||||
return ws_client, devices, ha_device, dev_reg
|
return ws_client, devices, ha_device, dev_reg
|
||||||
|
|
||||||
|
|
||||||
async def test_get_device_api(hass, hass_ws_client):
|
async def test_get_device_api(
|
||||||
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
|
) -> None:
|
||||||
"""Test getting an Insteon device."""
|
"""Test getting an Insteon device."""
|
||||||
|
|
||||||
ws_client, devices, ha_device, _ = await _async_setup(hass, hass_ws_client)
|
ws_client, devices, ha_device, _ = await _async_setup(hass, hass_ws_client)
|
||||||
|
@ -65,7 +69,9 @@ async def test_get_device_api(hass, hass_ws_client):
|
||||||
assert result["address"] == "11.11.11"
|
assert result["address"] == "11.11.11"
|
||||||
|
|
||||||
|
|
||||||
async def test_no_ha_device(hass, hass_ws_client):
|
async def test_no_ha_device(
|
||||||
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
|
) -> None:
|
||||||
"""Test response when no HA device exists."""
|
"""Test response when no HA device exists."""
|
||||||
|
|
||||||
ws_client, devices, _, _ = await _async_setup(hass, hass_ws_client)
|
ws_client, devices, _, _ = await _async_setup(hass, hass_ws_client)
|
||||||
|
@ -79,7 +85,9 @@ async def test_no_ha_device(hass, hass_ws_client):
|
||||||
assert msg["error"]["message"] == HA_DEVICE_NOT_FOUND
|
assert msg["error"]["message"] == HA_DEVICE_NOT_FOUND
|
||||||
|
|
||||||
|
|
||||||
async def test_no_insteon_device(hass, hass_ws_client):
|
async def test_no_insteon_device(
|
||||||
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
|
) -> None:
|
||||||
"""Test response when no Insteon device exists."""
|
"""Test response when no Insteon device exists."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -125,7 +133,9 @@ async def test_no_insteon_device(hass, hass_ws_client):
|
||||||
assert msg["error"]["message"] == INSTEON_DEVICE_NOT_FOUND
|
assert msg["error"]["message"] == INSTEON_DEVICE_NOT_FOUND
|
||||||
|
|
||||||
|
|
||||||
async def test_get_ha_device_name(hass, hass_ws_client):
|
async def test_get_ha_device_name(
|
||||||
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
|
) -> None:
|
||||||
"""Test getting the HA device name from an Insteon address."""
|
"""Test getting the HA device name from an Insteon address."""
|
||||||
|
|
||||||
_, devices, _, device_reg = await _async_setup(hass, hass_ws_client)
|
_, devices, _, device_reg = await _async_setup(hass, hass_ws_client)
|
||||||
|
@ -144,7 +154,9 @@ async def test_get_ha_device_name(hass, hass_ws_client):
|
||||||
assert name == ""
|
assert name == ""
|
||||||
|
|
||||||
|
|
||||||
async def test_add_device_api(hass, hass_ws_client):
|
async def test_add_device_api(
|
||||||
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
|
) -> None:
|
||||||
"""Test adding an Insteon device."""
|
"""Test adding an Insteon device."""
|
||||||
|
|
||||||
ws_client, devices, _, _ = await _async_setup(hass, hass_ws_client)
|
ws_client, devices, _, _ = await _async_setup(hass, hass_ws_client)
|
||||||
|
@ -172,7 +184,9 @@ async def test_add_device_api(hass, hass_ws_client):
|
||||||
assert msg["event"]["type"] == "linking_stopped"
|
assert msg["event"]["type"] == "linking_stopped"
|
||||||
|
|
||||||
|
|
||||||
async def test_cancel_add_device(hass, hass_ws_client):
|
async def test_cancel_add_device(
|
||||||
|
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
|
||||||
|
) -> None:
|
||||||
"""Test cancelling adding of a new device."""
|
"""Test cancelling adding of a new device."""
|
||||||
|
|
||||||
ws_client, devices, _, _ = await _async_setup(hass, hass_ws_client)
|
ws_client, devices, _, _ = await _async_setup(hass, hass_ws_client)
|
||||||
|
|
|
@ -627,7 +627,7 @@ async def test_options_override_bad_data(hass: HomeAssistant):
|
||||||
assert result["errors"] == {"base": "input_error"}
|
assert result["errors"] == {"base": "input_error"}
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_via_usb(hass):
|
async def test_discovery_via_usb(hass: HomeAssistant) -> None:
|
||||||
"""Test usb flow."""
|
"""Test usb flow."""
|
||||||
discovery_info = usb.UsbServiceInfo(
|
discovery_info = usb.UsbServiceInfo(
|
||||||
device="/dev/ttyINSTEON",
|
device="/dev/ttyINSTEON",
|
||||||
|
@ -656,7 +656,7 @@ async def test_discovery_via_usb(hass):
|
||||||
assert result2["data"] == {"device": "/dev/ttyINSTEON"}
|
assert result2["data"] == {"device": "/dev/ttyINSTEON"}
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_via_usb_already_setup(hass):
|
async def test_discovery_via_usb_already_setup(hass: HomeAssistant) -> None:
|
||||||
"""Test usb flow -- already setup."""
|
"""Test usb flow -- already setup."""
|
||||||
|
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""Tests for the Insteon lock."""
|
"""Tests for the Insteon lock."""
|
||||||
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -19,6 +18,7 @@ from homeassistant.const import ( # ATTR_ENTITY_ID,;
|
||||||
STATE_UNLOCKED,
|
STATE_UNLOCKED,
|
||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from .const import MOCK_USER_INPUT_PLM
|
from .const import MOCK_USER_INPUT_PLM
|
||||||
|
@ -57,7 +57,7 @@ async def mock_connection(*args, **kwargs):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def test_lock_lock(hass):
|
async def test_lock_lock(hass: HomeAssistant) -> None:
|
||||||
"""Test locking an Insteon lock device."""
|
"""Test locking an Insteon lock device."""
|
||||||
|
|
||||||
config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_INPUT_PLM)
|
config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_INPUT_PLM)
|
||||||
|
@ -82,7 +82,7 @@ async def test_lock_lock(hass):
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
async def test_lock_unlock(hass):
|
async def test_lock_unlock(hass: HomeAssistant) -> None:
|
||||||
"""Test locking an Insteon lock device."""
|
"""Test locking an Insteon lock device."""
|
||||||
|
|
||||||
config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_INPUT_PLM)
|
config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_USER_INPUT_PLM)
|
||||||
|
|
|
@ -140,7 +140,7 @@ async def test_restore_state_failed(hass: HomeAssistant) -> None:
|
||||||
assert "device_class" not in state.attributes
|
assert "device_class" not in state.attributes
|
||||||
|
|
||||||
|
|
||||||
async def test_trapezoidal(hass):
|
async def test_trapezoidal(hass: HomeAssistant) -> None:
|
||||||
"""Test integration sensor state."""
|
"""Test integration sensor state."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -177,7 +177,7 @@ async def test_trapezoidal(hass):
|
||||||
assert state.attributes.get("unit_of_measurement") == UnitOfEnergy.KILO_WATT_HOUR
|
assert state.attributes.get("unit_of_measurement") == UnitOfEnergy.KILO_WATT_HOUR
|
||||||
|
|
||||||
|
|
||||||
async def test_left(hass):
|
async def test_left(hass: HomeAssistant) -> None:
|
||||||
"""Test integration sensor state with left reimann method."""
|
"""Test integration sensor state with left reimann method."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -217,7 +217,7 @@ async def test_left(hass):
|
||||||
assert state.attributes.get("unit_of_measurement") == UnitOfEnergy.KILO_WATT_HOUR
|
assert state.attributes.get("unit_of_measurement") == UnitOfEnergy.KILO_WATT_HOUR
|
||||||
|
|
||||||
|
|
||||||
async def test_right(hass):
|
async def test_right(hass: HomeAssistant) -> None:
|
||||||
"""Test integration sensor state with left reimann method."""
|
"""Test integration sensor state with left reimann method."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -257,7 +257,7 @@ async def test_right(hass):
|
||||||
assert state.attributes.get("unit_of_measurement") == UnitOfEnergy.KILO_WATT_HOUR
|
assert state.attributes.get("unit_of_measurement") == UnitOfEnergy.KILO_WATT_HOUR
|
||||||
|
|
||||||
|
|
||||||
async def test_prefix(hass):
|
async def test_prefix(hass: HomeAssistant) -> None:
|
||||||
"""Test integration sensor state using a power source."""
|
"""Test integration sensor state using a power source."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -293,7 +293,7 @@ async def test_prefix(hass):
|
||||||
assert state.attributes.get("unit_of_measurement") == UnitOfEnergy.KILO_WATT_HOUR
|
assert state.attributes.get("unit_of_measurement") == UnitOfEnergy.KILO_WATT_HOUR
|
||||||
|
|
||||||
|
|
||||||
async def test_suffix(hass):
|
async def test_suffix(hass: HomeAssistant) -> None:
|
||||||
"""Test integration sensor state using a network counter source."""
|
"""Test integration sensor state using a network counter source."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -332,7 +332,7 @@ async def test_suffix(hass):
|
||||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfInformation.KILOBYTES
|
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfInformation.KILOBYTES
|
||||||
|
|
||||||
|
|
||||||
async def test_suffix_2(hass):
|
async def test_suffix_2(hass: HomeAssistant) -> None:
|
||||||
"""Test integration sensor state."""
|
"""Test integration sensor state."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -368,7 +368,7 @@ async def test_suffix_2(hass):
|
||||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == "m³"
|
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == "m³"
|
||||||
|
|
||||||
|
|
||||||
async def test_units(hass):
|
async def test_units(hass: HomeAssistant) -> None:
|
||||||
"""Test integration sensor units using a power source."""
|
"""Test integration sensor units using a power source."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -409,7 +409,7 @@ async def test_units(hass):
|
||||||
assert state.attributes.get("unit_of_measurement") == UnitOfEnergy.WATT_HOUR
|
assert state.attributes.get("unit_of_measurement") == UnitOfEnergy.WATT_HOUR
|
||||||
|
|
||||||
|
|
||||||
async def test_device_class(hass):
|
async def test_device_class(hass: HomeAssistant) -> None:
|
||||||
"""Test integration sensor units using a power source."""
|
"""Test integration sensor units using a power source."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -458,7 +458,7 @@ async def test_device_class(hass):
|
||||||
assert state.attributes.get("device_class") == SensorDeviceClass.ENERGY
|
assert state.attributes.get("device_class") == SensorDeviceClass.ENERGY
|
||||||
|
|
||||||
|
|
||||||
async def test_calc_errors(hass):
|
async def test_calc_errors(hass: HomeAssistant) -> None:
|
||||||
"""Test integration sensor units using a power source."""
|
"""Test integration sensor units using a power source."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
|
|
@ -3,6 +3,7 @@ import pytest
|
||||||
|
|
||||||
from homeassistant.components.cover import SERVICE_OPEN_COVER
|
from homeassistant.components.cover import SERVICE_OPEN_COVER
|
||||||
from homeassistant.const import SERVICE_TOGGLE, SERVICE_TURN_OFF, SERVICE_TURN_ON
|
from homeassistant.const import SERVICE_TOGGLE, SERVICE_TURN_OFF, SERVICE_TURN_ON
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import intent
|
from homeassistant.helpers import intent
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ async def test_http_handle_intent(hass, hass_client, hass_admin_user):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_cover_intents_loading(hass):
|
async def test_cover_intents_loading(hass: HomeAssistant) -> None:
|
||||||
"""Test Cover Intents Loading."""
|
"""Test Cover Intents Loading."""
|
||||||
assert await async_setup_component(hass, "intent", {})
|
assert await async_setup_component(hass, "intent", {})
|
||||||
|
|
||||||
|
@ -86,7 +87,7 @@ async def test_cover_intents_loading(hass):
|
||||||
assert call.data == {"entity_id": "cover.garage_door"}
|
assert call.data == {"entity_id": "cover.garage_door"}
|
||||||
|
|
||||||
|
|
||||||
async def test_turn_on_intent(hass):
|
async def test_turn_on_intent(hass: HomeAssistant) -> None:
|
||||||
"""Test HassTurnOn intent."""
|
"""Test HassTurnOn intent."""
|
||||||
result = await async_setup_component(hass, "homeassistant", {})
|
result = await async_setup_component(hass, "homeassistant", {})
|
||||||
result = await async_setup_component(hass, "intent", {})
|
result = await async_setup_component(hass, "intent", {})
|
||||||
|
@ -108,7 +109,7 @@ async def test_turn_on_intent(hass):
|
||||||
assert call.data == {"entity_id": ["light.test_light"]}
|
assert call.data == {"entity_id": ["light.test_light"]}
|
||||||
|
|
||||||
|
|
||||||
async def test_turn_off_intent(hass):
|
async def test_turn_off_intent(hass: HomeAssistant) -> None:
|
||||||
"""Test HassTurnOff intent."""
|
"""Test HassTurnOff intent."""
|
||||||
result = await async_setup_component(hass, "homeassistant", {})
|
result = await async_setup_component(hass, "homeassistant", {})
|
||||||
result = await async_setup_component(hass, "intent", {})
|
result = await async_setup_component(hass, "intent", {})
|
||||||
|
@ -129,7 +130,7 @@ async def test_turn_off_intent(hass):
|
||||||
assert call.data == {"entity_id": ["light.test_light"]}
|
assert call.data == {"entity_id": ["light.test_light"]}
|
||||||
|
|
||||||
|
|
||||||
async def test_toggle_intent(hass):
|
async def test_toggle_intent(hass: HomeAssistant) -> None:
|
||||||
"""Test HassToggle intent."""
|
"""Test HassToggle intent."""
|
||||||
result = await async_setup_component(hass, "homeassistant", {})
|
result = await async_setup_component(hass, "homeassistant", {})
|
||||||
result = await async_setup_component(hass, "intent", {})
|
result = await async_setup_component(hass, "intent", {})
|
||||||
|
@ -150,7 +151,7 @@ async def test_toggle_intent(hass):
|
||||||
assert call.data == {"entity_id": ["light.test_light"]}
|
assert call.data == {"entity_id": ["light.test_light"]}
|
||||||
|
|
||||||
|
|
||||||
async def test_turn_on_multiple_intent(hass):
|
async def test_turn_on_multiple_intent(hass: HomeAssistant) -> None:
|
||||||
"""Test HassTurnOn intent with multiple similar entities.
|
"""Test HassTurnOn intent with multiple similar entities.
|
||||||
|
|
||||||
This tests that matching finds the proper entity among similar names.
|
This tests that matching finds the proper entity among similar names.
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
"""Test intent_script component."""
|
"""Test intent_script component."""
|
||||||
from homeassistant.bootstrap import async_setup_component
|
from homeassistant.bootstrap import async_setup_component
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import intent
|
from homeassistant.helpers import intent
|
||||||
|
|
||||||
from tests.common import async_mock_service
|
from tests.common import async_mock_service
|
||||||
|
|
||||||
|
|
||||||
async def test_intent_script(hass):
|
async def test_intent_script(hass: HomeAssistant) -> None:
|
||||||
"""Test intent scripts work."""
|
"""Test intent scripts work."""
|
||||||
calls = async_mock_service(hass, "test", "service")
|
calls = async_mock_service(hass, "test", "service")
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ async def test_intent_script(hass):
|
||||||
assert response.card["simple"]["content"] == "Content for Paulus"
|
assert response.card["simple"]["content"] == "Content for Paulus"
|
||||||
|
|
||||||
|
|
||||||
async def test_intent_script_wait_response(hass):
|
async def test_intent_script_wait_response(hass: HomeAssistant) -> None:
|
||||||
"""Test intent scripts work."""
|
"""Test intent scripts work."""
|
||||||
calls = async_mock_service(hass, "test", "service")
|
calls = async_mock_service(hass, "test", "service")
|
||||||
|
|
||||||
|
@ -89,7 +90,7 @@ async def test_intent_script_wait_response(hass):
|
||||||
assert response.card["simple"]["content"] == "Content for Paulus"
|
assert response.card["simple"]["content"] == "Content for Paulus"
|
||||||
|
|
||||||
|
|
||||||
async def test_intent_script_falsy_reprompt(hass):
|
async def test_intent_script_falsy_reprompt(hass: HomeAssistant) -> None:
|
||||||
"""Test intent scripts work."""
|
"""Test intent scripts work."""
|
||||||
calls = async_mock_service(hass, "test", "service")
|
calls = async_mock_service(hass, "test", "service")
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ from unittest.mock import patch
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import ios
|
from homeassistant.components import ios
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import mock_component, mock_coro
|
from tests.common import mock_component, mock_coro
|
||||||
|
@ -23,7 +24,7 @@ def mock_dependencies(hass):
|
||||||
mock_component(hass, "device_tracker")
|
mock_component(hass, "device_tracker")
|
||||||
|
|
||||||
|
|
||||||
async def test_creating_entry_sets_up_sensor(hass):
|
async def test_creating_entry_sets_up_sensor(hass: HomeAssistant) -> None:
|
||||||
"""Test setting up iOS loads the sensor component."""
|
"""Test setting up iOS loads the sensor component."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.ios.sensor.async_setup_entry",
|
"homeassistant.components.ios.sensor.async_setup_entry",
|
||||||
|
@ -35,7 +36,7 @@ async def test_creating_entry_sets_up_sensor(hass):
|
||||||
assert len(mock_setup.mock_calls) == 1
|
assert len(mock_setup.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_configuring_ios_creates_entry(hass):
|
async def test_configuring_ios_creates_entry(hass: HomeAssistant) -> None:
|
||||||
"""Test that specifying config will create an entry."""
|
"""Test that specifying config will create an entry."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.ios.async_setup_entry", return_value=mock_coro(True)
|
"homeassistant.components.ios.async_setup_entry", return_value=mock_coro(True)
|
||||||
|
@ -46,7 +47,7 @@ async def test_configuring_ios_creates_entry(hass):
|
||||||
assert len(mock_setup.mock_calls) == 1
|
assert len(mock_setup.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_not_configuring_ios_not_creates_entry(hass):
|
async def test_not_configuring_ios_not_creates_entry(hass: HomeAssistant) -> None:
|
||||||
"""Test that no config will not create an entry."""
|
"""Test that no config will not create an entry."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.ios.async_setup_entry", return_value=mock_coro(True)
|
"homeassistant.components.ios.async_setup_entry", return_value=mock_coro(True)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
"""Tests for IPMA config flow."""
|
"""Tests for IPMA config flow."""
|
||||||
|
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
from homeassistant.components.ipma import DOMAIN, config_flow
|
from homeassistant.components.ipma import DOMAIN, config_flow
|
||||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_MODE
|
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_MODE
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ async def test_show_config_form_default_values() -> None:
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_with_home_location(hass):
|
async def test_flow_with_home_location(hass: HomeAssistant) -> None:
|
||||||
"""Test config flow .
|
"""Test config flow .
|
||||||
|
|
||||||
Tests the flow when a default location is configured
|
Tests the flow when a default location is configured
|
||||||
|
@ -122,7 +122,7 @@ async def test_flow_entry_config_entry_already_exists() -> None:
|
||||||
assert len(flow._errors) == 1
|
assert len(flow._errors) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_config_entry_migration(hass):
|
async def test_config_entry_migration(hass: HomeAssistant) -> None:
|
||||||
"""Tests config entry without mode in unique_id can be migrated."""
|
"""Tests config entry without mode in unique_id can be migrated."""
|
||||||
ipma_entry = MockConfigEntry(
|
ipma_entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""Test the IPMA integration."""
|
"""Test the IPMA integration."""
|
||||||
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from pyipma import IPMAException
|
from pyipma import IPMAException
|
||||||
|
@ -7,13 +6,14 @@ from pyipma import IPMAException
|
||||||
from homeassistant.components.ipma import DOMAIN
|
from homeassistant.components.ipma import DOMAIN
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_MODE
|
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_MODE
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .test_weather import MockLocation
|
from .test_weather import MockLocation
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_async_setup_raises_entry_not_ready(hass):
|
async def test_async_setup_raises_entry_not_ready(hass: HomeAssistant) -> None:
|
||||||
"""Test that it throws ConfigEntryNotReady when exception occurs during setup."""
|
"""Test that it throws ConfigEntryNotReady when exception occurs during setup."""
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -32,7 +32,7 @@ async def test_async_setup_raises_entry_not_ready(hass):
|
||||||
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||||
|
|
||||||
|
|
||||||
async def test_unload_config_entry(hass):
|
async def test_unload_config_entry(hass: HomeAssistant) -> None:
|
||||||
"""Test entry unloading."""
|
"""Test entry unloading."""
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
|
|
@ -2,12 +2,16 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from homeassistant.components.ipma.system_health import IPMA_API_URL
|
from homeassistant.components.ipma.system_health import IPMA_API_URL
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import get_system_health_info
|
from tests.common import get_system_health_info
|
||||||
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
|
|
||||||
async def test_ipma_system_health(hass, aioclient_mock):
|
async def test_ipma_system_health(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test ipma system health."""
|
"""Test ipma system health."""
|
||||||
aioclient_mock.get(IPMA_API_URL, json={"result": "ok", "data": {}})
|
aioclient_mock.get(IPMA_API_URL, json={"result": "ok", "data": {}})
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ from homeassistant.components.weather import (
|
||||||
ATTR_WEATHER_WIND_SPEED,
|
ATTR_WEATHER_WIND_SPEED,
|
||||||
)
|
)
|
||||||
from homeassistant.const import STATE_UNKNOWN
|
from homeassistant.const import STATE_UNKNOWN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import MockLocation
|
from . import MockLocation
|
||||||
|
|
||||||
|
@ -52,7 +53,7 @@ class MockBadLocation(MockLocation):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_config_flow(hass):
|
async def test_setup_config_flow(hass: HomeAssistant) -> None:
|
||||||
"""Test for successfully setting up the IPMA platform."""
|
"""Test for successfully setting up the IPMA platform."""
|
||||||
with patch(
|
with patch(
|
||||||
"pyipma.location.Location.get",
|
"pyipma.location.Location.get",
|
||||||
|
@ -75,7 +76,7 @@ async def test_setup_config_flow(hass):
|
||||||
assert state.attributes.get("friendly_name") == "HomeTown"
|
assert state.attributes.get("friendly_name") == "HomeTown"
|
||||||
|
|
||||||
|
|
||||||
async def test_daily_forecast(hass):
|
async def test_daily_forecast(hass: HomeAssistant) -> None:
|
||||||
"""Test for successfully getting daily forecast."""
|
"""Test for successfully getting daily forecast."""
|
||||||
with patch(
|
with patch(
|
||||||
"pyipma.location.Location.get",
|
"pyipma.location.Location.get",
|
||||||
|
@ -100,7 +101,7 @@ async def test_daily_forecast(hass):
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2020-01-14 23:00:00")
|
@freeze_time("2020-01-14 23:00:00")
|
||||||
async def test_hourly_forecast(hass):
|
async def test_hourly_forecast(hass: HomeAssistant) -> None:
|
||||||
"""Test for successfully getting daily forecast."""
|
"""Test for successfully getting daily forecast."""
|
||||||
with patch(
|
with patch(
|
||||||
"pyipma.location.Location.get",
|
"pyipma.location.Location.get",
|
||||||
|
@ -122,7 +123,7 @@ async def test_hourly_forecast(hass):
|
||||||
assert forecast.get(ATTR_FORECAST_WIND_BEARING) == "S"
|
assert forecast.get(ATTR_FORECAST_WIND_BEARING) == "S"
|
||||||
|
|
||||||
|
|
||||||
async def test_failed_get_observation_forecast(hass):
|
async def test_failed_get_observation_forecast(hass: HomeAssistant) -> None:
|
||||||
"""Test for successfully setting up the IPMA platform."""
|
"""Test for successfully setting up the IPMA platform."""
|
||||||
with patch(
|
with patch(
|
||||||
"pyipma.location.Location.get",
|
"pyipma.location.Location.get",
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
from homeassistant.components.iqvia import CONF_ZIP_CODE, DOMAIN
|
from homeassistant.components.iqvia import CONF_ZIP_CODE, DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_USER
|
from homeassistant.config_entries import SOURCE_USER
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
|
||||||
async def test_duplicate_error(hass, config, config_entry):
|
async def test_duplicate_error(hass, config, config_entry):
|
||||||
|
@ -13,7 +14,7 @@ async def test_duplicate_error(hass, config, config_entry):
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_invalid_zip_code(hass):
|
async def test_invalid_zip_code(hass: HomeAssistant) -> None:
|
||||||
"""Test that an invalid ZIP code key throws an error."""
|
"""Test that an invalid ZIP code key throws an error."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": SOURCE_USER}, data={CONF_ZIP_CODE: "bad"}
|
DOMAIN, context={"source": SOURCE_USER}, data={CONF_ZIP_CODE: "bad"}
|
||||||
|
@ -22,7 +23,7 @@ async def test_invalid_zip_code(hass):
|
||||||
assert result["errors"] == {CONF_ZIP_CODE: "invalid_zip_code"}
|
assert result["errors"] == {CONF_ZIP_CODE: "invalid_zip_code"}
|
||||||
|
|
||||||
|
|
||||||
async def test_show_form(hass):
|
async def test_show_form(hass: HomeAssistant) -> None:
|
||||||
"""Test that the form is served with no input."""
|
"""Test that the form is served with no input."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": SOURCE_USER}
|
DOMAIN, context={"source": SOURCE_USER}
|
||||||
|
|
|
@ -7,6 +7,7 @@ from homeassistant import config_entries, data_entry_flow
|
||||||
from homeassistant.components import islamic_prayer_times
|
from homeassistant.components import islamic_prayer_times
|
||||||
from homeassistant.components.islamic_prayer_times import config_flow # noqa: F401
|
from homeassistant.components.islamic_prayer_times import config_flow # noqa: F401
|
||||||
from homeassistant.components.islamic_prayer_times.const import CONF_CALC_METHOD, DOMAIN
|
from homeassistant.components.islamic_prayer_times.const import CONF_CALC_METHOD, DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ def mock_setup():
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_works(hass):
|
async def test_flow_works(hass: HomeAssistant) -> None:
|
||||||
"""Test user config."""
|
"""Test user config."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
islamic_prayer_times.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
islamic_prayer_times.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -36,7 +37,7 @@ async def test_flow_works(hass):
|
||||||
assert result["title"] == "Islamic Prayer Times"
|
assert result["title"] == "Islamic Prayer Times"
|
||||||
|
|
||||||
|
|
||||||
async def test_options(hass):
|
async def test_options(hass: HomeAssistant) -> None:
|
||||||
"""Test updating options."""
|
"""Test updating options."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -59,7 +60,7 @@ async def test_options(hass):
|
||||||
assert result["data"][CONF_CALC_METHOD] == "makkah"
|
assert result["data"][CONF_CALC_METHOD] == "makkah"
|
||||||
|
|
||||||
|
|
||||||
async def test_integration_already_configured(hass):
|
async def test_integration_already_configured(hass: HomeAssistant) -> None:
|
||||||
"""Test integration is already configured."""
|
"""Test integration is already configured."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
"""Tests for Islamic Prayer Times init."""
|
"""Tests for Islamic Prayer Times init."""
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
@ -9,6 +8,7 @@ import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components import islamic_prayer_times
|
from homeassistant.components import islamic_prayer_times
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
NEW_PRAYER_TIMES,
|
NEW_PRAYER_TIMES,
|
||||||
|
@ -27,7 +27,7 @@ def set_utc(hass):
|
||||||
hass.config.set_time_zone("UTC")
|
hass.config.set_time_zone("UTC")
|
||||||
|
|
||||||
|
|
||||||
async def test_successful_config_entry(hass):
|
async def test_successful_config_entry(hass: HomeAssistant) -> None:
|
||||||
"""Test that Islamic Prayer Times is configured successfully."""
|
"""Test that Islamic Prayer Times is configured successfully."""
|
||||||
|
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
|
@ -49,7 +49,7 @@ async def test_successful_config_entry(hass):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_failed(hass):
|
async def test_setup_failed(hass: HomeAssistant) -> None:
|
||||||
"""Test Islamic Prayer Times failed due to an error."""
|
"""Test Islamic Prayer Times failed due to an error."""
|
||||||
|
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
|
@ -68,7 +68,7 @@ async def test_setup_failed(hass):
|
||||||
assert entry.state is config_entries.ConfigEntryState.SETUP_RETRY
|
assert entry.state is config_entries.ConfigEntryState.SETUP_RETRY
|
||||||
|
|
||||||
|
|
||||||
async def test_unload_entry(hass):
|
async def test_unload_entry(hass: HomeAssistant) -> None:
|
||||||
"""Test removing Islamic Prayer Times."""
|
"""Test removing Islamic Prayer Times."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=islamic_prayer_times.DOMAIN,
|
domain=islamic_prayer_times.DOMAIN,
|
||||||
|
@ -88,7 +88,7 @@ async def test_unload_entry(hass):
|
||||||
assert islamic_prayer_times.DOMAIN not in hass.data
|
assert islamic_prayer_times.DOMAIN not in hass.data
|
||||||
|
|
||||||
|
|
||||||
async def test_islamic_prayer_times_timestamp_format(hass):
|
async def test_islamic_prayer_times_timestamp_format(hass: HomeAssistant) -> None:
|
||||||
"""Test Islamic prayer times timestamp format."""
|
"""Test Islamic prayer times timestamp format."""
|
||||||
entry = MockConfigEntry(domain=islamic_prayer_times.DOMAIN, data={})
|
entry = MockConfigEntry(domain=islamic_prayer_times.DOMAIN, data={})
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
@ -106,7 +106,7 @@ async def test_islamic_prayer_times_timestamp_format(hass):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_update(hass):
|
async def test_update(hass: HomeAssistant) -> None:
|
||||||
"""Test sensors are updated with new prayer times."""
|
"""Test sensors are updated with new prayer times."""
|
||||||
entry = MockConfigEntry(domain=islamic_prayer_times.DOMAIN, data={})
|
entry = MockConfigEntry(domain=islamic_prayer_times.DOMAIN, data={})
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
|
@ -5,6 +5,7 @@ from freezegun import freeze_time
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import islamic_prayer_times
|
from homeassistant.components import islamic_prayer_times
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
from . import NOW, PRAYER_TIMES, PRAYER_TIMES_TIMESTAMPS
|
from . import NOW, PRAYER_TIMES, PRAYER_TIMES_TIMESTAMPS
|
||||||
|
@ -18,7 +19,7 @@ def set_utc(hass):
|
||||||
hass.config.set_time_zone("UTC")
|
hass.config.set_time_zone("UTC")
|
||||||
|
|
||||||
|
|
||||||
async def test_islamic_prayer_times_sensors(hass):
|
async def test_islamic_prayer_times_sensors(hass: HomeAssistant) -> None:
|
||||||
"""Test minimum Islamic prayer times configuration."""
|
"""Test minimum Islamic prayer times configuration."""
|
||||||
entry = MockConfigEntry(domain=islamic_prayer_times.DOMAIN, data={})
|
entry = MockConfigEntry(domain=islamic_prayer_times.DOMAIN, data={})
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
|
@ -721,7 +721,7 @@ async def test_form_dhcp_existing_ignored_entry(hass: HomeAssistant):
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_reauth(hass):
|
async def test_reauth(hass: HomeAssistant) -> None:
|
||||||
"""Test we can reauth."""
|
"""Test we can reauth."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
|
|
@ -6,18 +6,22 @@ from aiohttp import ClientError
|
||||||
|
|
||||||
from homeassistant.components.isy994.const import DOMAIN, ISY_URL_POSTFIX
|
from homeassistant.components.isy994.const import DOMAIN, ISY_URL_POSTFIX
|
||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .test_config_flow import MOCK_HOSTNAME, MOCK_UUID
|
from .test_config_flow import MOCK_HOSTNAME, MOCK_UUID
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, get_system_health_info
|
from tests.common import MockConfigEntry, get_system_health_info
|
||||||
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
MOCK_ENTRY_ID = "cad4af20b811990e757588519917d6af"
|
MOCK_ENTRY_ID = "cad4af20b811990e757588519917d6af"
|
||||||
MOCK_CONNECTED = "connected"
|
MOCK_CONNECTED = "connected"
|
||||||
MOCK_HEARTBEAT = "2021-05-01T00:00:00.000000"
|
MOCK_HEARTBEAT = "2021-05-01T00:00:00.000000"
|
||||||
|
|
||||||
|
|
||||||
async def test_system_health(hass, aioclient_mock):
|
async def test_system_health(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test system health."""
|
"""Test system health."""
|
||||||
aioclient_mock.get(f"http://{MOCK_HOSTNAME}{ISY_URL_POSTFIX}", text="")
|
aioclient_mock.get(f"http://{MOCK_HOSTNAME}{ISY_URL_POSTFIX}", text="")
|
||||||
|
|
||||||
|
@ -54,7 +58,9 @@ async def test_system_health(hass, aioclient_mock):
|
||||||
assert info["websocket_status"] == MOCK_CONNECTED
|
assert info["websocket_status"] == MOCK_CONNECTED
|
||||||
|
|
||||||
|
|
||||||
async def test_system_health_failed_connect(hass, aioclient_mock):
|
async def test_system_health_failed_connect(
|
||||||
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
|
) -> None:
|
||||||
"""Test system health."""
|
"""Test system health."""
|
||||||
aioclient_mock.get(f"http://{MOCK_HOSTNAME}{ISY_URL_POSTFIX}", exc=ClientError)
|
aioclient_mock.get(f"http://{MOCK_HOSTNAME}{ISY_URL_POSTFIX}", exc=ClientError)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue