Add type hints to integration tests (b-c) (#87698)

This commit is contained in:
epenet 2023-02-08 18:08:43 +01:00 committed by GitHub
parent 1a414f1433
commit 807c69f621
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 548 additions and 350 deletions

View file

@ -6,6 +6,7 @@ from homeassistant import config_entries
from homeassistant.components import zeroconf from homeassistant.components import zeroconf
from homeassistant.components.baf.const import DOMAIN from homeassistant.components.baf.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 . import MOCK_NAME, MOCK_UUID, MockBAFDevice from . import MOCK_NAME, MOCK_UUID, MockBAFDevice
@ -22,7 +23,7 @@ def _patch_device_config_flow(side_effect=None):
return patch("homeassistant.components.baf.config_flow.Device", _create_mock_baf) return patch("homeassistant.components.baf.config_flow.Device", _create_mock_baf)
async def test_form_user(hass): async def test_form_user(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(
@ -47,7 +48,7 @@ async def test_form_user(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}
@ -63,7 +64,7 @@ async def test_form_cannot_connect(hass):
assert result2["errors"] == {CONF_IP_ADDRESS: "cannot_connect"} assert result2["errors"] == {CONF_IP_ADDRESS: "cannot_connect"}
async def test_form_unknown_exception(hass): async def test_form_unknown_exception(hass: HomeAssistant) -> None:
"""Test we handle unknown exceptions.""" """Test we handle unknown exceptions."""
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}
@ -79,7 +80,7 @@ async def test_form_unknown_exception(hass):
assert result2["errors"] == {"base": "unknown"} assert result2["errors"] == {"base": "unknown"}
async def test_zeroconf_discovery(hass): async def test_zeroconf_discovery(hass: HomeAssistant) -> None:
"""Test we can setup from zeroconf discovery.""" """Test we can setup from zeroconf discovery."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -114,7 +115,7 @@ async def test_zeroconf_discovery(hass):
assert len(mock_setup_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1
async def test_zeroconf_updates_existing_ip(hass): async def test_zeroconf_updates_existing_ip(hass: HomeAssistant) -> None:
"""Test we can setup from zeroconf discovery.""" """Test we can setup from zeroconf discovery."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, data={CONF_IP_ADDRESS: "127.0.0.2"}, unique_id=MOCK_UUID domain=DOMAIN, data={CONF_IP_ADDRESS: "127.0.0.2"}, unique_id=MOCK_UUID
@ -138,7 +139,7 @@ async def test_zeroconf_updates_existing_ip(hass):
assert entry.data[CONF_IP_ADDRESS] == "127.0.0.1" assert entry.data[CONF_IP_ADDRESS] == "127.0.0.1"
async def test_zeroconf_rejects_ipv6(hass): async def test_zeroconf_rejects_ipv6(hass: HomeAssistant) -> None:
"""Test zeroconf discovery rejects ipv6.""" """Test zeroconf discovery rejects ipv6."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
@ -157,7 +158,7 @@ async def test_zeroconf_rejects_ipv6(hass):
assert result["reason"] == "ipv6_not_supported" assert result["reason"] == "ipv6_not_supported"
async def test_user_flow_is_not_blocked_by_discovery(hass): async def test_user_flow_is_not_blocked_by_discovery(hass: HomeAssistant) -> None:
"""Test we can setup from the user flow when there is also a discovery.""" """Test we can setup from the user flow when there is also a discovery."""
discovery_result = await hass.config_entries.flow.async_init( discovery_result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,

View file

@ -2,6 +2,8 @@
import json import json
from unittest.mock import patch from unittest.mock import patch
import pytest
from homeassistant import config as hass_config from homeassistant import config as hass_config
from homeassistant.components.bayesian import DOMAIN, binary_sensor as bayesian from homeassistant.components.bayesian import DOMAIN, binary_sensor as bayesian
from homeassistant.components.homeassistant import ( from homeassistant.components.homeassistant import (
@ -16,7 +18,7 @@ from homeassistant.const import (
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
STATE_UNKNOWN, STATE_UNKNOWN,
) )
from homeassistant.core import Context, callback from homeassistant.core import Context, HomeAssistant, callback
from homeassistant.helpers.entity_registry import async_get as async_get_entities from homeassistant.helpers.entity_registry import async_get as async_get_entities
from homeassistant.helpers.event import async_track_state_change_event from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.issue_registry import async_get from homeassistant.helpers.issue_registry import async_get
@ -25,7 +27,7 @@ from homeassistant.setup import async_setup_component
from tests.common import get_fixture_path from tests.common import get_fixture_path
async def test_load_values_when_added_to_hass(hass): async def test_load_values_when_added_to_hass(hass: HomeAssistant) -> None:
"""Test that sensor initializes with observations of relevant entities.""" """Test that sensor initializes with observations of relevant entities."""
config = { config = {
@ -66,7 +68,9 @@ async def test_load_values_when_added_to_hass(hass):
assert state.attributes.get("observations")[0]["prob_given_false"] == 0.4 assert state.attributes.get("observations")[0]["prob_given_false"] == 0.4
async def test_unknown_state_does_not_influence_probability(hass): async def test_unknown_state_does_not_influence_probability(
hass: HomeAssistant,
) -> None:
"""Test that an unknown state does not change the output probability.""" """Test that an unknown state does not change the output probability."""
prior = 0.2 prior = 0.2
config = { config = {
@ -99,7 +103,7 @@ async def test_unknown_state_does_not_influence_probability(hass):
assert state.attributes.get("probability") == prior assert state.attributes.get("probability") == prior
async def test_sensor_numeric_state(hass): async def test_sensor_numeric_state(hass: HomeAssistant) -> None:
"""Test sensor on numeric state platform observations.""" """Test sensor on numeric state platform observations."""
config = { config = {
"binary_sensor": { "binary_sensor": {
@ -198,7 +202,7 @@ async def test_sensor_numeric_state(hass):
assert len(async_get(hass).issues) == 0 assert len(async_get(hass).issues) == 0
async def test_sensor_state(hass): async def test_sensor_state(hass: HomeAssistant) -> None:
"""Test sensor on state platform observations.""" """Test sensor on state platform observations."""
prior = 0.2 prior = 0.2
config = { config = {
@ -271,7 +275,7 @@ async def test_sensor_state(hass):
assert state.state == "off" assert state.state == "off"
async def test_sensor_value_template(hass): async def test_sensor_value_template(hass: HomeAssistant) -> None:
"""Test sensor on template platform observations.""" """Test sensor on template platform observations."""
config = { config = {
"binary_sensor": { "binary_sensor": {
@ -324,7 +328,7 @@ async def test_sensor_value_template(hass):
assert state.state == "off" assert state.state == "off"
async def test_threshold(hass): async def test_threshold(hass: HomeAssistant) -> None:
"""Test sensor on probability threshold limits.""" """Test sensor on probability threshold limits."""
config = { config = {
"binary_sensor": { "binary_sensor": {
@ -357,7 +361,7 @@ async def test_threshold(hass):
assert len(async_get(hass).issues) == 0 assert len(async_get(hass).issues) == 0
async def test_multiple_observations(hass): async def test_multiple_observations(hass: HomeAssistant) -> None:
"""Test sensor with multiple observations of same entity. """Test sensor with multiple observations of same entity.
these entries should be labelled as 'multi_state' and negative observations ignored - as the outcome is not known to be binary. these entries should be labelled as 'multi_state' and negative observations ignored - as the outcome is not known to be binary.
@ -433,7 +437,7 @@ async def test_multiple_observations(hass):
assert state.attributes.get("observations")[1]["platform"] == "multi_state" assert state.attributes.get("observations")[1]["platform"] == "multi_state"
async def test_multiple_numeric_observations(hass): async def test_multiple_numeric_observations(hass: HomeAssistant) -> None:
"""Test sensor with multiple numeric observations of same entity.""" """Test sensor with multiple numeric observations of same entity."""
config = { config = {
@ -508,7 +512,7 @@ async def test_multiple_numeric_observations(hass):
assert state.attributes.get("observations")[1]["platform"] == "numeric_state" assert state.attributes.get("observations")[1]["platform"] == "numeric_state"
async def test_mirrored_observations(hass): async def test_mirrored_observations(hass: HomeAssistant) -> None:
"""Test whether mirrored entries are detected and appropriate issues are created.""" """Test whether mirrored entries are detected and appropriate issues are created."""
config = { config = {
@ -596,7 +600,7 @@ async def test_mirrored_observations(hass):
) )
async def test_missing_prob_given_false(hass): async def test_missing_prob_given_false(hass: HomeAssistant) -> None:
"""Test whether missing prob_given_false are detected and appropriate issues are created.""" """Test whether missing prob_given_false are detected and appropriate issues are created."""
config = { config = {
@ -640,7 +644,7 @@ async def test_missing_prob_given_false(hass):
) )
async def test_probability_updates(hass): async def test_probability_updates(hass: HomeAssistant) -> None:
"""Test probability update function.""" """Test probability update function."""
prob_given_true = [0.3, 0.6, 0.8] prob_given_true = [0.3, 0.6, 0.8]
prob_given_false = [0.7, 0.4, 0.2] prob_given_false = [0.7, 0.4, 0.2]
@ -661,7 +665,7 @@ async def test_probability_updates(hass):
assert round(abs(0.9130434782608695 - prior), 7) == 0 assert round(abs(0.9130434782608695 - prior), 7) == 0
async def test_observed_entities(hass): async def test_observed_entities(hass: HomeAssistant) -> None:
"""Test sensor on observed entities.""" """Test sensor on observed entities."""
config = { config = {
"binary_sensor": { "binary_sensor": {
@ -720,7 +724,7 @@ async def test_observed_entities(hass):
) )
async def test_state_attributes_are_serializable(hass): async def test_state_attributes_are_serializable(hass: HomeAssistant) -> None:
"""Test sensor on observed entities.""" """Test sensor on observed entities."""
config = { config = {
"binary_sensor": { "binary_sensor": {
@ -782,7 +786,9 @@ async def test_state_attributes_are_serializable(hass):
json.dumps(attrs) json.dumps(attrs)
async def test_template_error(hass, caplog): async def test_template_error(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test sensor with template error.""" """Test sensor with template error."""
config = { config = {
"binary_sensor": { "binary_sensor": {
@ -810,7 +816,7 @@ async def test_template_error(hass, caplog):
assert "xyz" in caplog.text assert "xyz" in caplog.text
async def test_update_request_with_template(hass): async def test_update_request_with_template(hass: HomeAssistant) -> None:
"""Test sensor on template platform observations that gets an update request.""" """Test sensor on template platform observations that gets an update request."""
config = { config = {
"binary_sensor": { "binary_sensor": {
@ -846,7 +852,7 @@ async def test_update_request_with_template(hass):
assert hass.states.get("binary_sensor.test_binary").state == "off" assert hass.states.get("binary_sensor.test_binary").state == "off"
async def test_update_request_without_template(hass): async def test_update_request_without_template(hass: HomeAssistant) -> None:
"""Test sensor on template platform observations that gets an update request.""" """Test sensor on template platform observations that gets an update request."""
config = { config = {
"binary_sensor": { "binary_sensor": {
@ -886,7 +892,7 @@ async def test_update_request_without_template(hass):
assert hass.states.get("binary_sensor.test_binary").state == "off" assert hass.states.get("binary_sensor.test_binary").state == "off"
async def test_monitored_sensor_goes_away(hass): async def test_monitored_sensor_goes_away(hass: HomeAssistant) -> None:
"""Test sensor on template platform observations that goes away.""" """Test sensor on template platform observations that goes away."""
config = { config = {
"binary_sensor": { "binary_sensor": {
@ -927,7 +933,7 @@ async def test_monitored_sensor_goes_away(hass):
assert hass.states.get("binary_sensor.test_binary").state == "off" assert hass.states.get("binary_sensor.test_binary").state == "off"
async def test_reload(hass): async def test_reload(hass: HomeAssistant) -> None:
"""Verify we can reload bayesian sensors.""" """Verify we can reload bayesian sensors."""
config = { config = {
@ -972,7 +978,7 @@ async def test_reload(hass):
assert hass.states.get("binary_sensor.test2") assert hass.states.get("binary_sensor.test2")
async def test_template_triggers(hass): async def test_template_triggers(hass: HomeAssistant) -> None:
"""Test sensor with template triggers.""" """Test sensor with template triggers."""
hass.states.async_set("input_boolean.test", STATE_OFF) hass.states.async_set("input_boolean.test", STATE_OFF)
config = { config = {
@ -1010,7 +1016,7 @@ async def test_template_triggers(hass):
assert events[0].context == context assert events[0].context == context
async def test_state_triggers(hass): async def test_state_triggers(hass: HomeAssistant) -> None:
"""Test sensor with state triggers.""" """Test sensor with state triggers."""
hass.states.async_set("sensor.test_monitored", STATE_OFF) hass.states.async_set("sensor.test_monitored", STATE_OFF)

View file

@ -1,5 +1,4 @@
"""Test Home Assistant config flow for BleBox devices.""" """Test Home Assistant config flow for BleBox devices."""
from unittest.mock import DEFAULT, AsyncMock, PropertyMock, patch from unittest.mock import DEFAULT, AsyncMock, PropertyMock, patch
import blebox_uniapi import blebox_uniapi
@ -9,6 +8,7 @@ from homeassistant import config_entries, data_entry_flow
from homeassistant.components import zeroconf from homeassistant.components import zeroconf
from homeassistant.components.blebox import config_flow from homeassistant.components.blebox import config_flow
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 homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -144,7 +144,7 @@ async def test_flow_with_unsupported_version(hass, product_class_mock):
assert result["errors"] == {"base": "unsupported_version"} assert result["errors"] == {"base": "unsupported_version"}
async def test_async_setup(hass): async def test_async_setup(hass: HomeAssistant) -> None:
"""Test async_setup (for coverage).""" """Test async_setup (for coverage)."""
assert await async_setup_component(hass, "blebox", {"host": "172.2.3.4"}) assert await async_setup_component(hass, "blebox", {"host": "172.2.3.4"})
await hass.async_block_till_done() await hass.async_block_till_done()
@ -197,7 +197,7 @@ async def test_async_remove_entry(hass, valid_feature_mock):
assert config.state is config_entries.ConfigEntryState.NOT_LOADED assert config.state is config_entries.ConfigEntryState.NOT_LOADED
async def test_flow_with_zeroconf(hass): async def test_flow_with_zeroconf(hass: HomeAssistant) -> None:
"""Test setup from zeroconf discovery.""" """Test setup from zeroconf discovery."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
config_flow.DOMAIN, config_flow.DOMAIN,
@ -223,7 +223,7 @@ async def test_flow_with_zeroconf(hass):
assert result2["data"] == {"host": "172.100.123.4", "port": 80} assert result2["data"] == {"host": "172.100.123.4", "port": 80}
async def test_flow_with_zeroconf_when_already_configured(hass): async def test_flow_with_zeroconf_when_already_configured(hass: HomeAssistant) -> None:
"""Test behaviour if device already configured.""" """Test behaviour if device already configured."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=config_flow.DOMAIN, domain=config_flow.DOMAIN,
@ -257,7 +257,7 @@ async def test_flow_with_zeroconf_when_already_configured(hass):
assert result2["reason"] == "already_configured" assert result2["reason"] == "already_configured"
async def test_flow_with_zeroconf_when_device_unsupported(hass): async def test_flow_with_zeroconf_when_device_unsupported(hass: HomeAssistant) -> None:
"""Test behaviour when device is not supported.""" """Test behaviour when device is not supported."""
with patch( with patch(
"homeassistant.components.blebox.config_flow.Box.async_from_host", "homeassistant.components.blebox.config_flow.Box.async_from_host",
@ -280,7 +280,9 @@ async def test_flow_with_zeroconf_when_device_unsupported(hass):
assert result["reason"] == "unsupported_device_version" assert result["reason"] == "unsupported_device_version"
async def test_flow_with_zeroconf_when_device_response_unsupported(hass): async def test_flow_with_zeroconf_when_device_response_unsupported(
hass: HomeAssistant,
) -> None:
"""Test behaviour when device returned unsupported response.""" """Test behaviour when device returned unsupported response."""
with patch( with patch(

View file

@ -1,16 +1,19 @@
"""BleBox devices setup tests.""" """BleBox devices setup tests."""
import logging import logging
import blebox_uniapi import blebox_uniapi
import pytest
from homeassistant.components.blebox.const import DOMAIN from homeassistant.components.blebox.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from .conftest import mock_config, patch_product_identify, setup_product_mock from .conftest import mock_config, patch_product_identify, setup_product_mock
async def test_setup_failure(hass, caplog): async def test_setup_failure(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test that setup failure is handled and logged.""" """Test that setup failure is handled and logged."""
patch_product_identify(None, side_effect=blebox_uniapi.error.ClientError) patch_product_identify(None, side_effect=blebox_uniapi.error.ClientError)
@ -26,7 +29,9 @@ async def test_setup_failure(hass, caplog):
assert entry.state is ConfigEntryState.SETUP_RETRY assert entry.state is ConfigEntryState.SETUP_RETRY
async def test_setup_failure_on_connection(hass, caplog): async def test_setup_failure_on_connection(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test that setup failure is handled and logged.""" """Test that setup failure is handled and logged."""
patch_product_identify(None, side_effect=blebox_uniapi.error.ConnectionError) patch_product_identify(None, side_effect=blebox_uniapi.error.ConnectionError)
@ -42,7 +47,7 @@ async def test_setup_failure_on_connection(hass, caplog):
assert entry.state is ConfigEntryState.SETUP_RETRY assert entry.state is ConfigEntryState.SETUP_RETRY
async def test_unload_config_entry(hass): async def test_unload_config_entry(hass: HomeAssistant) -> None:
"""Test that unloading works properly.""" """Test that unloading works properly."""
setup_product_mock("switches", []) setup_product_mock("switches", [])

View file

@ -11,7 +11,7 @@ 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(
@ -49,7 +49,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_2fa(hass): async def test_form_2fa(hass: HomeAssistant) -> None:
"""Test we get the 2fa form.""" """Test we get the 2fa form."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -91,7 +91,7 @@ async def test_form_2fa(hass):
assert len(mock_setup_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1
async def test_form_2fa_connect_error(hass): async def test_form_2fa_connect_error(hass: HomeAssistant) -> None:
"""Test we report a connect error during 2fa setup.""" """Test we report a connect error during 2fa setup."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -130,7 +130,7 @@ async def test_form_2fa_connect_error(hass):
assert result3["errors"] == {"base": "cannot_connect"} assert result3["errors"] == {"base": "cannot_connect"}
async def test_form_2fa_invalid_key(hass): async def test_form_2fa_invalid_key(hass: HomeAssistant) -> None:
"""Test we report an error if key is invalid.""" """Test we report an error if key is invalid."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -171,7 +171,7 @@ async def test_form_2fa_invalid_key(hass):
assert result3["errors"] == {"base": "invalid_access_token"} assert result3["errors"] == {"base": "invalid_access_token"}
async def test_form_2fa_unknown_error(hass): async def test_form_2fa_unknown_error(hass: HomeAssistant) -> None:
"""Test we report an unknown error during 2fa setup.""" """Test we report an unknown error during 2fa setup."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -210,7 +210,7 @@ async def test_form_2fa_unknown_error(hass):
assert result3["errors"] == {"base": "unknown"} assert result3["errors"] == {"base": "unknown"}
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}
@ -228,7 +228,7 @@ async def test_form_invalid_auth(hass):
assert result2["errors"] == {"base": "invalid_auth"} assert result2["errors"] == {"base": "invalid_auth"}
async def test_form_unknown_error(hass): async def test_form_unknown_error(hass: HomeAssistant) -> None:
"""Test we handle unknown error at startup.""" """Test we handle unknown error at startup."""
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}
@ -246,7 +246,7 @@ async def test_form_unknown_error(hass):
assert result2["errors"] == {"base": "unknown"} assert result2["errors"] == {"base": "unknown"}
async def test_reauth_shows_user_step(hass): async def test_reauth_shows_user_step(hass: HomeAssistant) -> None:
"""Test reauth shows the user form.""" """Test reauth shows the user form."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,

View file

@ -1,9 +1,9 @@
"""Test the BlueMaestro config flow.""" """Test the BlueMaestro 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.bluemaestro.const import DOMAIN from homeassistant.components.bluemaestro.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType from homeassistant.data_entry_flow import FlowResultType
from . import BLUEMAESTRO_SERVICE_INFO, NOT_BLUEMAESTRO_SERVICE_INFO from . import BLUEMAESTRO_SERVICE_INFO, NOT_BLUEMAESTRO_SERVICE_INFO
@ -11,7 +11,7 @@ from . import BLUEMAESTRO_SERVICE_INFO, NOT_BLUEMAESTRO_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,
@ -32,7 +32,7 @@ async def test_async_step_bluetooth_valid_device(hass):
assert result2["result"].unique_id == "aa:bb:cc:dd:ee:ff" assert result2["result"].unique_id == "aa:bb:cc:dd:ee:ff"
async def test_async_step_bluetooth_not_bluemaestro(hass): async def test_async_step_bluetooth_not_bluemaestro(hass: HomeAssistant) -> None:
"""Test discovery via bluetooth not bluemaestro.""" """Test discovery via bluetooth not bluemaestro."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
@ -43,7 +43,7 @@ async def test_async_step_bluetooth_not_bluemaestro(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,
@ -53,7 +53,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.bluemaestro.config_flow.async_discovered_service_info", "homeassistant.components.bluemaestro.config_flow.async_discovered_service_info",
@ -78,7 +78,7 @@ async def test_async_step_user_with_found_devices(hass):
assert result2["result"].unique_id == "aa:bb:cc:dd:ee:ff" assert result2["result"].unique_id == "aa:bb:cc:dd:ee:ff"
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.bluemaestro.config_flow.async_discovered_service_info", "homeassistant.components.bluemaestro.config_flow.async_discovered_service_info",
@ -108,7 +108,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,
@ -128,7 +130,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,
@ -145,7 +147,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,
@ -164,7 +166,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,

View file

@ -1,9 +1,8 @@
"""Test the BlueMaestro sensors.""" """Test the BlueMaestro sensors."""
from homeassistant.components.bluemaestro.const import DOMAIN from homeassistant.components.bluemaestro.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 BLUEMAESTRO_SERVICE_INFO from . import BLUEMAESTRO_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,

View file

@ -5,9 +5,11 @@ from pathlib import Path
import pytest import pytest
from homeassistant.components.blueprint import importer from homeassistant.components.blueprint import importer
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from tests.common import load_fixture from tests.common import load_fixture
from tests.test_util.aiohttp import AiohttpClientMocker
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
@ -208,7 +210,9 @@ async def test_fetch_blueprint_from_github_url(hass, aioclient_mock, url):
assert imported_blueprint.blueprint.metadata["source_url"] == url assert imported_blueprint.blueprint.metadata["source_url"] == url
async def test_fetch_blueprint_from_github_gist_url(hass, aioclient_mock): async def test_fetch_blueprint_from_github_gist_url(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test fetching blueprint from url.""" """Test fetching blueprint from url."""
aioclient_mock.get( aioclient_mock.get(
"https://api.github.com/gists/e717ce85dd0d2f1bdcdfc884ea25a344", "https://api.github.com/gists/e717ce85dd0d2f1bdcdfc884ea25a344",

View file

@ -4,9 +4,12 @@ from unittest.mock import Mock, patch
import pytest import pytest
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from homeassistant.util.yaml import parse_yaml from homeassistant.util.yaml import parse_yaml
from tests.typing import WebSocketGenerator
@pytest.fixture @pytest.fixture
def automation_config(): def automation_config():
@ -30,7 +33,9 @@ async def setup_bp(hass, automation_config, script_config):
await async_setup_component(hass, "script", script_config) await async_setup_component(hass, "script", script_config)
async def test_list_blueprints(hass, hass_ws_client): async def test_list_blueprints(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test listing blueprints.""" """Test listing blueprints."""
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
await client.send_json({"id": 5, "type": "blueprint/list", "domain": "automation"}) await client.send_json({"id": 5, "type": "blueprint/list", "domain": "automation"})
@ -62,7 +67,9 @@ async def test_list_blueprints(hass, hass_ws_client):
} }
async def test_list_blueprints_non_existing_domain(hass, hass_ws_client): async def test_list_blueprints_non_existing_domain(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test listing blueprints.""" """Test listing blueprints."""
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
await client.send_json( await client.send_json(

View file

@ -1,5 +1,4 @@
"""Test the bluetooth config flow.""" """Test the bluetooth config flow."""
from unittest.mock import patch from unittest.mock import patch
from bluetooth_adapters import DEFAULT_ADDRESS, AdapterDetails from bluetooth_adapters import DEFAULT_ADDRESS, AdapterDetails
@ -11,6 +10,7 @@ from homeassistant.components.bluetooth.const import (
CONF_PASSIVE, CONF_PASSIVE,
DOMAIN, DOMAIN,
) )
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType from homeassistant.data_entry_flow import FlowResultType
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -126,7 +126,7 @@ async def test_async_step_user_only_allows_one(hass, macos_adapter):
assert result["reason"] == "no_adapters" assert result["reason"] == "no_adapters"
async def test_async_step_integration_discovery(hass): async def test_async_step_integration_discovery(hass: HomeAssistant) -> None:
"""Test setting up from integration discovery.""" """Test setting up from integration discovery."""
details = AdapterDetails( details = AdapterDetails(
@ -264,7 +264,9 @@ async def test_async_step_integration_discovery_during_onboarding(hass, macos_ad
assert len(mock_onboarding.mock_calls) == 1 assert len(mock_onboarding.mock_calls) == 1
async def test_async_step_integration_discovery_already_exists(hass): async def test_async_step_integration_discovery_already_exists(
hass: HomeAssistant,
) -> None:
"""Test setting up from integration discovery when an entry already exists.""" """Test setting up from integration discovery when an entry already exists."""
details = AdapterDetails( details = AdapterDetails(
address="00:00:00:00:00:01", address="00:00:00:00:00:01",

View file

@ -2612,7 +2612,9 @@ async def test_auto_detect_bluetooth_adapters_linux_multiple(hass, two_adapters)
assert len(hass.config_entries.flow.async_progress(bluetooth.DOMAIN)) == 2 assert len(hass.config_entries.flow.async_progress(bluetooth.DOMAIN)) == 2
async def test_auto_detect_bluetooth_adapters_linux_none_found(hass): async def test_auto_detect_bluetooth_adapters_linux_none_found(
hass: HomeAssistant,
) -> None:
"""Test we auto detect bluetooth adapters on linux with no adapters found.""" """Test we auto detect bluetooth adapters on linux with no adapters found."""
with patch( with patch(
"bluetooth_adapters.systems.platform.system", return_value="Linux" "bluetooth_adapters.systems.platform.system", return_value="Linux"
@ -2626,7 +2628,7 @@ async def test_auto_detect_bluetooth_adapters_linux_none_found(hass):
assert len(hass.config_entries.flow.async_progress(bluetooth.DOMAIN)) == 0 assert len(hass.config_entries.flow.async_progress(bluetooth.DOMAIN)) == 0
async def test_auto_detect_bluetooth_adapters_macos(hass): async def test_auto_detect_bluetooth_adapters_macos(hass: HomeAssistant) -> None:
"""Test we auto detect bluetooth adapters on macos.""" """Test we auto detect bluetooth adapters on macos."""
with patch("bluetooth_adapters.systems.platform.system", return_value="Darwin"): with patch("bluetooth_adapters.systems.platform.system", return_value="Darwin"):
assert await async_setup_component(hass, bluetooth.DOMAIN, {}) assert await async_setup_component(hass, bluetooth.DOMAIN, {})
@ -2635,7 +2637,7 @@ async def test_auto_detect_bluetooth_adapters_macos(hass):
assert len(hass.config_entries.flow.async_progress(bluetooth.DOMAIN)) == 1 assert len(hass.config_entries.flow.async_progress(bluetooth.DOMAIN)) == 1
async def test_no_auto_detect_bluetooth_adapters_windows(hass): async def test_no_auto_detect_bluetooth_adapters_windows(hass: HomeAssistant) -> None:
"""Test we auto detect bluetooth adapters on windows.""" """Test we auto detect bluetooth adapters on windows."""
with patch( with patch(
"bluetooth_adapters.systems.platform.system", "bluetooth_adapters.systems.platform.system",

View file

@ -1,6 +1,4 @@
"""Tests for the Bluetooth integration.""" """Tests for the Bluetooth integration."""
from unittest.mock import patch from unittest.mock import patch
import bleak import bleak
@ -15,6 +13,7 @@ from homeassistant.components.bluetooth.wrappers import (
HaBleakClientWrapper, HaBleakClientWrapper,
HaBleakScannerWrapper, HaBleakScannerWrapper,
) )
from homeassistant.core import HomeAssistant
from . import _get_manager from . import _get_manager
@ -23,7 +22,7 @@ MOCK_BLE_DEVICE = BLEDevice(
) )
async def test_multiple_bleak_scanner_instances(hass): async def test_multiple_bleak_scanner_instances(hass: HomeAssistant) -> None:
"""Test creating multiple BleakScanners without an integration.""" """Test creating multiple BleakScanners without an integration."""
install_multiple_bleak_catcher() install_multiple_bleak_catcher()

View file

@ -11,6 +11,7 @@ from homeassistant.components.bmw_connected_drive.const import (
CONF_REFRESH_TOKEN, CONF_REFRESH_TOKEN,
) )
from homeassistant.const import CONF_USERNAME from homeassistant.const import CONF_USERNAME
from homeassistant.core import HomeAssistant
from . import FIXTURE_CONFIG_ENTRY, FIXTURE_REFRESH_TOKEN, FIXTURE_USER_INPUT from . import FIXTURE_CONFIG_ENTRY, FIXTURE_REFRESH_TOKEN, FIXTURE_USER_INPUT
@ -25,7 +26,7 @@ def login_sideeffect(self: MyBMWAuthentication):
self.refresh_token = FIXTURE_REFRESH_TOKEN self.refresh_token = FIXTURE_REFRESH_TOKEN
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": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -35,7 +36,7 @@ async def test_show_form(hass):
assert result["step_id"] == "user" assert result["step_id"] == "user"
async def test_connection_error(hass): async def test_connection_error(hass: HomeAssistant) -> None:
"""Test we show user form on BMW connected drive connection error.""" """Test we show user form on BMW connected drive connection error."""
def _mock_get_oauth_token(*args, **kwargs): def _mock_get_oauth_token(*args, **kwargs):
@ -56,7 +57,7 @@ async def test_connection_error(hass):
assert result["errors"] == {"base": "cannot_connect"} assert result["errors"] == {"base": "cannot_connect"}
async def test_full_user_flow_implementation(hass): async def test_full_user_flow_implementation(hass: HomeAssistant) -> None:
"""Test registering an integration and finishing flow works.""" """Test registering an integration and finishing flow works."""
with patch( with patch(
"bimmer_connected.api.authentication.MyBMWAuthentication.login", "bimmer_connected.api.authentication.MyBMWAuthentication.login",
@ -78,7 +79,7 @@ async def test_full_user_flow_implementation(hass):
assert len(mock_setup_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1
async def test_options_flow_implementation(hass): async def test_options_flow_implementation(hass: HomeAssistant) -> None:
"""Test config flow options.""" """Test config flow options."""
with patch( with patch(
"bimmer_connected.account.MyBMWAccount.get_vehicles", "bimmer_connected.account.MyBMWAccount.get_vehicles",

View file

@ -1,13 +1,16 @@
"""Test bond diagnostics.""" """Test bond diagnostics."""
from homeassistant.components.fan import DOMAIN as FAN_DOMAIN from homeassistant.components.fan import DOMAIN as FAN_DOMAIN
from homeassistant.core import HomeAssistant
from .common import ceiling_fan_with_breeze, setup_platform from .common import ceiling_fan_with_breeze, setup_platform
from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator
async def test_diagnostics(hass, hass_client): async def test_diagnostics(
hass: HomeAssistant, hass_client: ClientSessionGenerator
) -> None:
"""Test generating diagnostics for a config entry.""" """Test generating diagnostics for a config entry."""
entry = await setup_platform( entry = await setup_platform(

View file

@ -31,6 +31,7 @@ from .common import (
) )
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
from tests.typing import WebSocketGenerator
async def test_async_setup_no_domain_config(hass: HomeAssistant): async def test_async_setup_no_domain_config(hass: HomeAssistant):
@ -286,7 +287,9 @@ async def test_bridge_device_suggested_area(hass: HomeAssistant):
assert device.suggested_area == "Office" assert device.suggested_area == "Office"
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", {})

View file

@ -13,6 +13,7 @@ from homeassistant import config_entries
from homeassistant.components import zeroconf from homeassistant.components import zeroconf
from homeassistant.components.bosch_shc.config_flow import write_tls_asset from homeassistant.components.bosch_shc.config_flow import write_tls_asset
from homeassistant.components.bosch_shc.const import CONF_SHC_CERT, CONF_SHC_KEY, DOMAIN from homeassistant.components.bosch_shc.const import CONF_SHC_CERT, CONF_SHC_KEY, DOMAIN
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -117,7 +118,7 @@ async def test_form_get_info_connection_error(hass, mock_zeroconf):
assert result2["errors"] == {"base": "cannot_connect"} assert result2["errors"] == {"base": "cannot_connect"}
async def test_form_get_info_exception(hass): async def test_form_get_info_exception(hass: HomeAssistant) -> None:
"""Test we handle exceptions.""" """Test we handle exceptions."""
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}
@ -618,7 +619,7 @@ async def test_reauth(hass, mock_zeroconf):
assert len(mock_setup_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1
async def test_tls_assets_writer(hass): async def test_tls_assets_writer(hass: HomeAssistant) -> None:
"""Test we write tls assets to correct location.""" """Test we write tls assets to correct location."""
assets = { assets = {
"token": "abc:123", "token": "abc:123",

View file

@ -20,6 +20,7 @@ from homeassistant.components.braviatv.const import (
) )
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_SSDP, SOURCE_USER from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_SSDP, SOURCE_USER
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PIN from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PIN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import instance_id from homeassistant.helpers import instance_id
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -84,7 +85,7 @@ FAKE_BRAVIA_SSDP = ssdp.SsdpServiceInfo(
) )
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}
@ -94,7 +95,7 @@ async def test_show_form(hass):
assert result["step_id"] == SOURCE_USER assert result["step_id"] == SOURCE_USER
async def test_ssdp_discovery(hass): async def test_ssdp_discovery(hass: HomeAssistant) -> None:
"""Test that the device is discovered.""" """Test that the device is discovered."""
uuid = await instance_id.async_get(hass) uuid = await instance_id.async_get(hass)
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -145,7 +146,7 @@ async def test_ssdp_discovery(hass):
} }
async def test_ssdp_discovery_fake(hass): async def test_ssdp_discovery_fake(hass: HomeAssistant) -> None:
"""Test that not Bravia device is not discovered.""" """Test that not Bravia device is not discovered."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
@ -157,7 +158,7 @@ async def test_ssdp_discovery_fake(hass):
assert result["reason"] == "not_bravia_device" assert result["reason"] == "not_bravia_device"
async def test_ssdp_discovery_exist(hass): async def test_ssdp_discovery_exist(hass: HomeAssistant) -> None:
"""Test that the existed device is not discovered.""" """Test that the existed device is not discovered."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -181,7 +182,7 @@ async def test_ssdp_discovery_exist(hass):
assert result["reason"] == "already_configured" assert result["reason"] == "already_configured"
async def test_user_invalid_host(hass): async def test_user_invalid_host(hass: HomeAssistant) -> None:
"""Test that errors are shown when the host is invalid.""" """Test that errors are shown when the host is invalid."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data={CONF_HOST: "invalid/host"} DOMAIN, context={"source": SOURCE_USER}, data={CONF_HOST: "invalid/host"}
@ -244,7 +245,7 @@ async def test_psk_form_error(hass, side_effect, error_message):
assert result["errors"] == {"base": error_message} assert result["errors"] == {"base": error_message}
async def test_no_ip_control(hass): async def test_no_ip_control(hass: HomeAssistant) -> None:
"""Test that error are shown when IP Control is disabled on the TV.""" """Test that error are shown when IP Control is disabled on the TV."""
with patch("pybravia.BraviaClient.pair", side_effect=BraviaError): with patch("pybravia.BraviaClient.pair", side_effect=BraviaError):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -258,7 +259,7 @@ async def test_no_ip_control(hass):
assert result["reason"] == "no_ip_control" assert result["reason"] == "no_ip_control"
async def test_duplicate_error(hass): async def test_duplicate_error(hass: HomeAssistant) -> None:
"""Test that error are shown when duplicates are added.""" """Test that error are shown when duplicates are added."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -292,7 +293,7 @@ async def test_duplicate_error(hass):
assert result["reason"] == "already_configured" assert result["reason"] == "already_configured"
async def test_create_entry(hass): async def test_create_entry(hass: HomeAssistant) -> None:
"""Test that entry is added correctly with PIN auth.""" """Test that entry is added correctly with PIN auth."""
uuid = await instance_id.async_get(hass) uuid = await instance_id.async_get(hass)
@ -335,7 +336,7 @@ async def test_create_entry(hass):
} }
async def test_create_entry_psk(hass): async def test_create_entry_psk(hass: HomeAssistant) -> None:
"""Test that entry is added correctly with PSK auth.""" """Test that entry is added correctly with PSK auth."""
with patch("pybravia.BraviaClient.connect"), patch( with patch("pybravia.BraviaClient.connect"), patch(
"pybravia.BraviaClient.set_wol_mode" "pybravia.BraviaClient.set_wol_mode"

View file

@ -9,6 +9,7 @@ import pytest
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components import dhcp from homeassistant.components import dhcp
from homeassistant.components.broadlink.const import DOMAIN from homeassistant.components.broadlink.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry
from . import get_device from . import get_device
@ -26,7 +27,7 @@ def broadlink_setup_fixture():
yield yield
async def test_flow_user_works(hass): async def test_flow_user_works(hass: HomeAssistant) -> None:
"""Test a config flow initiated by the user. """Test a config flow initiated by the user.
Best case scenario with no errors or locks. Best case scenario with no errors or locks.
@ -65,7 +66,7 @@ async def test_flow_user_works(hass):
assert mock_api.auth.call_count == 1 assert mock_api.auth.call_count == 1
async def test_flow_user_already_in_progress(hass): async def test_flow_user_already_in_progress(hass: HomeAssistant) -> None:
"""Test we do not accept more than one config flow per device.""" """Test we do not accept more than one config flow per device."""
device = get_device("Living Room") device = get_device("Living Room")
@ -93,7 +94,7 @@ async def test_flow_user_already_in_progress(hass):
assert result["reason"] == "already_in_progress" assert result["reason"] == "already_in_progress"
async def test_flow_user_mac_already_configured(hass): async def test_flow_user_mac_already_configured(hass: HomeAssistant) -> None:
"""Test we do not accept more than one config entry per device. """Test we do not accept more than one config entry per device.
We need to abort the flow and update the existing entry. We need to abort the flow and update the existing entry.
@ -123,7 +124,7 @@ async def test_flow_user_mac_already_configured(hass):
assert mock_api.auth.call_count == 0 assert mock_api.auth.call_count == 0
async def test_flow_user_invalid_ip_address(hass): async def test_flow_user_invalid_ip_address(hass: HomeAssistant) -> None:
"""Test we handle an invalid IP address in the user step.""" """Test we handle an invalid IP address in the user step."""
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}
@ -140,7 +141,7 @@ async def test_flow_user_invalid_ip_address(hass):
assert result["errors"] == {"base": "invalid_host"} assert result["errors"] == {"base": "invalid_host"}
async def test_flow_user_invalid_hostname(hass): async def test_flow_user_invalid_hostname(hass: HomeAssistant) -> None:
"""Test we handle an invalid hostname in the user step.""" """Test we handle an invalid hostname in the user step."""
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}
@ -157,7 +158,7 @@ async def test_flow_user_invalid_hostname(hass):
assert result["errors"] == {"base": "invalid_host"} assert result["errors"] == {"base": "invalid_host"}
async def test_flow_user_device_not_found(hass): async def test_flow_user_device_not_found(hass: HomeAssistant) -> None:
"""Test we handle a device not found in the user step.""" """Test we handle a device not found in the user step."""
device = get_device("Living Room") device = get_device("Living Room")
@ -176,7 +177,7 @@ async def test_flow_user_device_not_found(hass):
assert result["errors"] == {"base": "cannot_connect"} assert result["errors"] == {"base": "cannot_connect"}
async def test_flow_user_device_not_supported(hass): async def test_flow_user_device_not_supported(hass: HomeAssistant) -> None:
"""Test we handle a device not supported in the user step.""" """Test we handle a device not supported in the user step."""
device = get_device("Kitchen") device = get_device("Kitchen")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -195,7 +196,7 @@ async def test_flow_user_device_not_supported(hass):
assert result["reason"] == "not_supported" assert result["reason"] == "not_supported"
async def test_flow_user_network_unreachable(hass): async def test_flow_user_network_unreachable(hass: HomeAssistant) -> None:
"""Test we handle a network unreachable in the user step.""" """Test we handle a network unreachable in the user step."""
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}
@ -212,7 +213,7 @@ async def test_flow_user_network_unreachable(hass):
assert result["errors"] == {"base": "cannot_connect"} assert result["errors"] == {"base": "cannot_connect"}
async def test_flow_user_os_error(hass): async def test_flow_user_os_error(hass: HomeAssistant) -> None:
"""Test we handle an OS error in the user step.""" """Test we handle an OS error in the user step."""
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}
@ -229,7 +230,7 @@ async def test_flow_user_os_error(hass):
assert result["errors"] == {"base": "unknown"} assert result["errors"] == {"base": "unknown"}
async def test_flow_auth_authentication_error(hass): async def test_flow_auth_authentication_error(hass: HomeAssistant) -> None:
"""Test we handle an authentication error in the auth step.""" """Test we handle an authentication error in the auth step."""
device = get_device("Living Room") device = get_device("Living Room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -250,7 +251,7 @@ async def test_flow_auth_authentication_error(hass):
assert result["errors"] == {"base": "invalid_auth"} assert result["errors"] == {"base": "invalid_auth"}
async def test_flow_auth_network_timeout(hass): async def test_flow_auth_network_timeout(hass: HomeAssistant) -> None:
"""Test we handle a network timeout in the auth step.""" """Test we handle a network timeout in the auth step."""
device = get_device("Living Room") device = get_device("Living Room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -271,7 +272,7 @@ async def test_flow_auth_network_timeout(hass):
assert result["errors"] == {"base": "cannot_connect"} assert result["errors"] == {"base": "cannot_connect"}
async def test_flow_auth_firmware_error(hass): async def test_flow_auth_firmware_error(hass: HomeAssistant) -> None:
"""Test we handle a firmware error in the auth step.""" """Test we handle a firmware error in the auth step."""
device = get_device("Living Room") device = get_device("Living Room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -292,7 +293,7 @@ async def test_flow_auth_firmware_error(hass):
assert result["errors"] == {"base": "unknown"} assert result["errors"] == {"base": "unknown"}
async def test_flow_auth_network_unreachable(hass): async def test_flow_auth_network_unreachable(hass: HomeAssistant) -> None:
"""Test we handle a network unreachable in the auth step.""" """Test we handle a network unreachable in the auth step."""
device = get_device("Living Room") device = get_device("Living Room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -313,7 +314,7 @@ async def test_flow_auth_network_unreachable(hass):
assert result["errors"] == {"base": "cannot_connect"} assert result["errors"] == {"base": "cannot_connect"}
async def test_flow_auth_os_error(hass): async def test_flow_auth_os_error(hass: HomeAssistant) -> None:
"""Test we handle an OS error in the auth step.""" """Test we handle an OS error in the auth step."""
device = get_device("Living Room") device = get_device("Living Room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -334,7 +335,7 @@ async def test_flow_auth_os_error(hass):
assert result["errors"] == {"base": "unknown"} assert result["errors"] == {"base": "unknown"}
async def test_flow_reset_works(hass): async def test_flow_reset_works(hass: HomeAssistant) -> None:
"""Test we finish a config flow after a manual unlock.""" """Test we finish a config flow after a manual unlock."""
device = get_device("Living Room") device = get_device("Living Room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -366,7 +367,7 @@ async def test_flow_reset_works(hass):
assert result["data"] == device.get_entry_data() assert result["data"] == device.get_entry_data()
async def test_flow_unlock_works(hass): async def test_flow_unlock_works(hass: HomeAssistant) -> None:
"""Test we finish a config flow with an unlock request.""" """Test we finish a config flow with an unlock request."""
device = get_device("Living Room") device = get_device("Living Room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -404,7 +405,7 @@ async def test_flow_unlock_works(hass):
assert mock_api.set_lock.call_count == 1 assert mock_api.set_lock.call_count == 1
async def test_flow_unlock_network_timeout(hass): async def test_flow_unlock_network_timeout(hass: HomeAssistant) -> None:
"""Test we handle a network timeout in the unlock step.""" """Test we handle a network timeout in the unlock step."""
device = get_device("Living Room") device = get_device("Living Room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -431,7 +432,7 @@ async def test_flow_unlock_network_timeout(hass):
assert result["errors"] == {"base": "cannot_connect"} assert result["errors"] == {"base": "cannot_connect"}
async def test_flow_unlock_firmware_error(hass): async def test_flow_unlock_firmware_error(hass: HomeAssistant) -> None:
"""Test we handle a firmware error in the unlock step.""" """Test we handle a firmware error in the unlock step."""
device = get_device("Living Room") device = get_device("Living Room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -458,7 +459,7 @@ async def test_flow_unlock_firmware_error(hass):
assert result["errors"] == {"base": "unknown"} assert result["errors"] == {"base": "unknown"}
async def test_flow_unlock_network_unreachable(hass): async def test_flow_unlock_network_unreachable(hass: HomeAssistant) -> None:
"""Test we handle a network unreachable in the unlock step.""" """Test we handle a network unreachable in the unlock step."""
device = get_device("Living Room") device = get_device("Living Room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -485,7 +486,7 @@ async def test_flow_unlock_network_unreachable(hass):
assert result["errors"] == {"base": "cannot_connect"} assert result["errors"] == {"base": "cannot_connect"}
async def test_flow_unlock_os_error(hass): async def test_flow_unlock_os_error(hass: HomeAssistant) -> None:
"""Test we handle an OS error in the unlock step.""" """Test we handle an OS error in the unlock step."""
device = get_device("Living Room") device = get_device("Living Room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -512,7 +513,7 @@ async def test_flow_unlock_os_error(hass):
assert result["errors"] == {"base": "unknown"} assert result["errors"] == {"base": "unknown"}
async def test_flow_do_not_unlock(hass): async def test_flow_do_not_unlock(hass: HomeAssistant) -> None:
"""Test we do not unlock the device if the user does not want to.""" """Test we do not unlock the device if the user does not want to."""
device = get_device("Living Room") device = get_device("Living Room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -545,7 +546,7 @@ async def test_flow_do_not_unlock(hass):
assert mock_api.set_lock.call_count == 0 assert mock_api.set_lock.call_count == 0
async def test_flow_import_works(hass): async def test_flow_import_works(hass: HomeAssistant) -> None:
"""Test an import flow.""" """Test an import flow."""
device = get_device("Living Room") device = get_device("Living Room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -576,7 +577,7 @@ async def test_flow_import_works(hass):
assert mock_hello.call_count == 1 assert mock_hello.call_count == 1
async def test_flow_import_already_in_progress(hass): async def test_flow_import_already_in_progress(hass: HomeAssistant) -> None:
"""Test we do not import more than one flow per device.""" """Test we do not import more than one flow per device."""
device = get_device("Living Room") device = get_device("Living Room")
data = {"host": device.host} data = {"host": device.host}
@ -595,7 +596,7 @@ async def test_flow_import_already_in_progress(hass):
assert result["reason"] == "already_in_progress" assert result["reason"] == "already_in_progress"
async def test_flow_import_host_already_configured(hass): async def test_flow_import_host_already_configured(hass: HomeAssistant) -> None:
"""Test we do not import a host that is already configured.""" """Test we do not import a host that is already configured."""
device = get_device("Living Room") device = get_device("Living Room")
mock_entry = device.get_mock_entry() mock_entry = device.get_mock_entry()
@ -613,7 +614,7 @@ async def test_flow_import_host_already_configured(hass):
assert result["reason"] == "already_configured" assert result["reason"] == "already_configured"
async def test_flow_import_mac_already_configured(hass): async def test_flow_import_mac_already_configured(hass: HomeAssistant) -> None:
"""Test we do not import more than one config entry per device. """Test we do not import more than one config entry per device.
We need to abort the flow and update the existing entry. We need to abort the flow and update the existing entry.
@ -641,7 +642,7 @@ async def test_flow_import_mac_already_configured(hass):
assert mock_api.auth.call_count == 0 assert mock_api.auth.call_count == 0
async def test_flow_import_device_not_found(hass): async def test_flow_import_device_not_found(hass: HomeAssistant) -> None:
"""Test we handle a device not found in the import step.""" """Test we handle a device not found in the import step."""
with patch(DEVICE_HELLO, side_effect=blke.NetworkTimeoutError()): with patch(DEVICE_HELLO, side_effect=blke.NetworkTimeoutError()):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -654,7 +655,7 @@ async def test_flow_import_device_not_found(hass):
assert result["reason"] == "cannot_connect" assert result["reason"] == "cannot_connect"
async def test_flow_import_device_not_supported(hass): async def test_flow_import_device_not_supported(hass: HomeAssistant) -> None:
"""Test we handle a device not supported in the import step.""" """Test we handle a device not supported in the import step."""
device = get_device("Kitchen") device = get_device("Kitchen")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -670,7 +671,7 @@ async def test_flow_import_device_not_supported(hass):
assert result["reason"] == "not_supported" assert result["reason"] == "not_supported"
async def test_flow_import_invalid_ip_address(hass): async def test_flow_import_invalid_ip_address(hass: HomeAssistant) -> None:
"""Test we handle an invalid IP address in the import step.""" """Test we handle an invalid IP address in the import step."""
with patch(DEVICE_HELLO, side_effect=OSError(errno.EINVAL, None)): with patch(DEVICE_HELLO, side_effect=OSError(errno.EINVAL, None)):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -683,7 +684,7 @@ async def test_flow_import_invalid_ip_address(hass):
assert result["reason"] == "invalid_host" assert result["reason"] == "invalid_host"
async def test_flow_import_invalid_hostname(hass): async def test_flow_import_invalid_hostname(hass: HomeAssistant) -> None:
"""Test we handle an invalid hostname in the import step.""" """Test we handle an invalid hostname in the import step."""
with patch(DEVICE_HELLO, side_effect=OSError(socket.EAI_NONAME, None)): with patch(DEVICE_HELLO, side_effect=OSError(socket.EAI_NONAME, None)):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -696,7 +697,7 @@ async def test_flow_import_invalid_hostname(hass):
assert result["reason"] == "invalid_host" assert result["reason"] == "invalid_host"
async def test_flow_import_network_unreachable(hass): async def test_flow_import_network_unreachable(hass: HomeAssistant) -> None:
"""Test we handle a network unreachable in the import step.""" """Test we handle a network unreachable in the import step."""
with patch(DEVICE_HELLO, side_effect=OSError(errno.ENETUNREACH, None)): with patch(DEVICE_HELLO, side_effect=OSError(errno.ENETUNREACH, None)):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -709,7 +710,7 @@ async def test_flow_import_network_unreachable(hass):
assert result["reason"] == "cannot_connect" assert result["reason"] == "cannot_connect"
async def test_flow_import_os_error(hass): async def test_flow_import_os_error(hass: HomeAssistant) -> None:
"""Test we handle an OS error in the import step.""" """Test we handle an OS error in the import step."""
with patch(DEVICE_HELLO, side_effect=OSError()): with patch(DEVICE_HELLO, side_effect=OSError()):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -722,7 +723,7 @@ async def test_flow_import_os_error(hass):
assert result["reason"] == "unknown" assert result["reason"] == "unknown"
async def test_flow_reauth_works(hass): async def test_flow_reauth_works(hass: HomeAssistant) -> None:
"""Test a reauthentication flow.""" """Test a reauthentication flow."""
device = get_device("Living Room") device = get_device("Living Room")
mock_entry = device.get_mock_entry() mock_entry = device.get_mock_entry()
@ -755,7 +756,7 @@ async def test_flow_reauth_works(hass):
assert mock_hello.call_count == 1 assert mock_hello.call_count == 1
async def test_flow_reauth_invalid_host(hass): async def test_flow_reauth_invalid_host(hass: HomeAssistant) -> None:
"""Test we do not accept an invalid host for reauthentication. """Test we do not accept an invalid host for reauthentication.
The MAC address cannot change. The MAC address cannot change.
@ -789,7 +790,7 @@ async def test_flow_reauth_invalid_host(hass):
assert mock_api.auth.call_count == 0 assert mock_api.auth.call_count == 0
async def test_flow_reauth_valid_host(hass): async def test_flow_reauth_valid_host(hass: HomeAssistant) -> None:
"""Test we accept a valid host for reauthentication. """Test we accept a valid host for reauthentication.
The hostname/IP address may change. We need to update the entry. The hostname/IP address may change. We need to update the entry.
@ -823,7 +824,7 @@ async def test_flow_reauth_valid_host(hass):
assert mock_api.auth.call_count == 1 assert mock_api.auth.call_count == 1
async def test_dhcp_can_finish(hass): async def test_dhcp_can_finish(hass: HomeAssistant) -> None:
"""Test DHCP discovery flow can finish right away.""" """Test DHCP discovery flow can finish right away."""
device = get_device("Living Room") device = get_device("Living Room")
@ -861,7 +862,7 @@ async def test_dhcp_can_finish(hass):
} }
async def test_dhcp_fails_to_connect(hass): async def test_dhcp_fails_to_connect(hass: HomeAssistant) -> None:
"""Test DHCP discovery flow that fails to connect.""" """Test DHCP discovery flow that fails to connect."""
with patch(DEVICE_HELLO, side_effect=blke.NetworkTimeoutError()): with patch(DEVICE_HELLO, side_effect=blke.NetworkTimeoutError()):
@ -880,7 +881,7 @@ async def test_dhcp_fails_to_connect(hass):
assert result["reason"] == "cannot_connect" assert result["reason"] == "cannot_connect"
async def test_dhcp_unreachable(hass): async def test_dhcp_unreachable(hass: HomeAssistant) -> None:
"""Test DHCP discovery flow that fails to connect.""" """Test DHCP discovery flow that fails to connect."""
with patch(DEVICE_HELLO, side_effect=OSError(errno.ENETUNREACH, None)): with patch(DEVICE_HELLO, side_effect=OSError(errno.ENETUNREACH, None)):
@ -899,7 +900,7 @@ async def test_dhcp_unreachable(hass):
assert result["reason"] == "cannot_connect" assert result["reason"] == "cannot_connect"
async def test_dhcp_connect_unknown_error(hass): async def test_dhcp_connect_unknown_error(hass: HomeAssistant) -> None:
"""Test DHCP discovery flow that fails to connect with an OSError.""" """Test DHCP discovery flow that fails to connect with an OSError."""
with patch(DEVICE_HELLO, side_effect=OSError()): with patch(DEVICE_HELLO, side_effect=OSError()):
@ -918,7 +919,7 @@ async def test_dhcp_connect_unknown_error(hass):
assert result["reason"] == "unknown" assert result["reason"] == "unknown"
async def test_dhcp_device_not_supported(hass): async def test_dhcp_device_not_supported(hass: HomeAssistant) -> None:
"""Test DHCP discovery flow that fails because the device is not supported.""" """Test DHCP discovery flow that fails because the device is not supported."""
device = get_device("Kitchen") device = get_device("Kitchen")
@ -939,7 +940,7 @@ async def test_dhcp_device_not_supported(hass):
assert result["reason"] == "not_supported" assert result["reason"] == "not_supported"
async def test_dhcp_already_exists(hass): async def test_dhcp_already_exists(hass: HomeAssistant) -> None:
"""Test DHCP discovery flow that fails to connect.""" """Test DHCP discovery flow that fails to connect."""
device = get_device("Living Room") device = get_device("Living Room")
@ -964,7 +965,7 @@ async def test_dhcp_already_exists(hass):
assert result["reason"] == "already_configured" assert result["reason"] == "already_configured"
async def test_dhcp_updates_host(hass): async def test_dhcp_updates_host(hass: HomeAssistant) -> None:
"""Test DHCP updates host.""" """Test DHCP updates host."""
device = get_device("Living Room") device = get_device("Living Room")

View file

@ -7,6 +7,7 @@ from homeassistant.components.broadlink.const import DOMAIN
from homeassistant.components.broadlink.device import get_domains from homeassistant.components.broadlink.device import get_domains
from homeassistant.config_entries import ConfigEntryState from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import ATTR_FRIENDLY_NAME from homeassistant.const import ATTR_FRIENDLY_NAME
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_registry import async_entries_for_device from homeassistant.helpers.entity_registry import async_entries_for_device
from . import get_device from . import get_device
@ -16,7 +17,7 @@ from tests.common import mock_device_registry, mock_registry
DEVICE_FACTORY = "homeassistant.components.broadlink.device.blk.gendevice" DEVICE_FACTORY = "homeassistant.components.broadlink.device.blk.gendevice"
async def test_device_setup(hass): async def test_device_setup(hass: HomeAssistant) -> None:
"""Test a successful setup.""" """Test a successful setup."""
device = get_device("Office") device = get_device("Office")
@ -39,7 +40,7 @@ async def test_device_setup(hass):
assert mock_init.call_count == 0 assert mock_init.call_count == 0
async def test_device_setup_authentication_error(hass): async def test_device_setup_authentication_error(hass: HomeAssistant) -> None:
"""Test we handle an authentication error.""" """Test we handle an authentication error."""
device = get_device("Living Room") device = get_device("Living Room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -63,7 +64,7 @@ async def test_device_setup_authentication_error(hass):
} }
async def test_device_setup_network_timeout(hass): async def test_device_setup_network_timeout(hass: HomeAssistant) -> None:
"""Test we handle a network timeout.""" """Test we handle a network timeout."""
device = get_device("Office") device = get_device("Office")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -82,7 +83,7 @@ async def test_device_setup_network_timeout(hass):
assert mock_init.call_count == 0 assert mock_init.call_count == 0
async def test_device_setup_os_error(hass): async def test_device_setup_os_error(hass: HomeAssistant) -> None:
"""Test we handle an OS error.""" """Test we handle an OS error."""
device = get_device("Office") device = get_device("Office")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -101,7 +102,7 @@ async def test_device_setup_os_error(hass):
assert mock_init.call_count == 0 assert mock_init.call_count == 0
async def test_device_setup_broadlink_exception(hass): async def test_device_setup_broadlink_exception(hass: HomeAssistant) -> None:
"""Test we handle a Broadlink exception.""" """Test we handle a Broadlink exception."""
device = get_device("Office") device = get_device("Office")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -120,7 +121,7 @@ async def test_device_setup_broadlink_exception(hass):
assert mock_init.call_count == 0 assert mock_init.call_count == 0
async def test_device_setup_update_network_timeout(hass): async def test_device_setup_update_network_timeout(hass: HomeAssistant) -> None:
"""Test we handle a network timeout in the update step.""" """Test we handle a network timeout in the update step."""
device = get_device("Office") device = get_device("Office")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -140,7 +141,7 @@ async def test_device_setup_update_network_timeout(hass):
assert mock_init.call_count == 0 assert mock_init.call_count == 0
async def test_device_setup_update_authorization_error(hass): async def test_device_setup_update_authorization_error(hass: HomeAssistant) -> None:
"""Test we handle an authorization error in the update step.""" """Test we handle an authorization error in the update step."""
device = get_device("Office") device = get_device("Office")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -167,7 +168,7 @@ async def test_device_setup_update_authorization_error(hass):
assert mock_init.call_count == 0 assert mock_init.call_count == 0
async def test_device_setup_update_authentication_error(hass): async def test_device_setup_update_authentication_error(hass: HomeAssistant) -> None:
"""Test we handle an authentication error in the update step.""" """Test we handle an authentication error in the update step."""
device = get_device("Garage") device = get_device("Garage")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -193,7 +194,7 @@ async def test_device_setup_update_authentication_error(hass):
} }
async def test_device_setup_update_broadlink_exception(hass): async def test_device_setup_update_broadlink_exception(hass: HomeAssistant) -> None:
"""Test we handle a Broadlink exception in the update step.""" """Test we handle a Broadlink exception in the update step."""
device = get_device("Garage") device = get_device("Garage")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -213,7 +214,9 @@ async def test_device_setup_update_broadlink_exception(hass):
assert mock_init.call_count == 0 assert mock_init.call_count == 0
async def test_device_setup_get_fwversion_broadlink_exception(hass): async def test_device_setup_get_fwversion_broadlink_exception(
hass: HomeAssistant,
) -> None:
"""Test we load the device even if we cannot read the firmware version.""" """Test we load the device even if we cannot read the firmware version."""
device = get_device("Office") device = get_device("Office")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -229,7 +232,7 @@ async def test_device_setup_get_fwversion_broadlink_exception(hass):
assert forward_entries == domains assert forward_entries == domains
async def test_device_setup_get_fwversion_os_error(hass): async def test_device_setup_get_fwversion_os_error(hass: HomeAssistant) -> None:
"""Test we load the device even if we cannot read the firmware version.""" """Test we load the device even if we cannot read the firmware version."""
device = get_device("Office") device = get_device("Office")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -245,7 +248,7 @@ async def test_device_setup_get_fwversion_os_error(hass):
assert forward_entries == domains assert forward_entries == domains
async def test_device_setup_registry(hass): async def test_device_setup_registry(hass: HomeAssistant) -> None:
"""Test we register the device and the entries correctly.""" """Test we register the device and the entries correctly."""
device = get_device("Office") device = get_device("Office")
@ -274,7 +277,7 @@ async def test_device_setup_registry(hass):
) )
async def test_device_unload_works(hass): async def test_device_unload_works(hass: HomeAssistant) -> None:
"""Test we unload the device.""" """Test we unload the device."""
device = get_device("Office") device = get_device("Office")
@ -293,7 +296,7 @@ async def test_device_unload_works(hass):
assert forward_entries == domains assert forward_entries == domains
async def test_device_unload_authentication_error(hass): async def test_device_unload_authentication_error(hass: HomeAssistant) -> None:
"""Test we unload a device that failed the authentication step.""" """Test we unload a device that failed the authentication step."""
device = get_device("Living Room") device = get_device("Living Room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -313,7 +316,7 @@ async def test_device_unload_authentication_error(hass):
assert mock_forward.call_count == 0 assert mock_forward.call_count == 0
async def test_device_unload_update_failed(hass): async def test_device_unload_update_failed(hass: HomeAssistant) -> None:
"""Test we unload a device that failed the update step.""" """Test we unload a device that failed the update step."""
device = get_device("Office") device = get_device("Office")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -331,7 +334,7 @@ async def test_device_unload_update_failed(hass):
assert mock_forward.call_count == 0 assert mock_forward.call_count == 0
async def test_device_update_listener(hass): async def test_device_update_listener(hass: HomeAssistant) -> None:
"""Test we update device and entity registry when the entry is renamed.""" """Test we update device and entity registry when the entry is renamed."""
device = get_device("Office") device = get_device("Office")

View file

@ -1,7 +1,10 @@
"""Tests for Broadlink heartbeats.""" """Tests for Broadlink heartbeats."""
from unittest.mock import call, patch from unittest.mock import call, patch
import pytest
from homeassistant.components.broadlink.heartbeat import BroadlinkHeartbeat from homeassistant.components.broadlink.heartbeat import BroadlinkHeartbeat
from homeassistant.core import HomeAssistant
from homeassistant.util import dt from homeassistant.util import dt
from . import get_device from . import get_device
@ -11,7 +14,7 @@ from tests.common import async_fire_time_changed
DEVICE_PING = "homeassistant.components.broadlink.heartbeat.blk.ping" DEVICE_PING = "homeassistant.components.broadlink.heartbeat.blk.ping"
async def test_heartbeat_trigger_startup(hass): async def test_heartbeat_trigger_startup(hass: HomeAssistant) -> None:
"""Test that the heartbeat is initialized with the first config entry.""" """Test that the heartbeat is initialized with the first config entry."""
device = get_device("Office") device = get_device("Office")
@ -23,7 +26,9 @@ async def test_heartbeat_trigger_startup(hass):
assert mock_ping.call_args == call(device.host) assert mock_ping.call_args == call(device.host)
async def test_heartbeat_ignore_oserror(hass, caplog): async def test_heartbeat_ignore_oserror(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test that an OSError is ignored.""" """Test that an OSError is ignored."""
device = get_device("Office") device = get_device("Office")
@ -34,7 +39,7 @@ async def test_heartbeat_ignore_oserror(hass, caplog):
assert "Failed to send heartbeat to" in caplog.text assert "Failed to send heartbeat to" in caplog.text
async def test_heartbeat_trigger_right_time(hass): async def test_heartbeat_trigger_right_time(hass: HomeAssistant) -> None:
"""Test that the heartbeat is triggered at the right time.""" """Test that the heartbeat is triggered at the right time."""
device = get_device("Office") device = get_device("Office")
@ -51,7 +56,7 @@ async def test_heartbeat_trigger_right_time(hass):
assert mock_ping.call_args == call(device.host) assert mock_ping.call_args == call(device.host)
async def test_heartbeat_do_not_trigger_before_time(hass): async def test_heartbeat_do_not_trigger_before_time(hass: HomeAssistant) -> None:
"""Test that the heartbeat is not triggered before the time.""" """Test that the heartbeat is not triggered before the time."""
device = get_device("Office") device = get_device("Office")
@ -68,7 +73,7 @@ async def test_heartbeat_do_not_trigger_before_time(hass):
assert mock_ping.call_count == 0 assert mock_ping.call_count == 0
async def test_heartbeat_unload(hass): async def test_heartbeat_unload(hass: HomeAssistant) -> None:
"""Test that the heartbeat is deactivated when the last config entry is removed.""" """Test that the heartbeat is deactivated when the last config entry is removed."""
device = get_device("Office") device = get_device("Office")
@ -86,7 +91,7 @@ async def test_heartbeat_unload(hass):
assert mock_ping.call_count == 0 assert mock_ping.call_count == 0
async def test_heartbeat_do_not_unload(hass): async def test_heartbeat_do_not_unload(hass: HomeAssistant) -> None:
"""Test that the heartbeat is not deactivated until the last config entry is removed.""" """Test that the heartbeat is not deactivated until the last config entry is removed."""
device_a = get_device("Office") device_a = get_device("Office")
device_b = get_device("Bedroom") device_b = get_device("Bedroom")

View file

@ -3,16 +3,17 @@ import pytest
import voluptuous as vol import voluptuous as vol
from homeassistant.components.broadlink.helpers import data_packet, mac_address from homeassistant.components.broadlink.helpers import data_packet, mac_address
from homeassistant.core import HomeAssistant
async def test_padding(hass): async def test_padding(hass: HomeAssistant) -> None:
"""Verify that non padding strings are allowed.""" """Verify that non padding strings are allowed."""
assert data_packet("Jg") == b"&" assert data_packet("Jg") == b"&"
assert data_packet("Jg=") == b"&" assert data_packet("Jg=") == b"&"
assert data_packet("Jg==") == b"&" assert data_packet("Jg==") == b"&"
async def test_valid_mac_address(hass): async def test_valid_mac_address(hass: HomeAssistant) -> None:
"""Test we convert a valid MAC address to bytes.""" """Test we convert a valid MAC address to bytes."""
valid = [ valid = [
"A1B2C3D4E5F6", "A1B2C3D4E5F6",
@ -30,7 +31,7 @@ async def test_valid_mac_address(hass):
assert mac_address(mac) == b"\xa1\xb2\xc3\xd4\xe5\xf6" assert mac_address(mac) == b"\xa1\xb2\xc3\xd4\xe5\xf6"
async def test_invalid_mac_address(hass): async def test_invalid_mac_address(hass: HomeAssistant) -> None:
"""Test we do not accept an invalid MAC address.""" """Test we do not accept an invalid MAC address."""
invalid = [ invalid = [
None, None,

View file

@ -10,6 +10,7 @@ from homeassistant.components.remote import (
SERVICE_TURN_ON, SERVICE_TURN_ON,
) )
from homeassistant.const import ATTR_FRIENDLY_NAME, STATE_OFF, STATE_ON, Platform from homeassistant.const import ATTR_FRIENDLY_NAME, STATE_OFF, STATE_ON, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_registry import async_entries_for_device from homeassistant.helpers.entity_registry import async_entries_for_device
from . import get_device from . import get_device
@ -24,7 +25,7 @@ IR_PACKET = (
) )
async def test_remote_setup_works(hass): async def test_remote_setup_works(hass: HomeAssistant) -> None:
"""Test a successful setup with all remotes.""" """Test a successful setup with all remotes."""
for device in map(get_device, REMOTE_DEVICES): for device in map(get_device, REMOTE_DEVICES):
device_registry = mock_device_registry(hass) device_registry = mock_device_registry(hass)
@ -47,7 +48,7 @@ async def test_remote_setup_works(hass):
assert mock_setup.api.auth.call_count == 1 assert mock_setup.api.auth.call_count == 1
async def test_remote_send_command(hass): async def test_remote_send_command(hass: HomeAssistant) -> None:
"""Test sending a command with all remotes.""" """Test sending a command with all remotes."""
for device in map(get_device, REMOTE_DEVICES): for device in map(get_device, REMOTE_DEVICES):
device_registry = mock_device_registry(hass) device_registry = mock_device_registry(hass)
@ -74,7 +75,7 @@ async def test_remote_send_command(hass):
assert mock_setup.api.auth.call_count == 1 assert mock_setup.api.auth.call_count == 1
async def test_remote_turn_off_turn_on(hass): async def test_remote_turn_off_turn_on(hass: HomeAssistant) -> None:
"""Test we do not send commands if the remotes are off.""" """Test we do not send commands if the remotes are off."""
for device in map(get_device, REMOTE_DEVICES): for device in map(get_device, REMOTE_DEVICES):
device_registry = mock_device_registry(hass) device_registry = mock_device_registry(hass)

View file

@ -4,6 +4,7 @@ from datetime import timedelta
from homeassistant.components.broadlink.const import DOMAIN from homeassistant.components.broadlink.const import DOMAIN
from homeassistant.components.broadlink.updater import BroadlinkSP4UpdateManager from homeassistant.components.broadlink.updater import BroadlinkSP4UpdateManager
from homeassistant.const import ATTR_FRIENDLY_NAME, Platform from homeassistant.const import ATTR_FRIENDLY_NAME, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_component import async_update_entity from homeassistant.helpers.entity_component import async_update_entity
from homeassistant.helpers.entity_registry import async_entries_for_device from homeassistant.helpers.entity_registry import async_entries_for_device
from homeassistant.util import dt from homeassistant.util import dt
@ -13,7 +14,7 @@ from . import get_device
from tests.common import async_fire_time_changed, mock_device_registry, mock_registry from tests.common import async_fire_time_changed, mock_device_registry, mock_registry
async def test_a1_sensor_setup(hass): async def test_a1_sensor_setup(hass: HomeAssistant) -> None:
"""Test a successful e-Sensor setup.""" """Test a successful e-Sensor setup."""
device = get_device("Bedroom") device = get_device("Bedroom")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -54,7 +55,7 @@ async def test_a1_sensor_setup(hass):
} }
async def test_a1_sensor_update(hass): async def test_a1_sensor_update(hass: HomeAssistant) -> None:
"""Test a successful e-Sensor update.""" """Test a successful e-Sensor update."""
device = get_device("Bedroom") device = get_device("Bedroom")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -104,7 +105,7 @@ async def test_a1_sensor_update(hass):
} }
async def test_rm_pro_sensor_setup(hass): async def test_rm_pro_sensor_setup(hass: HomeAssistant) -> None:
"""Test a successful RM pro sensor setup.""" """Test a successful RM pro sensor setup."""
device = get_device("Office") device = get_device("Office")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -133,7 +134,7 @@ async def test_rm_pro_sensor_setup(hass):
assert sensors_and_states == {(f"{device.name} Temperature", "18.2")} assert sensors_and_states == {(f"{device.name} Temperature", "18.2")}
async def test_rm_pro_sensor_update(hass): async def test_rm_pro_sensor_update(hass: HomeAssistant) -> None:
"""Test a successful RM pro sensor update.""" """Test a successful RM pro sensor update."""
device = get_device("Office") device = get_device("Office")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -165,7 +166,7 @@ async def test_rm_pro_sensor_update(hass):
assert sensors_and_states == {(f"{device.name} Temperature", "25.8")} assert sensors_and_states == {(f"{device.name} Temperature", "25.8")}
async def test_rm_pro_filter_crazy_temperature(hass): async def test_rm_pro_filter_crazy_temperature(hass: HomeAssistant) -> None:
"""Test we filter a crazy temperature variation. """Test we filter a crazy temperature variation.
Firmware issue. See https://github.com/home-assistant/core/issues/42100. Firmware issue. See https://github.com/home-assistant/core/issues/42100.
@ -200,7 +201,7 @@ async def test_rm_pro_filter_crazy_temperature(hass):
assert sensors_and_states == {(f"{device.name} Temperature", "22.9")} assert sensors_and_states == {(f"{device.name} Temperature", "22.9")}
async def test_rm_mini3_no_sensor(hass): async def test_rm_mini3_no_sensor(hass: HomeAssistant) -> None:
"""Test we do not set up sensors for RM mini 3.""" """Test we do not set up sensors for RM mini 3."""
device = get_device("Entrance") device = get_device("Entrance")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -220,7 +221,7 @@ async def test_rm_mini3_no_sensor(hass):
assert len(sensors) == 0 assert len(sensors) == 0
async def test_rm4_pro_hts2_sensor_setup(hass): async def test_rm4_pro_hts2_sensor_setup(hass: HomeAssistant) -> None:
"""Test a successful RM4 pro sensor setup with HTS2 cable.""" """Test a successful RM4 pro sensor setup with HTS2 cable."""
device = get_device("Garage") device = get_device("Garage")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -252,7 +253,7 @@ async def test_rm4_pro_hts2_sensor_setup(hass):
} }
async def test_rm4_pro_hts2_sensor_update(hass): async def test_rm4_pro_hts2_sensor_update(hass: HomeAssistant) -> None:
"""Test a successful RM4 pro sensor update with HTS2 cable.""" """Test a successful RM4 pro sensor update with HTS2 cable."""
device = get_device("Garage") device = get_device("Garage")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -287,7 +288,7 @@ async def test_rm4_pro_hts2_sensor_update(hass):
} }
async def test_rm4_pro_no_sensor(hass): async def test_rm4_pro_no_sensor(hass: HomeAssistant) -> None:
"""Test we do not set up sensors for RM4 pro without HTS2 cable.""" """Test we do not set up sensors for RM4 pro without HTS2 cable."""
device = get_device("Garage") device = get_device("Garage")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -307,7 +308,7 @@ async def test_rm4_pro_no_sensor(hass):
assert len(sensors) == 0 assert len(sensors) == 0
async def test_scb1e_sensor_setup(hass): async def test_scb1e_sensor_setup(hass: HomeAssistant) -> None:
"""Test a successful SCB1E sensor setup.""" """Test a successful SCB1E sensor setup."""
device = get_device("Dining room") device = get_device("Dining room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()
@ -352,7 +353,7 @@ async def test_scb1e_sensor_setup(hass):
} }
async def test_scb1e_sensor_update(hass): async def test_scb1e_sensor_update(hass: HomeAssistant) -> None:
"""Test a successful SCB1E sensor update.""" """Test a successful SCB1E sensor update."""
device = get_device("Dining room") device = get_device("Dining room")
mock_api = device.get_mock_api() mock_api = device.get_mock_api()

View file

@ -6,6 +6,7 @@ from homeassistant.components.switch import (
SERVICE_TURN_ON, SERVICE_TURN_ON,
) )
from homeassistant.const import ATTR_FRIENDLY_NAME, STATE_OFF, STATE_ON, Platform from homeassistant.const import ATTR_FRIENDLY_NAME, STATE_OFF, STATE_ON, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_registry import async_entries_for_device from homeassistant.helpers.entity_registry import async_entries_for_device
from . import get_device from . import get_device
@ -13,7 +14,7 @@ from . import get_device
from tests.common import mock_device_registry, mock_registry from tests.common import mock_device_registry, mock_registry
async def test_switch_setup_works(hass): async def test_switch_setup_works(hass: HomeAssistant) -> None:
"""Test a successful setup with a switch.""" """Test a successful setup with a switch."""
device = get_device("Dining room") device = get_device("Dining room")
device_registry = mock_device_registry(hass) device_registry = mock_device_registry(hass)
@ -35,7 +36,7 @@ async def test_switch_setup_works(hass):
assert mock_setup.api.auth.call_count == 1 assert mock_setup.api.auth.call_count == 1
async def test_switch_turn_off_turn_on(hass): async def test_switch_turn_off_turn_on(hass: HomeAssistant) -> None:
"""Test send turn on and off for a switch.""" """Test send turn on and off for a switch."""
device = get_device("Dining room") device = get_device("Dining room")
device_registry = mock_device_registry(hass) device_registry = mock_device_registry(hass)
@ -69,7 +70,7 @@ async def test_switch_turn_off_turn_on(hass):
assert mock_setup.api.auth.call_count == 1 assert mock_setup.api.auth.call_count == 1
async def test_slots_switch_setup_works(hass): async def test_slots_switch_setup_works(hass: HomeAssistant) -> None:
"""Test a successful setup with a switch with slots.""" """Test a successful setup with a switch with slots."""
device = get_device("Gaming room") device = get_device("Gaming room")
device_registry = mock_device_registry(hass) device_registry = mock_device_registry(hass)
@ -92,7 +93,7 @@ async def test_slots_switch_setup_works(hass):
assert mock_setup.api.auth.call_count == 1 assert mock_setup.api.auth.call_count == 1
async def test_slots_switch_turn_off_turn_on(hass): async def test_slots_switch_turn_off_turn_on(hass: HomeAssistant) -> None:
"""Test send turn on and off for a switch with slots.""" """Test send turn on and off for a switch with slots."""
device = get_device("Gaming room") device = get_device("Gaming room")
device_registry = mock_device_registry(hass) device_registry = mock_device_registry(hass)

View file

@ -365,7 +365,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert entry.unique_id == "0123456789_uptime" assert entry.unique_id == "0123456789_uptime"
async def test_disabled_by_default_sensors(hass): async def test_disabled_by_default_sensors(hass: HomeAssistant) -> None:
"""Test the disabled by default Brother sensors.""" """Test the disabled by default Brother sensors."""
await init_integration(hass) await init_integration(hass)

View file

@ -8,13 +8,14 @@ import pytest
from homeassistant import config_entries, data_entry_flow from homeassistant import config_entries, data_entry_flow
from homeassistant.components.brunt.const import DOMAIN from homeassistant.components.brunt.const import DOMAIN
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
CONFIG = {CONF_USERNAME: "test-username", CONF_PASSWORD: "test-password"} CONFIG = {CONF_USERNAME: "test-username", CONF_PASSWORD: "test-password"}
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(
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=None DOMAIN, context={"source": config_entries.SOURCE_USER}, data=None
@ -41,7 +42,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_duplicate_login(hass): async def test_form_duplicate_login(hass: HomeAssistant) -> None:
"""Test uniqueness of username.""" """Test uniqueness of username."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,

View file

@ -1,5 +1,4 @@
"""Test the BTHome config flow.""" """Test the BTHome config flow."""
from unittest.mock import patch from unittest.mock import patch
from bthome_ble import BTHomeBluetoothDeviceData as DeviceData from bthome_ble import BTHomeBluetoothDeviceData as DeviceData
@ -7,6 +6,7 @@ from bthome_ble import BTHomeBluetoothDeviceData as DeviceData
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components.bluetooth import BluetoothChange from homeassistant.components.bluetooth import BluetoothChange
from homeassistant.components.bthome.const import DOMAIN from homeassistant.components.bthome.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType from homeassistant.data_entry_flow import FlowResultType
from . import ( from . import (
@ -19,7 +19,7 @@ from . import (
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,
@ -38,7 +38,7 @@ async def test_async_step_bluetooth_valid_device(hass):
assert result2["result"].unique_id == "A4:C1:38:8D:18:B2" assert result2["result"].unique_id == "A4:C1:38:8D:18:B2"
async def test_async_step_bluetooth_during_onboarding(hass): async def test_async_step_bluetooth_during_onboarding(hass: HomeAssistant) -> None:
"""Test discovery via bluetooth during onboarding.""" """Test discovery via bluetooth during onboarding."""
with patch( with patch(
"homeassistant.components.bthome.async_setup_entry", return_value=True "homeassistant.components.bthome.async_setup_entry", return_value=True
@ -60,7 +60,9 @@ async def test_async_step_bluetooth_during_onboarding(hass):
assert len(mock_onboarding.mock_calls) == 1 assert len(mock_onboarding.mock_calls) == 1
async def test_async_step_bluetooth_valid_device_with_encryption(hass): async def test_async_step_bluetooth_valid_device_with_encryption(
hass: HomeAssistant,
) -> None:
"""Test discovery via bluetooth with a valid device, with encryption.""" """Test discovery via bluetooth with a valid device, with encryption."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
@ -81,7 +83,9 @@ async def test_async_step_bluetooth_valid_device_with_encryption(hass):
assert result2["result"].unique_id == "54:48:E6:8F:80:A5" assert result2["result"].unique_id == "54:48:E6:8F:80:A5"
async def test_async_step_bluetooth_valid_device_encryption_wrong_key(hass): async def test_async_step_bluetooth_valid_device_encryption_wrong_key(
hass: HomeAssistant,
) -> None:
"""Test discovery via bluetooth with a valid device, with encryption and invalid key.""" """Test discovery via bluetooth with a valid device, with encryption and invalid key."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
@ -111,7 +115,9 @@ async def test_async_step_bluetooth_valid_device_encryption_wrong_key(hass):
assert result2["result"].unique_id == "54:48:E6:8F:80:A5" assert result2["result"].unique_id == "54:48:E6:8F:80:A5"
async def test_async_step_bluetooth_valid_device_encryption_wrong_key_length(hass): async def test_async_step_bluetooth_valid_device_encryption_wrong_key_length(
hass: HomeAssistant,
) -> None:
"""Test discovery via bluetooth with a valid device, with encryption and wrong key length.""" """Test discovery via bluetooth with a valid device, with encryption and wrong key length."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
@ -142,7 +148,7 @@ async def test_async_step_bluetooth_valid_device_encryption_wrong_key_length(has
assert result2["result"].unique_id == "54:48:E6:8F:80:A5" assert result2["result"].unique_id == "54:48:E6:8F:80:A5"
async def test_async_step_bluetooth_not_supported(hass): async def test_async_step_bluetooth_not_supported(hass: HomeAssistant) -> None:
"""Test discovery via bluetooth not supported.""" """Test discovery via bluetooth not supported."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
@ -153,7 +159,7 @@ async def test_async_step_bluetooth_not_supported(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,
@ -163,7 +169,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_no_devices_found_2(hass): async def test_async_step_user_no_devices_found_2(hass: HomeAssistant) -> None:
"""Test setup from service info cache with no devices found. """Test setup from service info cache with no devices found.
This variant tests with a non-BTHome device known to us. This variant tests with a non-BTHome device known to us.
@ -180,7 +186,7 @@ async def test_async_step_user_no_devices_found_2(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.bthome.config_flow.async_discovered_service_info", "homeassistant.components.bthome.config_flow.async_discovered_service_info",
@ -203,7 +209,9 @@ async def test_async_step_user_with_found_devices(hass):
assert result2["result"].unique_id == "54:48:E6:8F:80:A5" assert result2["result"].unique_id == "54:48:E6:8F:80:A5"
async def test_async_step_user_with_found_devices_encryption(hass): async def test_async_step_user_with_found_devices_encryption(
hass: HomeAssistant,
) -> None:
"""Test setup from service info cache with devices found, with encryption.""" """Test setup from service info cache with devices found, with encryption."""
with patch( with patch(
"homeassistant.components.bthome.config_flow.async_discovered_service_info", "homeassistant.components.bthome.config_flow.async_discovered_service_info",
@ -235,7 +243,9 @@ async def test_async_step_user_with_found_devices_encryption(hass):
assert result2["result"].unique_id == "54:48:E6:8F:80:A5" assert result2["result"].unique_id == "54:48:E6:8F:80:A5"
async def test_async_step_user_with_found_devices_encryption_wrong_key(hass): async def test_async_step_user_with_found_devices_encryption_wrong_key(
hass: HomeAssistant,
) -> None:
"""Test setup from service info cache with devices found, with encryption and wrong key.""" """Test setup from service info cache with devices found, with encryption and wrong key."""
# Get a list of devices # Get a list of devices
with patch( with patch(
@ -279,7 +289,9 @@ async def test_async_step_user_with_found_devices_encryption_wrong_key(hass):
assert result2["result"].unique_id == "54:48:E6:8F:80:A5" assert result2["result"].unique_id == "54:48:E6:8F:80:A5"
async def test_async_step_user_with_found_devices_encryption_wrong_key_length(hass): async def test_async_step_user_with_found_devices_encryption_wrong_key_length(
hass: HomeAssistant,
) -> None:
"""Test setup from service info cache with devices found, with encryption and wrong key length.""" """Test setup from service info cache with devices found, with encryption and wrong key length."""
# Get a list of devices # Get a list of devices
with patch( with patch(
@ -324,7 +336,7 @@ async def test_async_step_user_with_found_devices_encryption_wrong_key_length(ha
assert result2["result"].unique_id == "54:48:E6:8F:80:A5" assert result2["result"].unique_id == "54:48:E6:8F:80:A5"
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.bthome.config_flow.async_discovered_service_info", "homeassistant.components.bthome.config_flow.async_discovered_service_info",
@ -352,7 +364,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,
@ -372,7 +386,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,
@ -389,7 +403,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,
@ -408,7 +422,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,
@ -442,7 +458,7 @@ async def test_async_step_user_takes_precedence_over_discovery(hass):
assert not hass.config_entries.flow.async_progress(DOMAIN) assert not hass.config_entries.flow.async_progress(DOMAIN)
async def test_async_step_reauth(hass): async def test_async_step_reauth(hass: HomeAssistant) -> None:
"""Test reauth with a key.""" """Test reauth with a key."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -482,7 +498,7 @@ async def test_async_step_reauth(hass):
assert result2["reason"] == "reauth_successful" assert result2["reason"] == "reauth_successful"
async def test_async_step_reauth_wrong_key(hass): async def test_async_step_reauth_wrong_key(hass: HomeAssistant) -> None:
"""Test reauth with a bad key, and that we can recover.""" """Test reauth with a bad key, and that we can recover."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -530,7 +546,7 @@ async def test_async_step_reauth_wrong_key(hass):
assert result2["reason"] == "reauth_successful" assert result2["reason"] == "reauth_successful"
async def test_async_step_reauth_abort_early(hass): async def test_async_step_reauth_abort_early(hass: HomeAssistant) -> None:
"""Test we can abort the reauth if there is no encryption. """Test we can abort the reauth if there is no encryption.
(This can't currently happen in practice). (This can't currently happen in practice).

View file

@ -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.buienradar.const import DOMAIN from homeassistant.components.buienradar.const import DOMAIN
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -11,7 +12,7 @@ TEST_LATITUDE = 51.5288504
TEST_LONGITUDE = 5.4002156 TEST_LONGITUDE = 5.4002156
async def test_config_flow_setup_(hass): async def test_config_flow_setup_(hass: HomeAssistant) -> None:
"""Test setup of camera.""" """Test setup of camera."""
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}
@ -37,7 +38,7 @@ async def test_config_flow_setup_(hass):
} }
async def test_config_flow_already_configured_weather(hass): async def test_config_flow_already_configured_weather(hass: HomeAssistant) -> None:
"""Test already configured.""" """Test already configured."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -66,7 +67,7 @@ async def test_config_flow_already_configured_weather(hass):
assert result["reason"] == "already_configured" assert result["reason"] == "already_configured"
async def test_options_flow(hass): async def test_options_flow(hass: HomeAssistant) -> None:
"""Test options flow.""" """Test options flow."""
entry = MockConfigEntry( entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,

View file

@ -1,5 +1,4 @@
"""The tests for the calendar component.""" """The tests for the calendar component."""
from __future__ import annotations from __future__ import annotations
from datetime import timedelta from datetime import timedelta
@ -16,8 +15,12 @@ from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from tests.typing import ClientSessionGenerator
async def test_events_http_api(hass, hass_client):
async def test_events_http_api(
hass: HomeAssistant, hass_client: ClientSessionGenerator
) -> None:
"""Test the calendar demo view.""" """Test the calendar demo view."""
await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}}) await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
await hass.async_block_till_done() await hass.async_block_till_done()
@ -34,7 +37,9 @@ async def test_events_http_api(hass, hass_client):
assert events[0]["summary"] == "Future Event" assert events[0]["summary"] == "Future Event"
async def test_events_http_api_missing_fields(hass, hass_client): async def test_events_http_api_missing_fields(
hass: HomeAssistant, hass_client: ClientSessionGenerator
) -> None:
"""Test the calendar demo view.""" """Test the calendar demo view."""
await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}}) await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
await hass.async_block_till_done() await hass.async_block_till_done()
@ -43,7 +48,9 @@ async def test_events_http_api_missing_fields(hass, hass_client):
assert response.status == HTTPStatus.BAD_REQUEST assert response.status == HTTPStatus.BAD_REQUEST
async def test_events_http_api_error(hass, hass_client): async def test_events_http_api_error(
hass: HomeAssistant, hass_client: ClientSessionGenerator
) -> None:
"""Test the calendar demo view.""" """Test the calendar demo view."""
await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}}) await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
await hass.async_block_till_done() await hass.async_block_till_done()
@ -64,7 +71,9 @@ async def test_events_http_api_error(hass, hass_client):
assert await response.json() == {"message": "Error reading events: Failure"} assert await response.json() == {"message": "Error reading events: Failure"}
async def test_calendars_http_api(hass, hass_client): async def test_calendars_http_api(
hass: HomeAssistant, hass_client: ClientSessionGenerator
) -> None:
"""Test the calendar demo view.""" """Test the calendar demo view."""
await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}}) await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})
await hass.async_block_till_done() await hass.async_block_till_done()
@ -166,7 +175,7 @@ async def test_unsupported_websocket(hass, hass_ws_client, payload, code):
assert resp["error"].get("code") == code assert resp["error"].get("code") == code
async def test_unsupported_create_event_service(hass): async def test_unsupported_create_event_service(hass: HomeAssistant) -> None:
"""Test unsupported service call.""" """Test unsupported service call."""
await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}}) await async_setup_component(hass, "calendar", {"calendar": {"platform": "demo"}})

View file

@ -446,7 +446,9 @@ async def test_overlap_events(hass, calls, fake_schedule):
] ]
async def test_invalid_calendar_id(hass, caplog): async def test_invalid_calendar_id(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test creating a trigger with an invalid calendar id.""" """Test creating a trigger with an invalid calendar id."""
assert await async_setup_component( assert await async_setup_component(
hass, hass,
@ -465,7 +467,9 @@ async def test_invalid_calendar_id(hass, caplog):
assert "Entity ID invalid-calendar-id is an invalid entity ID" in caplog.text assert "Entity ID invalid-calendar-id is an invalid entity ID" in caplog.text
async def test_legacy_entity_type(hass, caplog): async def test_legacy_entity_type(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test creating a trigger with an invalid calendar id.""" """Test creating a trigger with an invalid calendar id."""
assert await async_setup_component( assert await async_setup_component(
hass, hass,

View file

@ -6,11 +6,12 @@ import pytest
from homeassistant import config_entries, data_entry_flow from homeassistant import config_entries, data_entry_flow
from homeassistant.components import cast from homeassistant.components import cast
from homeassistant.components.cast.home_assistant_cast import CAST_USER_NAME from homeassistant.components.cast.home_assistant_cast import CAST_USER_NAME
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
async def test_creating_entry_sets_up_media_player(hass): async def test_creating_entry_sets_up_media_player(hass: HomeAssistant) -> None:
"""Test setting up Cast loads the media player.""" """Test setting up Cast loads the media player."""
with patch( with patch(
"homeassistant.components.cast.media_player.async_setup_entry", "homeassistant.components.cast.media_player.async_setup_entry",
@ -55,7 +56,7 @@ async def test_single_instance(hass, source):
assert result["reason"] == "single_instance_allowed" assert result["reason"] == "single_instance_allowed"
async def test_user_setup(hass): async def test_user_setup(hass: HomeAssistant) -> None:
"""Test we can finish a config flow.""" """Test we can finish a config flow."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
"cast", context={"source": config_entries.SOURCE_USER} "cast", context={"source": config_entries.SOURCE_USER}
@ -75,7 +76,7 @@ async def test_user_setup(hass):
} }
async def test_user_setup_options(hass): async def test_user_setup_options(hass: HomeAssistant) -> None:
"""Test we can finish a config flow.""" """Test we can finish a config flow."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
"cast", context={"source": config_entries.SOURCE_USER} "cast", context={"source": config_entries.SOURCE_USER}
@ -97,7 +98,7 @@ async def test_user_setup_options(hass):
} }
async def test_zeroconf_setup(hass): async def test_zeroconf_setup(hass: HomeAssistant) -> None:
"""Test we can finish a config flow through zeroconf.""" """Test we can finish a config flow through zeroconf."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
"cast", context={"source": config_entries.SOURCE_ZEROCONF} "cast", context={"source": config_entries.SOURCE_ZEROCONF}
@ -117,7 +118,7 @@ async def test_zeroconf_setup(hass):
} }
async def test_zeroconf_setup_onboarding(hass): async def test_zeroconf_setup_onboarding(hass: HomeAssistant) -> None:
"""Test we automatically finish a config flow through zeroconf during onboarding.""" """Test we automatically finish a config flow through zeroconf during onboarding."""
with patch( with patch(
"homeassistant.components.onboarding.async_is_onboarded", return_value=False "homeassistant.components.onboarding.async_is_onboarded", return_value=False

View file

@ -1,11 +1,14 @@
"""Tests for the Cast integration.""" """Tests for the Cast integration."""
from unittest.mock import patch from unittest.mock import patch
import pytest
from homeassistant.components import cast from homeassistant.components import cast
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
async def test_import(hass, caplog): async def test_import(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -> None:
"""Test that specifying config will create an entry.""" """Test that specifying config will create an entry."""
with patch( with patch(
"homeassistant.components.cast.async_setup_entry", return_value=True "homeassistant.components.cast.async_setup_entry", return_value=True
@ -36,7 +39,7 @@ async def test_import(hass, caplog):
assert "Invalid config '{'incorrect': 'config'}'" in caplog.text assert "Invalid config '{'incorrect': 'config'}'" in caplog.text
async def test_not_configuring_cast_not_creates_entry(hass): async def test_not_configuring_cast_not_creates_entry(hass: HomeAssistant) -> None:
"""Test that an empty config does not create an entry.""" """Test that an empty config does not create an entry."""
with patch( with patch(
"homeassistant.components.cast.async_setup_entry", return_value=True "homeassistant.components.cast.async_setup_entry", return_value=True

View file

@ -446,14 +446,14 @@ async def test_stop_discovery_called_on_stop(hass, castbrowser_mock):
assert castbrowser_mock.return_value.stop_discovery.call_count == 1 assert castbrowser_mock.return_value.stop_discovery.call_count == 1
async def test_create_cast_device_without_uuid(hass): async def test_create_cast_device_without_uuid(hass: HomeAssistant) -> None:
"""Test create a cast device with no UUId does not create an entity.""" """Test create a cast device with no UUId does not create an entity."""
info = get_fake_chromecast_info(uuid=None) info = get_fake_chromecast_info(uuid=None)
cast_device = cast._async_create_cast_device(hass, info) cast_device = cast._async_create_cast_device(hass, info)
assert cast_device is None assert cast_device is None
async def test_create_cast_device_with_uuid(hass): async def test_create_cast_device_with_uuid(hass: HomeAssistant) -> None:
"""Test create cast devices with UUID creates entities.""" """Test create cast devices with UUID creates entities."""
added_casts = hass.data[cast.ADDED_CAST_DEVICES_KEY] = set() added_casts = hass.data[cast.ADDED_CAST_DEVICES_KEY] = set()
info = get_fake_chromecast_info() info = get_fake_chromecast_info()
@ -467,7 +467,7 @@ async def test_create_cast_device_with_uuid(hass):
assert cast_device is None assert cast_device is None
async def test_manual_cast_chromecasts_uuid(hass): async def test_manual_cast_chromecasts_uuid(hass: HomeAssistant) -> None:
"""Test only wanted casts are added for manual configuration.""" """Test only wanted casts are added for manual configuration."""
cast_1 = get_fake_chromecast_info(host="host_1", uuid=FakeUUID) cast_1 = get_fake_chromecast_info(host="host_1", uuid=FakeUUID)
cast_2 = get_fake_chromecast_info(host="host_2", uuid=FakeUUID2) cast_2 = get_fake_chromecast_info(host="host_2", uuid=FakeUUID2)
@ -507,7 +507,7 @@ async def test_manual_cast_chromecasts_uuid(hass):
assert add_dev1.call_count == 1 assert add_dev1.call_count == 1
async def test_auto_cast_chromecasts(hass): async def test_auto_cast_chromecasts(hass: HomeAssistant) -> None:
"""Test all discovered casts are added for default configuration.""" """Test all discovered casts are added for default configuration."""
cast_1 = get_fake_chromecast_info(host="some_host") cast_1 = get_fake_chromecast_info(host="some_host")
cast_2 = get_fake_chromecast_info(host="other_host", uuid=FakeUUID2) cast_2 = get_fake_chromecast_info(host="other_host", uuid=FakeUUID2)
@ -665,7 +665,7 @@ async def test_discover_dynamic_group(
assert "Disconnecting from chromecast" in caplog.text assert "Disconnecting from chromecast" in caplog.text
async def test_update_cast_chromecasts(hass): async def test_update_cast_chromecasts(hass: HomeAssistant) -> None:
"""Test discovery of same UUID twice only adds one cast.""" """Test discovery of same UUID twice only adds one cast."""
cast_1 = get_fake_chromecast_info(host="old_host") cast_1 = get_fake_chromecast_info(host="old_host")
cast_2 = get_fake_chromecast_info(host="new_host") cast_2 = get_fake_chromecast_info(host="new_host")
@ -1819,7 +1819,9 @@ async def test_group_media_control(hass, mz_mock, quick_play_mock):
) )
async def test_failed_cast_on_idle(hass, caplog): async def test_failed_cast_on_idle(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test no warning when unless player went idle with reason "ERROR".""" """Test no warning when unless player went idle with reason "ERROR"."""
info = get_fake_chromecast_info() info = get_fake_chromecast_info()
chromecast, _ = await async_setup_media_player_cast(hass, info) chromecast, _ = await async_setup_media_player_cast(hass, info)
@ -1847,7 +1849,9 @@ async def test_failed_cast_on_idle(hass, caplog):
assert "Failed to cast media http://example.com:8123/tts.mp3." in caplog.text assert "Failed to cast media http://example.com:8123/tts.mp3." in caplog.text
async def test_failed_cast_other_url(hass, caplog): async def test_failed_cast_other_url(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test warning when casting from internal_url fails.""" """Test warning when casting from internal_url fails."""
with assert_setup_component(1, tts.DOMAIN): with assert_setup_component(1, tts.DOMAIN):
assert await async_setup_component( assert await async_setup_component(
@ -1868,7 +1872,9 @@ async def test_failed_cast_other_url(hass, caplog):
assert "Failed to cast media http://example.com:8123/tts.mp3." in caplog.text assert "Failed to cast media http://example.com:8123/tts.mp3." in caplog.text
async def test_failed_cast_internal_url(hass, caplog): async def test_failed_cast_internal_url(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test warning when casting from internal_url fails.""" """Test warning when casting from internal_url fails."""
await async_process_ha_core_config( await async_process_ha_core_config(
hass, hass,
@ -1894,7 +1900,9 @@ async def test_failed_cast_internal_url(hass, caplog):
) )
async def test_failed_cast_external_url(hass, caplog): async def test_failed_cast_external_url(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test warning when casting from external_url fails.""" """Test warning when casting from external_url fails."""
await async_process_ha_core_config( await async_process_ha_core_config(
hass, hass,
@ -1922,7 +1930,9 @@ async def test_failed_cast_external_url(hass, caplog):
) )
async def test_failed_cast_tts_base_url(hass, caplog): async def test_failed_cast_tts_base_url(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test warning when casting from tts.base_url fails.""" """Test warning when casting from tts.base_url fails."""
with assert_setup_component(1, tts.DOMAIN): with assert_setup_component(1, tts.DOMAIN):
assert await async_setup_component( assert await async_setup_component(

View file

@ -6,6 +6,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.cert_expiry.const import DEFAULT_PORT, DOMAIN from homeassistant.components.cert_expiry.const import DEFAULT_PORT, DOMAIN
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT
from homeassistant.core import HomeAssistant
from .const import HOST, PORT from .const import HOST, PORT
from .helpers import future_timestamp from .helpers import future_timestamp
@ -13,7 +14,7 @@ from .helpers import future_timestamp
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
async def test_user(hass): async def test_user(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(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -37,7 +38,7 @@ async def test_user(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
async def test_user_with_bad_cert(hass): async def test_user_with_bad_cert(hass: HomeAssistant) -> None:
"""Test user config with bad certificate.""" """Test user config with bad certificate."""
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}
@ -63,7 +64,7 @@ async def test_user_with_bad_cert(hass):
await hass.async_block_till_done() await hass.async_block_till_done()
async def test_import_host_only(hass): async def test_import_host_only(hass: HomeAssistant) -> None:
"""Test import with host only.""" """Test import with host only."""
with patch( with patch(
"homeassistant.components.cert_expiry.config_flow.get_cert_expiry_timestamp" "homeassistant.components.cert_expiry.config_flow.get_cert_expiry_timestamp"
@ -85,7 +86,7 @@ async def test_import_host_only(hass):
assert result["result"].unique_id == f"{HOST}:{DEFAULT_PORT}" assert result["result"].unique_id == f"{HOST}:{DEFAULT_PORT}"
async def test_import_host_and_port(hass): async def test_import_host_and_port(hass: HomeAssistant) -> None:
"""Test import with host and port.""" """Test import with host and port."""
with patch( with patch(
"homeassistant.components.cert_expiry.config_flow.get_cert_expiry_timestamp" "homeassistant.components.cert_expiry.config_flow.get_cert_expiry_timestamp"
@ -107,7 +108,7 @@ async def test_import_host_and_port(hass):
assert result["result"].unique_id == f"{HOST}:{PORT}" assert result["result"].unique_id == f"{HOST}:{PORT}"
async def test_import_non_default_port(hass): async def test_import_non_default_port(hass: HomeAssistant) -> None:
"""Test import with host and non-default port.""" """Test import with host and non-default port."""
with patch( with patch(
"homeassistant.components.cert_expiry.config_flow.get_cert_expiry_timestamp" "homeassistant.components.cert_expiry.config_flow.get_cert_expiry_timestamp"
@ -129,7 +130,7 @@ async def test_import_non_default_port(hass):
assert result["result"].unique_id == f"{HOST}:888" assert result["result"].unique_id == f"{HOST}:888"
async def test_import_with_name(hass): async def test_import_with_name(hass: HomeAssistant) -> None:
"""Test import with name (deprecated).""" """Test import with name (deprecated)."""
with patch( with patch(
"homeassistant.components.cert_expiry.config_flow.get_cert_expiry_timestamp" "homeassistant.components.cert_expiry.config_flow.get_cert_expiry_timestamp"
@ -151,7 +152,7 @@ async def test_import_with_name(hass):
assert result["result"].unique_id == f"{HOST}:{PORT}" assert result["result"].unique_id == f"{HOST}:{PORT}"
async def test_bad_import(hass): async def test_bad_import(hass: HomeAssistant) -> None:
"""Test import step.""" """Test import step."""
with patch( with patch(
"homeassistant.components.cert_expiry.helper.get_cert", "homeassistant.components.cert_expiry.helper.get_cert",
@ -167,7 +168,7 @@ async def test_bad_import(hass):
assert result["reason"] == "import_failed" assert result["reason"] == "import_failed"
async def test_abort_if_already_setup(hass): async def test_abort_if_already_setup(hass: HomeAssistant) -> None:
"""Test we abort if the cert is already setup.""" """Test we abort if the cert is already setup."""
MockConfigEntry( MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -192,7 +193,7 @@ async def test_abort_if_already_setup(hass):
assert result["reason"] == "already_configured" assert result["reason"] == "already_configured"
async def test_abort_on_socket_failed(hass): async def test_abort_on_socket_failed(hass: HomeAssistant) -> None:
"""Test we abort of we have errors during socket creation.""" """Test we abort of we have errors during socket creation."""
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}

View file

@ -12,7 +12,7 @@ from homeassistant.const import (
EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STARTED,
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
) )
from homeassistant.core import CoreState from homeassistant.core import CoreState, 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
@ -22,7 +22,7 @@ from .helpers import future_timestamp, static_datetime
from tests.common import MockConfigEntry, async_fire_time_changed from tests.common import MockConfigEntry, async_fire_time_changed
async def test_setup_with_config(hass): async def test_setup_with_config(hass: HomeAssistant) -> None:
"""Test setup component with config.""" """Test setup component with config."""
assert hass.state is CoreState.running assert hass.state is CoreState.running
@ -50,7 +50,7 @@ async def test_setup_with_config(hass):
assert len(hass.config_entries.async_entries(DOMAIN)) == 2 assert len(hass.config_entries.async_entries(DOMAIN)) == 2
async def test_update_unique_id(hass): async def test_update_unique_id(hass: HomeAssistant) -> None:
"""Test updating a config entry without a unique_id.""" """Test updating a config entry without a unique_id."""
assert hass.state is CoreState.running assert hass.state is CoreState.running
@ -116,7 +116,7 @@ async def test_unload_config_entry(mock_now, hass):
assert state is None assert state is None
async def test_delay_load_during_startup(hass): async def test_delay_load_during_startup(hass: HomeAssistant) -> None:
"""Test delayed loading of a config entry during startup.""" """Test delayed loading of a config entry during startup."""
hass.state = CoreState.not_running hass.state = CoreState.not_running

View file

@ -6,7 +6,7 @@ from unittest.mock import patch
from homeassistant.components.cert_expiry.const import DOMAIN from homeassistant.components.cert_expiry.const import DOMAIN
from homeassistant.const import CONF_HOST, CONF_PORT, STATE_UNAVAILABLE, STATE_UNKNOWN from homeassistant.const import CONF_HOST, CONF_PORT, STATE_UNAVAILABLE, STATE_UNKNOWN
from homeassistant.core import CoreState from homeassistant.core import CoreState, HomeAssistant
from homeassistant.util.dt import utcnow from homeassistant.util.dt import utcnow
from .const import HOST, PORT from .const import HOST, PORT
@ -44,7 +44,7 @@ async def test_async_setup_entry(mock_now, hass):
assert state.attributes.get("is_valid") assert state.attributes.get("is_valid")
async def test_async_setup_entry_bad_cert(hass): async def test_async_setup_entry_bad_cert(hass: HomeAssistant) -> None:
"""Test async_setup_entry with a bad/expired cert.""" """Test async_setup_entry with a bad/expired cert."""
assert hass.state is CoreState.running assert hass.state is CoreState.running
@ -69,7 +69,7 @@ async def test_async_setup_entry_bad_cert(hass):
assert not state.attributes.get("is_valid") assert not state.attributes.get("is_valid")
async def test_update_sensor(hass): async def test_update_sensor(hass: HomeAssistant) -> None:
"""Test async_update for sensor.""" """Test async_update for sensor."""
assert hass.state is CoreState.running assert hass.state is CoreState.running
@ -113,7 +113,7 @@ async def test_update_sensor(hass):
assert state.attributes.get("is_valid") assert state.attributes.get("is_valid")
async def test_update_sensor_network_errors(hass): async def test_update_sensor_network_errors(hass: HomeAssistant) -> None:
"""Test async_update for sensor.""" """Test async_update for sensor."""
assert hass.state is CoreState.running assert hass.state is CoreState.running

View file

@ -9,6 +9,7 @@ import requests_mock
from homeassistant.components import notify from homeassistant.components import notify
import homeassistant.components.clicksend_tts.notify as cs_tts import homeassistant.components.clicksend_tts.notify as cs_tts
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
@ -62,7 +63,7 @@ async def test_no_notify_service(hass, mock_clicksend_tts_notify, caplog):
assert "Failed to initialize notification service clicksend_tts" in caplog.text assert "Failed to initialize notification service clicksend_tts" in caplog.text
async def test_send_simple_message(hass): async def test_send_simple_message(hass: HomeAssistant) -> None:
"""Test sending a simple message with success.""" """Test sending a simple message with success."""
with requests_mock.Mocker() as mock: with requests_mock.Mocker() as mock:

View file

@ -5,6 +5,7 @@ import voluptuous_serialize
import homeassistant.components.automation as automation import homeassistant.components.automation as automation
from homeassistant.components.climate import DOMAIN, HVACMode, const, device_action from homeassistant.components.climate import DOMAIN, HVACMode, const, device_action
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
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
@ -148,7 +149,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(
"climate.entity", "climate.entity",

View file

@ -12,6 +12,7 @@ from homeassistant.components.climate import (
) )
from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.const import UnitOfTemperature from homeassistant.const import UnitOfTemperature
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
@ -254,7 +255,7 @@ async def test_if_fires_on_state_change(hass, calls):
assert calls[2].data["some"] == "current_humidity_changed" assert calls[2].data["some"] == "current_humidity_changed"
async def test_get_trigger_capabilities_hvac_mode(hass): async def test_get_trigger_capabilities_hvac_mode(hass: HomeAssistant) -> None:
"""Test we get the expected capabilities from a climate trigger.""" """Test we get the expected capabilities from a climate trigger."""
capabilities = await device_trigger.async_get_trigger_capabilities( capabilities = await device_trigger.async_get_trigger_capabilities(
hass, hass,

View file

@ -11,11 +11,14 @@ from homeassistant.components.climate import (
ClimateEntity, ClimateEntity,
HVACMode, HVACMode,
) )
from homeassistant.core import HomeAssistant
from tests.common import async_mock_service from tests.common import async_mock_service
async def test_set_temp_schema_no_req(hass, caplog): async def test_set_temp_schema_no_req(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test the set temperature schema with missing required data.""" """Test the set temperature schema with missing required data."""
domain = "climate" domain = "climate"
service = "test_set_temperature" service = "test_set_temperature"
@ -30,7 +33,9 @@ async def test_set_temp_schema_no_req(hass, caplog):
assert len(calls) == 0 assert len(calls) == 0
async def test_set_temp_schema(hass, caplog): async def test_set_temp_schema(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test the set temperature schema with ok required data.""" """Test the set temperature schema with ok required data."""
domain = "climate" domain = "climate"
service = "test_set_temperature" service = "test_set_temperature"
@ -71,7 +76,7 @@ class MockClimateEntity(ClimateEntity):
"""Turn off.""" """Turn off."""
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."""
climate = MockClimateEntity() climate = MockClimateEntity()
climate.hass = hass climate.hass = hass
@ -82,7 +87,7 @@ async def test_sync_turn_on(hass):
assert climate.turn_on.called assert climate.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."""
climate = MockClimateEntity() climate = MockClimateEntity()
climate.hass = hass climate.hass = hass

View file

@ -1,5 +1,4 @@
"""The tests for reproduction of state.""" """The tests for reproduction of state."""
import pytest import pytest
from homeassistant.components.climate import ( from homeassistant.components.climate import (
@ -22,7 +21,7 @@ from homeassistant.components.climate import (
) )
from homeassistant.components.climate.reproduce_state import async_reproduce_states from homeassistant.components.climate.reproduce_state import async_reproduce_states
from homeassistant.const import ATTR_TEMPERATURE from homeassistant.const import ATTR_TEMPERATURE
from homeassistant.core import Context, State from homeassistant.core import Context, HomeAssistant, State
from tests.common import async_mock_service from tests.common import async_mock_service
@ -43,7 +42,7 @@ async def test_with_hvac_mode(hass, state):
assert calls[0].data == {"entity_id": ENTITY_1, "hvac_mode": state} assert calls[0].data == {"entity_id": ENTITY_1, "hvac_mode": state}
async def test_multiple_state(hass): async def test_multiple_state(hass: HomeAssistant) -> None:
"""Test that multiple states gets calls.""" """Test that multiple states gets calls."""
calls_1 = async_mock_service(hass, DOMAIN, SERVICE_SET_HVAC_MODE) calls_1 = async_mock_service(hass, DOMAIN, SERVICE_SET_HVAC_MODE)
@ -65,7 +64,7 @@ async def test_multiple_state(hass):
) )
async def test_state_with_none(hass): async def test_state_with_none(hass: HomeAssistant) -> None:
"""Test that none is not a hvac state.""" """Test that none is not a hvac state."""
calls = async_mock_service(hass, DOMAIN, SERVICE_SET_HVAC_MODE) calls = async_mock_service(hass, DOMAIN, SERVICE_SET_HVAC_MODE)
@ -76,7 +75,7 @@ async def test_state_with_none(hass):
assert len(calls) == 0 assert len(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."""
calls = async_mock_service(hass, DOMAIN, SERVICE_SET_HVAC_MODE) calls = async_mock_service(hass, DOMAIN, SERVICE_SET_HVAC_MODE)
@ -120,7 +119,7 @@ async def test_attribute(hass, service, attribute):
assert calls_1[0].data == {"entity_id": ENTITY_1, attribute: value} assert calls_1[0].data == {"entity_id": ENTITY_1, attribute: value}
async def test_attribute_partial_temperature(hass): async def test_attribute_partial_temperature(hass: HomeAssistant) -> None:
"""Test that service call ignores null attributes.""" """Test that service call ignores null attributes."""
calls_1 = async_mock_service(hass, DOMAIN, SERVICE_SET_TEMPERATURE) calls_1 = async_mock_service(hass, DOMAIN, SERVICE_SET_TEMPERATURE)
@ -145,7 +144,7 @@ async def test_attribute_partial_temperature(hass):
assert calls_1[0].data == {"entity_id": ENTITY_1, ATTR_TEMPERATURE: 23.1} assert calls_1[0].data == {"entity_id": ENTITY_1, ATTR_TEMPERATURE: 23.1}
async def test_attribute_partial_high_low_temperature(hass): async def test_attribute_partial_high_low_temperature(hass: HomeAssistant) -> None:
"""Test that service call ignores null attributes.""" """Test that service call ignores null attributes."""
calls_1 = async_mock_service(hass, DOMAIN, SERVICE_SET_TEMPERATURE) calls_1 = async_mock_service(hass, DOMAIN, SERVICE_SET_TEMPERATURE)

View file

@ -8,6 +8,7 @@ import pytest
from homeassistant import config_entries, data_entry_flow from homeassistant import config_entries, data_entry_flow
from homeassistant.components.cloud import account_link from homeassistant.components.cloud import account_link
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.helpers import config_entry_oauth2_flow
from homeassistant.util.dt import utcnow from homeassistant.util.dt import utcnow
@ -36,7 +37,7 @@ def flow_handler(hass):
yield TestFlowHandler yield TestFlowHandler
async def test_setup_provide_implementation(hass): async def test_setup_provide_implementation(hass: HomeAssistant) -> None:
"""Test that we provide implementations.""" """Test that we provide implementations."""
legacy_entry = MockConfigEntry( legacy_entry = MockConfigEntry(
domain="legacy", domain="legacy",
@ -124,7 +125,7 @@ async def test_setup_provide_implementation(hass):
assert dev_implementations["cloud"].hass is hass assert dev_implementations["cloud"].hass is hass
async def test_get_services_cached(hass): async def test_get_services_cached(hass: HomeAssistant) -> None:
"""Test that we cache services.""" """Test that we cache services."""
hass.data["cloud"] = None hass.data["cloud"] = None
@ -153,7 +154,7 @@ async def test_get_services_cached(hass):
assert await account_link._get_services(hass) == 4 assert await account_link._get_services(hass) == 4
async def test_get_services_error(hass): async def test_get_services_error(hass: HomeAssistant) -> None:
"""Test that we cache services.""" """Test that we cache services."""
hass.data["cloud"] = None hass.data["cloud"] = None

View file

@ -2,12 +2,13 @@
from unittest.mock import Mock, patch from unittest.mock import Mock, patch
from homeassistant.components.cloud.const import DISPATCHER_REMOTE_UPDATE from homeassistant.components.cloud.const import DISPATCHER_REMOTE_UPDATE
from homeassistant.core import HomeAssistant
from homeassistant.helpers.discovery import async_load_platform from homeassistant.helpers.discovery import async_load_platform
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
async def test_remote_connection_sensor(hass): async def test_remote_connection_sensor(hass: HomeAssistant) -> None:
"""Test the remote connection sensor.""" """Test the remote connection sensor."""
assert await async_setup_component(hass, "cloud", {"cloud": {}}) assert await async_setup_component(hass, "cloud", {"cloud": {}})
await hass.async_block_till_done() await hass.async_block_till_done()

View file

@ -14,7 +14,7 @@ from homeassistant.components.cloud.const import (
PREF_ENABLE_GOOGLE, PREF_ENABLE_GOOGLE,
) )
from homeassistant.const import CONTENT_TYPE_JSON from homeassistant.const import CONTENT_TYPE_JSON
from homeassistant.core import State from homeassistant.core import HomeAssistant, State
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
@ -30,7 +30,7 @@ def mock_cloud_inst():
return MagicMock(subscription_expired=False) return MagicMock(subscription_expired=False)
async def test_handler_alexa(hass): async def test_handler_alexa(hass: HomeAssistant) -> None:
"""Test handler Alexa.""" """Test handler Alexa."""
hass.states.async_set("switch.test", "on", {"friendly_name": "Test switch"}) hass.states.async_set("switch.test", "on", {"friendly_name": "Test switch"})
hass.states.async_set("switch.test2", "on", {"friendly_name": "Test switch 2"}) hass.states.async_set("switch.test2", "on", {"friendly_name": "Test switch 2"})
@ -83,7 +83,7 @@ async def test_handler_alexa_disabled(hass, mock_cloud_fixture):
assert resp["event"]["payload"]["type"] == "BRIDGE_UNREACHABLE" assert resp["event"]["payload"]["type"] == "BRIDGE_UNREACHABLE"
async def test_handler_google_actions(hass): async def test_handler_google_actions(hass: HomeAssistant) -> None:
"""Test handler Google Actions.""" """Test handler Google Actions."""
hass.states.async_set("switch.test", "on", {"friendly_name": "Test switch"}) hass.states.async_set("switch.test", "on", {"friendly_name": "Test switch"})
hass.states.async_set("switch.test2", "on", {"friendly_name": "Test switch 2"}) hass.states.async_set("switch.test2", "on", {"friendly_name": "Test switch 2"})
@ -164,7 +164,9 @@ async def test_handler_google_actions_disabled(
assert resp["payload"] == response_payload assert resp["payload"] == response_payload
async def test_webhook_msg(hass, caplog): async def test_webhook_msg(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test webhook msg.""" """Test webhook msg."""
with patch("hass_nabucasa.Cloud.initialize"): with patch("hass_nabucasa.Cloud.initialize"):
setup = await async_setup_component(hass, "cloud", {"cloud": {}}) setup = await async_setup_component(hass, "cloud", {"cloud": {}})
@ -269,7 +271,7 @@ async def test_google_config_should_2fa(hass, mock_cloud_setup, mock_cloud_login
assert not gconf.should_2fa(state) assert not gconf.should_2fa(state)
async def test_set_username(hass): async def test_set_username(hass: HomeAssistant) -> None:
"""Test we set username during login.""" """Test we set username during login."""
prefs = MagicMock( prefs = MagicMock(
alexa_enabled=False, alexa_enabled=False,
@ -284,7 +286,9 @@ async def test_set_username(hass):
assert prefs.async_set_username.mock_calls[0][1][0] == "mock-username" assert prefs.async_set_username.mock_calls[0][1][0] == "mock-username"
async def test_login_recovers_bad_internet(hass, caplog): async def test_login_recovers_bad_internet(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test Alexa can recover bad auth.""" """Test Alexa can recover bad auth."""
prefs = Mock( prefs = Mock(
alexa_enabled=True, alexa_enabled=True,

View file

@ -14,12 +14,13 @@ from homeassistant.components.alexa import errors as alexa_errors
from homeassistant.components.alexa.entities import LightCapabilities from homeassistant.components.alexa.entities import LightCapabilities
from homeassistant.components.cloud.const import DOMAIN from homeassistant.components.cloud.const import DOMAIN
from homeassistant.components.google_assistant.helpers import GoogleEntity from homeassistant.components.google_assistant.helpers import GoogleEntity
from homeassistant.core import State from homeassistant.core import HomeAssistant, State
from homeassistant.util.location import LocationInfo from homeassistant.util.location import LocationInfo
from . import mock_cloud, mock_cloud_prefs from . import mock_cloud, mock_cloud_prefs
from tests.components.google_assistant import MockConfig from tests.components.google_assistant import MockConfig
from tests.typing import WebSocketGenerator
SUBSCRIPTION_INFO_URL = "https://api-test.hass.io/payments/subscription_info" SUBSCRIPTION_INFO_URL = "https://api-test.hass.io/payments/subscription_info"
@ -427,7 +428,9 @@ async def test_websocket_status(
} }
async def test_websocket_status_not_logged_in(hass, hass_ws_client): async def test_websocket_status_not_logged_in(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test querying the status.""" """Test querying the status."""
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
await client.send_json({"id": 5, "type": "cloud/status"}) await client.send_json({"id": 5, "type": "cloud/status"})
@ -466,7 +469,9 @@ async def test_websocket_subscription_fail(
assert response["error"]["code"] == "request_failed" assert response["error"]["code"] == "request_failed"
async def test_websocket_subscription_not_logged_in(hass, hass_ws_client): async def test_websocket_subscription_not_logged_in(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test querying the status.""" """Test querying the status."""
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
with patch( with patch(

View file

@ -1,5 +1,4 @@
"""Test the cloud component.""" """Test the cloud component."""
from unittest.mock import patch from unittest.mock import patch
import pytest import pytest
@ -8,12 +7,12 @@ from homeassistant.components import cloud
from homeassistant.components.cloud.const import DOMAIN from homeassistant.components.cloud.const import DOMAIN
from homeassistant.components.cloud.prefs import STORAGE_KEY from homeassistant.components.cloud.prefs import STORAGE_KEY
from homeassistant.const import EVENT_HOMEASSISTANT_STOP from homeassistant.const import EVENT_HOMEASSISTANT_STOP
from homeassistant.core import Context from homeassistant.core import Context, HomeAssistant
from homeassistant.exceptions import Unauthorized from homeassistant.exceptions import Unauthorized
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
async def test_constructor_loads_info_from_config(hass): async def test_constructor_loads_info_from_config(hass: HomeAssistant) -> None:
"""Test non-dev mode loads info from SERVERS constant.""" """Test non-dev mode loads info from SERVERS constant."""
with patch("hass_nabucasa.Cloud.initialize"): with patch("hass_nabucasa.Cloud.initialize"):
result = await async_setup_component( result = await async_setup_component(

View file

@ -3,9 +3,10 @@ from unittest.mock import patch
from homeassistant.auth.const import GROUP_ID_ADMIN from homeassistant.auth.const import GROUP_ID_ADMIN
from homeassistant.components.cloud.prefs import STORAGE_KEY, CloudPreferences from homeassistant.components.cloud.prefs import STORAGE_KEY, CloudPreferences
from homeassistant.core import HomeAssistant
async def test_set_username(hass): async def test_set_username(hass: HomeAssistant) -> None:
"""Test we clear config if we set different username.""" """Test we clear config if we set different username."""
prefs = CloudPreferences(hass) prefs = CloudPreferences(hass)
await prefs.async_initialize() await prefs.async_initialize()
@ -21,7 +22,7 @@ async def test_set_username(hass):
assert prefs.google_enabled assert prefs.google_enabled
async def test_set_username_migration(hass): async def test_set_username_migration(hass: HomeAssistant) -> None:
"""Test we not clear config if we had no username.""" """Test we not clear config if we had no username."""
prefs = CloudPreferences(hass) prefs = CloudPreferences(hass)

View file

@ -4,13 +4,17 @@ from unittest.mock import Mock
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 homeassistant.util.dt import utcnow from homeassistant.util.dt import utcnow
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_cloud_system_health(hass, aioclient_mock): async def test_cloud_system_health(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test cloud system health.""" """Test cloud system health."""
aioclient_mock.get("https://cloud.bla.com/status", text="") aioclient_mock.get("https://cloud.bla.com/status", text="")
aioclient_mock.get("https://cert-server/directory", text="") aioclient_mock.get("https://cert-server/directory", text="")

View file

@ -8,6 +8,7 @@ from pycfdns.exceptions import (
from homeassistant.components.cloudflare.const import CONF_RECORDS, DOMAIN from homeassistant.components.cloudflare.const import CONF_RECORDS, DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
from homeassistant.const import CONF_API_TOKEN, CONF_SOURCE, CONF_ZONE from homeassistant.const import CONF_API_TOKEN, CONF_SOURCE, CONF_ZONE
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType from homeassistant.data_entry_flow import FlowResultType
from . import ( from . import (
@ -144,7 +145,7 @@ async def test_user_form_unexpected_exception(hass, cfupdate_flow):
assert result["errors"] == {"base": "unknown"} assert result["errors"] == {"base": "unknown"}
async def test_user_form_single_instance_allowed(hass): async def test_user_form_single_instance_allowed(hass: HomeAssistant) -> None:
"""Test that configuring more than one instance is rejected.""" """Test that configuring more than one instance is rejected."""
entry = MockConfigEntry(domain=DOMAIN, data=ENTRY_CONFIG) entry = MockConfigEntry(domain=DOMAIN, data=ENTRY_CONFIG)
entry.add_to_hass(hass) entry.add_to_hass(hass)

View file

@ -4,15 +4,19 @@ from unittest.mock import patch
from homeassistant.components.co2signal import DOMAIN from homeassistant.components.co2signal import DOMAIN
from homeassistant.components.diagnostics import REDACTED from homeassistant.components.diagnostics import REDACTED
from homeassistant.const import CONF_API_KEY from homeassistant.const import CONF_API_KEY
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from . import VALID_PAYLOAD from . import VALID_PAYLOAD
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator
async def test_entry_diagnostics(hass, hass_client): async def test_entry_diagnostics(
hass: HomeAssistant, hass_client: ClientSessionGenerator
) -> None:
"""Test config entry diagnostics.""" """Test config entry diagnostics."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, data={CONF_API_KEY: "api_key", "location": ""} domain=DOMAIN, data={CONF_API_KEY: "api_key", "location": ""}

View file

@ -3,6 +3,7 @@ import logging
from unittest.mock import patch from unittest.mock import patch
from coinbase.wallet.error import AuthenticationError from coinbase.wallet.error import AuthenticationError
import pytest
from requests.models import Response from requests.models import Response
from homeassistant import config_entries from homeassistant import config_entries
@ -13,6 +14,7 @@ from homeassistant.components.coinbase.const import (
DOMAIN, DOMAIN,
) )
from homeassistant.const import CONF_API_KEY, CONF_API_TOKEN from homeassistant.const import CONF_API_KEY, CONF_API_TOKEN
from homeassistant.core import HomeAssistant
from .common import ( from .common import (
init_mock_coinbase, init_mock_coinbase,
@ -23,7 +25,7 @@ from .common import (
from .const import BAD_CURRENCY, BAD_EXCHANGE_RATE, GOOD_CURRENCY, GOOD_EXCHANGE_RATE from .const import BAD_CURRENCY, BAD_EXCHANGE_RATE, GOOD_CURRENCY, GOOD_EXCHANGE_RATE
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(
@ -59,7 +61,9 @@ 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, caplog): async def test_form_invalid_auth(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> 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}
@ -138,7 +142,7 @@ async def test_form_invalid_auth(hass, caplog):
) )
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}
@ -160,7 +164,7 @@ async def test_form_cannot_connect(hass):
assert result2["errors"] == {"base": "cannot_connect"} assert result2["errors"] == {"base": "cannot_connect"}
async def test_form_catch_all_exception(hass): async def test_form_catch_all_exception(hass: HomeAssistant) -> None:
"""Test we handle unknown exceptions.""" """Test we handle unknown exceptions."""
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}
@ -182,7 +186,7 @@ async def test_form_catch_all_exception(hass):
assert result2["errors"] == {"base": "unknown"} assert result2["errors"] == {"base": "unknown"}
async def test_option_form(hass): async def test_option_form(hass: HomeAssistant) -> None:
"""Test we handle a good wallet currency option.""" """Test we handle a good wallet currency option."""
with patch( with patch(
@ -213,7 +217,7 @@ async def test_option_form(hass):
assert len(mock_update_listener.mock_calls) == 1 assert len(mock_update_listener.mock_calls) == 1
async def test_form_bad_account_currency(hass): async def test_form_bad_account_currency(hass: HomeAssistant) -> None:
"""Test we handle a bad currency option.""" """Test we handle a bad currency option."""
with patch( with patch(
"coinbase.wallet.client.Client.get_current_user", "coinbase.wallet.client.Client.get_current_user",
@ -240,7 +244,7 @@ async def test_form_bad_account_currency(hass):
assert result2["errors"] == {"base": "currency_unavailable"} assert result2["errors"] == {"base": "currency_unavailable"}
async def test_form_bad_exchange_rate(hass): async def test_form_bad_exchange_rate(hass: HomeAssistant) -> None:
"""Test we handle a bad exchange rate.""" """Test we handle a bad exchange rate."""
with patch( with patch(
"coinbase.wallet.client.Client.get_current_user", "coinbase.wallet.client.Client.get_current_user",
@ -266,7 +270,7 @@ async def test_form_bad_exchange_rate(hass):
assert result2["errors"] == {"base": "exchange_rate_unavailable"} assert result2["errors"] == {"base": "exchange_rate_unavailable"}
async def test_option_catch_all_exception(hass): async def test_option_catch_all_exception(hass: HomeAssistant) -> None:
"""Test we handle an unknown exception in the option flow.""" """Test we handle an unknown exception in the option flow."""
with patch( with patch(
"coinbase.wallet.client.Client.get_current_user", "coinbase.wallet.client.Client.get_current_user",

View file

@ -25,7 +25,7 @@ from .const import (
) )
async def test_unload_entry(hass): async def test_unload_entry(hass: HomeAssistant) -> None:
"""Test successful unload of entry.""" """Test successful unload of entry."""
with patch( with patch(
"coinbase.wallet.client.Client.get_current_user", "coinbase.wallet.client.Client.get_current_user",

View file

@ -21,10 +21,12 @@ from homeassistant.components.light import (
SERVICE_TURN_OFF as LIGHT_SERVICE_TURN_OFF, SERVICE_TURN_OFF as LIGHT_SERVICE_TURN_OFF,
) )
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
import homeassistant.util.color as color_util import homeassistant.util.color as color_util
from tests.common import load_fixture from tests.common import load_fixture
from tests.test_util.aiohttp import AiohttpClientMocker
LIGHT_ENTITY = "light.kitchen_lights" LIGHT_ENTITY = "light.kitchen_lights"
CLOSE_THRESHOLD = 10 CLOSE_THRESHOLD = 10
@ -84,7 +86,7 @@ async def setup_light(hass):
assert state.state == STATE_OFF assert state.state == STATE_OFF
async def test_missing_url_and_path(hass): async def test_missing_url_and_path(hass: HomeAssistant) -> None:
"""Test that nothing happens when url and path are missing.""" """Test that nothing happens when url and path are missing."""
# Load our color_extractor component # Load our color_extractor component
await async_setup_component( await async_setup_component(
@ -138,7 +140,9 @@ async def _async_load_color_extractor_url(hass, service_data):
await hass.async_block_till_done() await hass.async_block_till_done()
async def test_url_success(hass, aioclient_mock): async def test_url_success(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test that a successful image GET translate to light RGB.""" """Test that a successful image GET translate to light RGB."""
service_data = { service_data = {
ATTR_URL: "http://example.com/images/logo.png", ATTR_URL: "http://example.com/images/logo.png",
@ -171,7 +175,9 @@ async def test_url_success(hass, aioclient_mock):
assert _close_enough(state.attributes[ATTR_RGB_COLOR], (50, 100, 150)) assert _close_enough(state.attributes[ATTR_RGB_COLOR], (50, 100, 150))
async def test_url_not_allowed(hass, aioclient_mock): async def test_url_not_allowed(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test that a not allowed external URL fails to turn light on.""" """Test that a not allowed external URL fails to turn light on."""
service_data = { service_data = {
ATTR_URL: "http://denied.com/images/logo.png", ATTR_URL: "http://denied.com/images/logo.png",
@ -186,7 +192,9 @@ async def test_url_not_allowed(hass, aioclient_mock):
assert state.state == STATE_OFF assert state.state == STATE_OFF
async def test_url_exception(hass, aioclient_mock): async def test_url_exception(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test that a HTTPError fails to turn light on.""" """Test that a HTTPError fails to turn light on."""
service_data = { service_data = {
ATTR_URL: "http://example.com/images/logo.png", ATTR_URL: "http://example.com/images/logo.png",
@ -207,7 +215,9 @@ async def test_url_exception(hass, aioclient_mock):
assert state.state == STATE_OFF assert state.state == STATE_OFF
async def test_url_error(hass, aioclient_mock): async def test_url_error(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test that a HTTP Error (non 200) doesn't turn light on.""" """Test that a HTTP Error (non 200) doesn't turn light on."""
service_data = { service_data = {
ATTR_URL: "http://example.com/images/logo.png", ATTR_URL: "http://example.com/images/logo.png",
@ -248,7 +258,7 @@ def _get_file_mock(file_path):
@patch("os.path.isfile", Mock(return_value=True)) @patch("os.path.isfile", Mock(return_value=True))
@patch("os.access", Mock(return_value=True)) @patch("os.access", Mock(return_value=True))
async def test_file(hass): async def test_file(hass: HomeAssistant) -> None:
"""Test that the file only service reads a file and translates to light RGB.""" """Test that the file only service reads a file and translates to light RGB."""
service_data = { service_data = {
ATTR_PATH: "/opt/image.png", ATTR_PATH: "/opt/image.png",
@ -289,7 +299,7 @@ async def test_file(hass):
@patch("os.path.isfile", Mock(return_value=True)) @patch("os.path.isfile", Mock(return_value=True))
@patch("os.access", Mock(return_value=True)) @patch("os.access", Mock(return_value=True))
async def test_file_denied_dir(hass): async def test_file_denied_dir(hass: HomeAssistant) -> None:
"""Test that the file only service fails to read an image in a dir not explicitly allowed.""" """Test that the file only service fails to read an image in a dir not explicitly allowed."""
service_data = { service_data = {
ATTR_PATH: "/path/to/a/dir/not/allowed/image.png", ATTR_PATH: "/path/to/a/dir/not/allowed/image.png",

View file

@ -1,4 +1,5 @@
"""The tests for the integration sensor platform.""" """The tests for the integration sensor platform."""
import pytest
from homeassistant.components.compensation.const import CONF_PRECISION, DOMAIN from homeassistant.components.compensation.const import CONF_PRECISION, DOMAIN
from homeassistant.components.compensation.sensor import ATTR_COEFFICIENTS from homeassistant.components.compensation.sensor import ATTR_COEFFICIENTS
@ -9,10 +10,11 @@ from homeassistant.const import (
EVENT_STATE_CHANGED, EVENT_STATE_CHANGED,
STATE_UNKNOWN, STATE_UNKNOWN,
) )
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
async def test_linear_state(hass): async def test_linear_state(hass: HomeAssistant) -> None:
"""Test compensation sensor state.""" """Test compensation sensor state."""
config = { config = {
"compensation": { "compensation": {
@ -57,7 +59,7 @@ async def test_linear_state(hass):
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
async def test_linear_state_from_attribute(hass): async def test_linear_state_from_attribute(hass: HomeAssistant) -> None:
"""Test compensation sensor state that pulls from attribute.""" """Test compensation sensor state that pulls from attribute."""
config = { config = {
"compensation": { "compensation": {
@ -101,7 +103,7 @@ async def test_linear_state_from_attribute(hass):
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN
async def test_quadratic_state(hass): async def test_quadratic_state(hass: HomeAssistant) -> None:
"""Test 3 degree polynominial compensation sensor.""" """Test 3 degree polynominial compensation sensor."""
config = { config = {
"compensation": { "compensation": {
@ -145,7 +147,9 @@ async def test_quadratic_state(hass):
assert round(float(state.state), config[DOMAIN]["test"][CONF_PRECISION]) == 3.327 assert round(float(state.state), config[DOMAIN]["test"][CONF_PRECISION]) == 3.327
async def test_numpy_errors(hass, caplog): async def test_numpy_errors(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Tests bad polyfits.""" """Tests bad polyfits."""
config = { config = {
"compensation": { "compensation": {
@ -166,7 +170,9 @@ async def test_numpy_errors(hass, caplog):
assert "invalid value encountered in divide" in caplog.text assert "invalid value encountered in divide" in caplog.text
async def test_datapoints_greater_than_degree(hass, caplog): async def test_datapoints_greater_than_degree(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Tests 3 bad data points.""" """Tests 3 bad data points."""
config = { config = {
"compensation": { "compensation": {
@ -188,7 +194,7 @@ async def test_datapoints_greater_than_degree(hass, caplog):
assert "data_points must have at least 3 data_points" in caplog.text assert "data_points must have at least 3 data_points" in caplog.text
async def test_new_state_is_none(hass): async def test_new_state_is_none(hass: HomeAssistant) -> None:
"""Tests catch for empty new states.""" """Tests catch for empty new states."""
config = { config = {
"compensation": { "compensation": {

View file

@ -3,8 +3,10 @@ import pytest
from homeassistant.auth import models as auth_models from homeassistant.auth import models as auth_models
from homeassistant.components.config import auth as auth_config from homeassistant.components.config import auth as auth_config
from homeassistant.core import HomeAssistant
from tests.common import CLIENT_ID, MockGroup, MockUser from tests.common import CLIENT_ID, MockGroup, MockUser
from tests.typing import WebSocketGenerator
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
@ -224,7 +226,7 @@ async def test_create_requires_admin(hass, hass_ws_client, hass_read_only_access
assert result["error"]["code"] == "unauthorized" assert result["error"]["code"] == "unauthorized"
async def test_update(hass, hass_ws_client): async def test_update(hass: HomeAssistant, hass_ws_client: WebSocketGenerator) -> None:
"""Test update command works.""" """Test update command works."""
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
@ -272,7 +274,9 @@ async def test_update_requires_admin(hass, hass_ws_client, hass_read_only_access
assert user.name == "Test user" assert user.name == "Test user"
async def test_update_system_generated(hass, hass_ws_client): async def test_update_system_generated(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test update command cannot update a system generated.""" """Test update command cannot update a system generated."""
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
@ -293,7 +297,9 @@ async def test_update_system_generated(hass, hass_ws_client):
assert user.name == "Test user" assert user.name == "Test user"
async def test_deactivate(hass, hass_ws_client): async def test_deactivate(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test deactivation and reactivation of regular user.""" """Test deactivation and reactivation of regular user."""
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
@ -331,7 +337,9 @@ async def test_deactivate(hass, hass_ws_client):
assert data_user["is_active"] is True assert data_user["is_active"] is True
async def test_deactivate_owner(hass, hass_ws_client): async def test_deactivate_owner(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test that owner cannot be deactivated.""" """Test that owner cannot be deactivated."""
user = MockUser(id="abc", name="Test Owner", is_owner=True).add_to_hass(hass) user = MockUser(id="abc", name="Test Owner", is_owner=True).add_to_hass(hass)
@ -348,7 +356,9 @@ async def test_deactivate_owner(hass, hass_ws_client):
assert result["error"]["code"] == "cannot_deactivate_owner" assert result["error"]["code"] == "cannot_deactivate_owner"
async def test_deactivate_system_generated(hass, hass_ws_client): async def test_deactivate_system_generated(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test that owner cannot be deactivated.""" """Test that owner cannot be deactivated."""
client = await hass_ws_client(hass) client = await hass_ws_client(hass)

View file

@ -3,8 +3,10 @@ import pytest
from homeassistant.auth.providers import homeassistant as prov_ha from homeassistant.auth.providers import homeassistant as prov_ha
from homeassistant.components.config import auth_provider_homeassistant as auth_ha from homeassistant.components.config import auth_provider_homeassistant as auth_ha
from homeassistant.core import HomeAssistant
from tests.common import CLIENT_ID, MockUser from tests.common import CLIENT_ID, MockUser
from tests.typing import WebSocketGenerator
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
@ -40,7 +42,9 @@ async def hass_admin_credential(hass, auth_provider):
) )
async def test_create_auth_system_generated_user(hass, hass_ws_client): async def test_create_auth_system_generated_user(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test we can't add auth to system generated users.""" """Test we can't add auth to system generated users."""
system_user = MockUser(system_generated=True).add_to_hass(hass) system_user = MockUser(system_generated=True).add_to_hass(hass)
client = await hass_ws_client(hass) client = await hass_ws_client(hass)
@ -229,7 +233,9 @@ async def test_delete_requires_admin(hass, hass_ws_client, hass_read_only_access
assert result["error"]["code"] == "unauthorized" assert result["error"]["code"] == "unauthorized"
async def test_delete_unknown_auth(hass, hass_ws_client): async def test_delete_unknown_auth(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test trying to delete an unknown auth username.""" """Test trying to delete an unknown auth username."""
client = await hass_ws_client(hass) client = await hass_ws_client(hass)

View file

@ -1,5 +1,4 @@
"""Test config entries API.""" """Test config entries API."""
from collections import OrderedDict from collections import OrderedDict
from http import HTTPStatus from http import HTTPStatus
from unittest.mock import ANY, AsyncMock, patch from unittest.mock import ANY, AsyncMock, patch
@ -10,7 +9,7 @@ import voluptuous as vol
from homeassistant import config_entries as core_ce, data_entry_flow from homeassistant import config_entries as core_ce, data_entry_flow
from homeassistant.components.config import config_entries from homeassistant.components.config import config_entries
from homeassistant.config_entries import HANDLERS, ConfigFlow from homeassistant.config_entries import HANDLERS, ConfigFlow
from homeassistant.core import callback from homeassistant.core import HomeAssistant, callback
from homeassistant.generated import config_flows from homeassistant.generated import config_flows
from homeassistant.helpers import config_entry_flow, config_validation as cv from homeassistant.helpers import config_entry_flow, config_validation as cv
from homeassistant.loader import IntegrationNotFound from homeassistant.loader import IntegrationNotFound
@ -22,6 +21,7 @@ from tests.common import (
mock_entity_platform, mock_entity_platform,
mock_integration, mock_integration,
) )
from tests.typing import WebSocketGenerator
@pytest.fixture @pytest.fixture
@ -635,7 +635,9 @@ async def test_continue_flow_unauth(hass, client, hass_admin_user):
assert resp.status == HTTPStatus.UNAUTHORIZED assert resp.status == HTTPStatus.UNAUTHORIZED
async def test_get_progress_index(hass, hass_ws_client): async def test_get_progress_index(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test querying for the flows that are in progress.""" """Test querying for the flows that are in progress."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
mock_entity_platform(hass, "config_flow.test", None) mock_entity_platform(hass, "config_flow.test", None)
@ -936,7 +938,9 @@ async def test_options_flow_with_invalid_data(hass, client):
} }
async def test_update_prefrences(hass, hass_ws_client): async def test_update_prefrences(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test that we can update system options.""" """Test that we can update system options."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
ws_client = await hass_ws_client(hass) ws_client = await hass_ws_client(hass)
@ -985,7 +989,9 @@ async def test_update_prefrences(hass, hass_ws_client):
assert entry.pref_disable_polling is True assert entry.pref_disable_polling is True
async def test_update_entry(hass, hass_ws_client): async def test_update_entry(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test that we can update entry.""" """Test that we can update entry."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
ws_client = await hass_ws_client(hass) ws_client = await hass_ws_client(hass)
@ -1008,7 +1014,9 @@ async def test_update_entry(hass, hass_ws_client):
assert entry.title == "Updated Title" assert entry.title == "Updated Title"
async def test_update_entry_nonexisting(hass, hass_ws_client): async def test_update_entry_nonexisting(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test that we can update entry.""" """Test that we can update entry."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
ws_client = await hass_ws_client(hass) ws_client = await hass_ws_client(hass)
@ -1027,7 +1035,9 @@ async def test_update_entry_nonexisting(hass, hass_ws_client):
assert response["error"]["code"] == "not_found" assert response["error"]["code"] == "not_found"
async def test_disable_entry(hass, hass_ws_client): async def test_disable_entry(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test that we can disable entry.""" """Test that we can disable entry."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
ws_client = await hass_ws_client(hass) ws_client = await hass_ws_client(hass)
@ -1085,7 +1095,9 @@ async def test_disable_entry(hass, hass_ws_client):
assert entry.state == core_ce.ConfigEntryState.FAILED_UNLOAD assert entry.state == core_ce.ConfigEntryState.FAILED_UNLOAD
async def test_disable_entry_nonexisting(hass, hass_ws_client): async def test_disable_entry_nonexisting(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test that we can disable entry.""" """Test that we can disable entry."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
ws_client = await hass_ws_client(hass) ws_client = await hass_ws_client(hass)
@ -1104,7 +1116,9 @@ async def test_disable_entry_nonexisting(hass, hass_ws_client):
assert response["error"]["code"] == "not_found" assert response["error"]["code"] == "not_found"
async def test_ignore_flow(hass, hass_ws_client): async def test_ignore_flow(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test we can ignore a flow.""" """Test we can ignore a flow."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
mock_integration( mock_integration(
@ -1147,7 +1161,9 @@ async def test_ignore_flow(hass, hass_ws_client):
assert entry.title == "Test Integration" assert entry.title == "Test Integration"
async def test_ignore_flow_nonexisting(hass, hass_ws_client): async def test_ignore_flow_nonexisting(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test we can ignore a flow.""" """Test we can ignore a flow."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
ws_client = await hass_ws_client(hass) ws_client = await hass_ws_client(hass)

View file

@ -12,9 +12,12 @@ from homeassistant.const import (
CONF_UNIT_SYSTEM_IMPERIAL, CONF_UNIT_SYSTEM_IMPERIAL,
CONF_UNIT_SYSTEM_METRIC, CONF_UNIT_SYSTEM_METRIC,
) )
from homeassistant.core import HomeAssistant
from homeassistant.util import dt as dt_util, location from homeassistant.util import dt as dt_util, location
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
from tests.typing import ClientSessionGenerator
@pytest.fixture @pytest.fixture
async def client(hass, hass_ws_client): async def client(hass, hass_ws_client):
@ -24,7 +27,9 @@ async def client(hass, hass_ws_client):
return await hass_ws_client(hass) return await hass_ws_client(hass)
async def test_validate_config_ok(hass, hass_client): async def test_validate_config_ok(
hass: HomeAssistant, hass_client: ClientSessionGenerator
) -> None:
"""Test checking config.""" """Test checking config."""
with patch.object(config, "SECTIONS", ["core"]): with patch.object(config, "SECTIONS", ["core"]):
await async_setup_component(hass, "config", {}) await async_setup_component(hass, "config", {})

View file

@ -2,6 +2,7 @@
import pytest import pytest
from homeassistant.components.config import device_registry from homeassistant.components.config import device_registry
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as helpers_dr from homeassistant.helpers import device_registry as helpers_dr
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -12,6 +13,7 @@ from tests.common import (
mock_integration, mock_integration,
) )
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401 from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
from tests.typing import WebSocketGenerator
@pytest.fixture @pytest.fixture
@ -166,7 +168,9 @@ async def test_update_device(hass, client, registry, payload_key, payload_value)
assert isinstance(device.disabled_by, (helpers_dr.DeviceEntryDisabler, type(None))) assert isinstance(device.disabled_by, (helpers_dr.DeviceEntryDisabler, type(None)))
async def test_remove_config_entry_from_device(hass, hass_ws_client): async def test_remove_config_entry_from_device(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test removing config entry from device.""" """Test removing config entry from device."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
ws_client = await hass_ws_client(hass) ws_client = await hass_ws_client(hass)
@ -271,7 +275,9 @@ async def test_remove_config_entry_from_device(hass, hass_ws_client):
assert not device_registry.async_get(device_entry.id) assert not device_registry.async_get(device_entry.id)
async def test_remove_config_entry_from_device_fails(hass, hass_ws_client): async def test_remove_config_entry_from_device_fails(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test removing config entry from device failing cases.""" """Test removing config entry from device failing cases."""
assert await async_setup_component(hass, "config", {}) assert await async_setup_component(hass, "config", {})
ws_client = await hass_ws_client(hass) ws_client = await hass_ws_client(hass)

View file

@ -14,6 +14,7 @@ from homeassistant.const import (
CONF_SCAN_INTERVAL, CONF_SCAN_INTERVAL,
CONF_USERNAME, CONF_USERNAME,
) )
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -44,7 +45,7 @@ def _get_mock_c4_director(getAllItemInfo={}):
return c4_director_mock return c4_director_mock
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(
@ -86,7 +87,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}
@ -109,7 +110,7 @@ async def test_form_invalid_auth(hass):
assert result2["errors"] == {"base": "invalid_auth"} assert result2["errors"] == {"base": "invalid_auth"}
async def test_form_unexpected_exception(hass): async def test_form_unexpected_exception(hass: HomeAssistant) -> None:
"""Test we handle an unexpected exception.""" """Test we handle an unexpected 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}
@ -132,7 +133,7 @@ async def test_form_unexpected_exception(hass):
assert result2["errors"] == {"base": "unknown"} assert result2["errors"] == {"base": "unknown"}
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}
@ -158,7 +159,7 @@ async def test_form_cannot_connect(hass):
assert result2["errors"] == {"base": "cannot_connect"} assert result2["errors"] == {"base": "cannot_connect"}
async def test_option_flow(hass): async def test_option_flow(hass: HomeAssistant) -> None:
"""Test config flow options.""" """Test config flow options."""
entry = MockConfigEntry(domain=DOMAIN, data={}, options=None) entry = MockConfigEntry(domain=DOMAIN, data={}, options=None)
entry.add_to_hass(hass) entry.add_to_hass(hass)
@ -178,7 +179,7 @@ async def test_option_flow(hass):
} }
async def test_option_flow_defaults(hass): async def test_option_flow_defaults(hass: HomeAssistant) -> None:
"""Test config flow options.""" """Test config flow options."""
entry = MockConfigEntry(domain=DOMAIN, data={}, options=None) entry = MockConfigEntry(domain=DOMAIN, data={}, options=None)
entry.add_to_hass(hass) entry.add_to_hass(hass)

View file

@ -8,7 +8,7 @@ import voluptuous as vol
from homeassistant.components import conversation from homeassistant.components import conversation
from homeassistant.components.cover import SERVICE_OPEN_COVER from homeassistant.components.cover import SERVICE_OPEN_COVER
from homeassistant.const import ATTR_FRIENDLY_NAME from homeassistant.const import ATTR_FRIENDLY_NAME
from homeassistant.core import DOMAIN as HASS_DOMAIN, Context from homeassistant.core import DOMAIN as HASS_DOMAIN, Context, HomeAssistant
from homeassistant.helpers import ( from homeassistant.helpers import (
area_registry, area_registry,
device_registry, device_registry,
@ -633,7 +633,7 @@ async def test_custom_sentences_config(hass, hass_client, hass_admin_user):
} }
async def test_prepare_reload(hass): async def test_prepare_reload(hass: HomeAssistant) -> None:
"""Test calling the reload service.""" """Test calling the reload service."""
language = hass.config.language language = hass.config.language
assert await async_setup_component(hass, "conversation", {}) assert await async_setup_component(hass, "conversation", {})
@ -654,7 +654,7 @@ async def test_prepare_reload(hass):
assert not agent._lang_intents.get(language) assert not agent._lang_intents.get(language)
async def test_prepare_fail(hass): async def test_prepare_fail(hass: HomeAssistant) -> None:
"""Test calling prepare with a non-existent language.""" """Test calling prepare with a non-existent language."""
assert await async_setup_component(hass, "conversation", {}) assert await async_setup_component(hass, "conversation", {})
@ -691,7 +691,7 @@ async def test_language_region(hass, init_components):
assert call.data == {"entity_id": "light.kitchen"} assert call.data == {"entity_id": "light.kitchen"}
async def test_reload_on_new_component(hass): async def test_reload_on_new_component(hass: HomeAssistant) -> None:
"""Test intents being reloaded when a new component is loaded.""" """Test intents being reloaded when a new component is loaded."""
language = hass.config.language language = hass.config.language
assert await async_setup_component(hass, "conversation", {}) assert await async_setup_component(hass, "conversation", {})
@ -849,7 +849,7 @@ async def test_light_area_same_name(hass, init_components):
assert call.data == {"entity_id": kitchen_light.entity_id} assert call.data == {"entity_id": kitchen_light.entity_id}
async def test_agent_id_validator_invalid_agent(hass): async def test_agent_id_validator_invalid_agent(hass: HomeAssistant) -> None:
"""Test validating agent id.""" """Test validating agent id."""
with pytest.raises(vol.Invalid): with pytest.raises(vol.Invalid):
conversation.agent_id_validator("invalid_agent") conversation.agent_id_validator("invalid_agent")

View file

@ -4,6 +4,7 @@ from unittest.mock import patch
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components.coolmaster.config_flow import AVAILABLE_MODES from homeassistant.components.coolmaster.config_flow import AVAILABLE_MODES
from homeassistant.components.coolmaster.const import DOMAIN from homeassistant.components.coolmaster.const import DOMAIN
from homeassistant.core import HomeAssistant
def _flow_data(): def _flow_data():
@ -14,7 +15,7 @@ def _flow_data():
return options return options
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(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -45,7 +46,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_timeout(hass): async def test_form_timeout(hass: HomeAssistant) -> None:
"""Test we handle a connection timeout.""" """Test we handle a connection timeout."""
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}
@ -63,7 +64,7 @@ async def test_form_timeout(hass):
assert result2["errors"] == {"base": "cannot_connect"} assert result2["errors"] == {"base": "cannot_connect"}
async def test_form_connection_refused(hass): async def test_form_connection_refused(hass: HomeAssistant) -> None:
"""Test we handle a connection error.""" """Test we handle a connection 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}
@ -81,7 +82,7 @@ async def test_form_connection_refused(hass):
assert result2["errors"] == {"base": "cannot_connect"} assert result2["errors"] == {"base": "cannot_connect"}
async def test_form_no_units(hass): async def test_form_no_units(hass: HomeAssistant) -> None:
"""Test we handle no units found.""" """Test we handle no units found."""
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}

View file

@ -1,5 +1,4 @@
"""The tests for the counter component.""" """The tests for the counter component."""
import logging import logging
import pytest import pytest
@ -20,7 +19,7 @@ from homeassistant.components.counter import (
DOMAIN, DOMAIN,
) )
from homeassistant.const import ATTR_FRIENDLY_NAME, ATTR_ICON, ATTR_NAME from homeassistant.const import ATTR_FRIENDLY_NAME, ATTR_ICON, ATTR_NAME
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
@ -67,7 +66,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}]
@ -75,7 +74,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())
@ -123,7 +122,7 @@ async def test_config_options(hass):
assert state_3.attributes.get(ATTR_STEP) == DEFAULT_STEP assert state_3.attributes.get(ATTR_STEP) == DEFAULT_STEP
async def test_methods(hass): async def test_methods(hass: HomeAssistant) -> None:
"""Test increment, decrement, and reset methods.""" """Test increment, decrement, and reset methods."""
config = {DOMAIN: {"test_1": {}}} config = {DOMAIN: {"test_1": {}}}
@ -159,7 +158,7 @@ async def test_methods(hass):
assert int(state.state) == 0 assert int(state.state) == 0
async def test_methods_with_config(hass): async def test_methods_with_config(hass: HomeAssistant) -> None:
"""Test increment, decrement, and reset methods with configuration.""" """Test increment, decrement, and reset methods with configuration."""
config = { config = {
DOMAIN: {"test": {CONF_NAME: "Hello World", CONF_INITIAL: 10, CONF_STEP: 5}} DOMAIN: {"test": {CONF_NAME: "Hello World", CONF_INITIAL: 10, CONF_STEP: 5}}
@ -191,7 +190,7 @@ async def test_methods_with_config(hass):
assert int(state.state) == 15 assert int(state.state) == 15
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("counter.test1", "11"), State("counter.test2", "-22")) hass, (State("counter.test1", "11"), State("counter.test2", "-22"))
@ -219,7 +218,7 @@ async def test_initial_state_overrules_restore_state(hass):
assert int(state.state) == 10 assert int(state.state) == 10
async def test_restore_state_overrules_initial_state(hass): async def test_restore_state_overrules_initial_state(hass: HomeAssistant) -> None:
"""Ensure states are restored on startup.""" """Ensure states are restored on startup."""
attr = {"initial": 6, "minimum": 1, "maximum": 8, "step": 2} attr = {"initial": 6, "minimum": 1, "maximum": 8, "step": 2}
@ -256,7 +255,7 @@ async def test_restore_state_overrules_initial_state(hass):
assert state.attributes.get("step") == 2 assert state.attributes.get("step") == 2
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

View file

@ -1,11 +1,15 @@
"""Test reproduce state for Counter.""" """Test reproduce state for Counter."""
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 Counter states.""" """Test reproducing Counter states."""
hass.states.async_set("counter.entity", "5", {}) hass.states.async_set("counter.entity", "5", {})
hass.states.async_set( hass.states.async_set(

View file

@ -1,16 +1,16 @@
"""The tests for the cover platform.""" """The tests for the cover platform."""
from homeassistant.components.cover import ( from homeassistant.components.cover import (
SERVICE_CLOSE_COVER, SERVICE_CLOSE_COVER,
SERVICE_OPEN_COVER, SERVICE_OPEN_COVER,
intent as cover_intent, intent as cover_intent,
) )
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_open_cover_intent(hass): async def test_open_cover_intent(hass: HomeAssistant) -> None:
"""Test HassOpenCover intent.""" """Test HassOpenCover intent."""
await cover_intent.async_setup_intents(hass) await cover_intent.async_setup_intents(hass)
@ -30,7 +30,7 @@ async def test_open_cover_intent(hass):
assert call.data == {"entity_id": "cover.garage_door"} assert call.data == {"entity_id": "cover.garage_door"}
async def test_close_cover_intent(hass): async def test_close_cover_intent(hass: HomeAssistant) -> None:
"""Test HassCloseCover intent.""" """Test HassCloseCover intent."""
await cover_intent.async_setup_intents(hass) await cover_intent.async_setup_intents(hass)

View file

@ -1,4 +1,6 @@
"""Test reproduce state for Cover.""" """Test reproduce state for Cover."""
import pytest
from homeassistant.components.cover import ( from homeassistant.components.cover import (
ATTR_CURRENT_POSITION, ATTR_CURRENT_POSITION,
ATTR_CURRENT_TILT_POSITION, ATTR_CURRENT_TILT_POSITION,
@ -15,13 +17,15 @@ from homeassistant.const import (
STATE_CLOSED, STATE_CLOSED,
STATE_OPEN, STATE_OPEN,
) )
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 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 Cover states.""" """Test reproducing Cover states."""
hass.states.async_set("cover.entity_close", STATE_CLOSED, {}) hass.states.async_set("cover.entity_close", STATE_CLOSED, {})
hass.states.async_set( hass.states.async_set(