core/tests/components/simplisafe/test_init.py

41 lines
1.5 KiB
Python

"""Define tests for SimpliSafe setup."""
from unittest.mock import patch
from homeassistant.components.simplisafe import DOMAIN
from homeassistant.helpers import device_registry as dr
from homeassistant.setup import async_setup_component
async def test_base_station_migration(hass, api, config, config_entry):
"""Test that errors are shown when duplicates are added."""
old_identifers = (DOMAIN, 12345)
new_identifiers = (DOMAIN, "12345")
device_registry = dr.async_get(hass)
device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
identifiers={old_identifers},
manufacturer="SimpliSafe",
name="old",
)
with patch(
"homeassistant.components.simplisafe.config_flow.API.async_from_auth",
return_value=api,
), patch(
"homeassistant.components.simplisafe.API.async_from_auth",
return_value=api,
), patch(
"homeassistant.components.simplisafe.API.async_from_refresh_token",
return_value=api,
), patch(
"homeassistant.components.simplisafe.SimpliSafe._async_start_websocket_loop"
), patch(
"homeassistant.components.simplisafe.PLATFORMS", []
):
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
assert device_registry.async_get_device(identifiers={old_identifers}) is None
assert device_registry.async_get_device(identifiers={new_identifiers}) is not None