Add Abode MFA support (#43572)

This commit is contained in:
shred86 2020-11-27 04:39:26 -08:00 committed by GitHub
parent ea55051161
commit bdb04dcb9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 318 additions and 59 deletions

View file

@ -1,4 +1,6 @@
"""Tests for the Abode module."""
from abodepy.exceptions import AbodeAuthenticationException
from homeassistant.components.abode import (
DOMAIN as ABODE_DOMAIN,
SERVICE_CAPTURE_IMAGE,
@ -6,6 +8,7 @@ from homeassistant.components.abode import (
SERVICE_TRIGGER_AUTOMATION,
)
from homeassistant.components.alarm_control_panel import DOMAIN as ALARM_DOMAIN
from homeassistant.const import CONF_USERNAME, HTTP_BAD_REQUEST
from .common import setup_platform
@ -27,6 +30,22 @@ async def test_change_settings(hass):
mock_set_setting.assert_called_once()
async def test_add_unique_id(hass):
"""Test unique_id is set to Abode username."""
mock_entry = await setup_platform(hass, ALARM_DOMAIN)
# Set unique_id to None to match previous config entries
hass.config_entries.async_update_entry(entry=mock_entry, unique_id=None)
await hass.async_block_till_done()
assert mock_entry.unique_id is None
with patch("abodepy.UTILS"):
await hass.config_entries.async_reload(mock_entry.entry_id)
await hass.async_block_till_done()
assert mock_entry.unique_id == mock_entry.data[CONF_USERNAME]
async def test_unload_entry(hass):
"""Test unloading the Abode entry."""
mock_entry = await setup_platform(hass, ALARM_DOMAIN)
@ -41,3 +60,16 @@ async def test_unload_entry(hass):
assert not hass.services.has_service(ABODE_DOMAIN, SERVICE_SETTINGS)
assert not hass.services.has_service(ABODE_DOMAIN, SERVICE_CAPTURE_IMAGE)
assert not hass.services.has_service(ABODE_DOMAIN, SERVICE_TRIGGER_AUTOMATION)
async def test_invalid_credentials(hass):
"""Test Abode credentials changing."""
with patch(
"homeassistant.components.abode.Abode",
side_effect=AbodeAuthenticationException((HTTP_BAD_REQUEST, "auth error")),
), patch(
"homeassistant.components.abode.config_flow.AbodeFlowHandler.async_step_reauth"
) as mock_async_step_reauth:
await setup_platform(hass, ALARM_DOMAIN)
mock_async_step_reauth.assert_called_once()