Add Schlage integration (#93777)
Co-authored-by: J. Nick Koston <nick@koston.org> Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
This commit is contained in:
parent
7d8462b11c
commit
b31cfe0b24
17 changed files with 550 additions and 0 deletions
61
tests/components/schlage/test_init.py
Normal file
61
tests/components/schlage/test_init.py
Normal file
|
@ -0,0 +1,61 @@
|
|||
"""Tests for the Schlage integration."""
|
||||
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from pycognito.exceptions import WarrantException
|
||||
from pyschlage.exceptions import Error
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@patch(
|
||||
"pyschlage.Auth",
|
||||
side_effect=WarrantException,
|
||||
)
|
||||
async def test_auth_failed(
|
||||
mock_auth: Mock, hass: HomeAssistant, mock_config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test failed auth on setup."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_auth.call_count == 1
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR
|
||||
|
||||
|
||||
async def test_update_data_fails(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_pyschlage_auth: Mock,
|
||||
mock_schlage: Mock,
|
||||
) -> None:
|
||||
"""Test that we properly handle API errors."""
|
||||
mock_schlage.locks.side_effect = Error
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_schlage.locks.call_count == 1
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_load_unload_config_entry(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_pyschlage_auth: Mock,
|
||||
mock_schlage: Mock,
|
||||
) -> None:
|
||||
"""Test the Schlage configuration entry loading/unloading."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
Loading…
Add table
Add a link
Reference in a new issue