Make type checking pass for deCONZ init, gateway and services (#66054)

* Type and enable type checking for init, config_flow, diagnostics, gateway and services

* Fix import

* Fix review comment
This commit is contained in:
Robert Svensson 2022-02-23 13:10:35 +01:00 committed by GitHub
parent 3afadf8adb
commit dd88a05cb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 180 additions and 150 deletions

View file

@ -1,6 +1,5 @@
"""Test deCONZ component setup process."""
import asyncio
from unittest.mock import patch
from homeassistant.components.deconz import (
@ -13,6 +12,7 @@ from homeassistant.components.deconz.const import (
CONF_GROUP_ID_BASE,
DOMAIN as DECONZ_DOMAIN,
)
from homeassistant.components.deconz.errors import AuthenticationRequired, CannotConnect
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT
from homeassistant.helpers import entity_registry as er
@ -42,22 +42,6 @@ async def setup_entry(hass, entry):
assert await async_setup_entry(hass, entry) is True
async def test_setup_entry_fails(hass):
"""Test setup entry fails if deCONZ is not available."""
with patch("pydeconz.DeconzSession.refresh_state", side_effect=Exception):
await setup_deconz_integration(hass)
assert not hass.data[DECONZ_DOMAIN]
async def test_setup_entry_no_available_bridge(hass):
"""Test setup entry fails if deCONZ is not available."""
with patch(
"pydeconz.DeconzSession.refresh_state", side_effect=asyncio.TimeoutError
):
await setup_deconz_integration(hass)
assert not hass.data[DECONZ_DOMAIN]
async def test_setup_entry_successful(hass, aioclient_mock):
"""Test setup entry is successful."""
config_entry = await setup_deconz_integration(hass, aioclient_mock)
@ -67,6 +51,29 @@ async def test_setup_entry_successful(hass, aioclient_mock):
assert hass.data[DECONZ_DOMAIN][config_entry.entry_id].master
async def test_setup_entry_fails_config_entry_not_ready(hass):
"""Failed authentication trigger a reauthentication flow."""
with patch(
"homeassistant.components.deconz.get_deconz_session",
side_effect=CannotConnect,
):
await setup_deconz_integration(hass)
assert hass.data[DECONZ_DOMAIN] == {}
async def test_setup_entry_fails_trigger_reauth_flow(hass):
"""Failed authentication trigger a reauthentication flow."""
with patch(
"homeassistant.components.deconz.get_deconz_session",
side_effect=AuthenticationRequired,
), patch.object(hass.config_entries.flow, "async_init") as mock_flow_init:
await setup_deconz_integration(hass)
mock_flow_init.assert_called_once()
assert hass.data[DECONZ_DOMAIN] == {}
async def test_setup_entry_multiple_gateways(hass, aioclient_mock):
"""Test setup entry is successful with multiple gateways."""
config_entry = await setup_deconz_integration(hass, aioclient_mock)