Support for local push in Risco integration (#75874)
* Local config flow * Local entities * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Address code review comments * More type hints * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * More annotations * Even more annonations * New entity naming * Move fixtures to conftest * Improve state tests for local * Remove mutable default arguments * Remove assertions for lack of state * Add missing file * Switch setup to fixtures * Use error fixtures in test_config_flow * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
2497ff5a39
commit
635eda584d
16 changed files with 1596 additions and 480 deletions
148
tests/components/risco/conftest.py
Normal file
148
tests/components/risco/conftest.py
Normal file
|
@ -0,0 +1,148 @@
|
|||
"""Fixtures for Risco tests."""
|
||||
from unittest.mock import MagicMock, PropertyMock, patch
|
||||
|
||||
from pytest import fixture
|
||||
|
||||
from homeassistant.components.risco.const import DOMAIN, TYPE_LOCAL
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_PASSWORD,
|
||||
CONF_PIN,
|
||||
CONF_PORT,
|
||||
CONF_TYPE,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
|
||||
from .util import TEST_SITE_NAME, TEST_SITE_UUID, zone_mock
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
TEST_CLOUD_CONFIG = {
|
||||
CONF_USERNAME: "test-username",
|
||||
CONF_PASSWORD: "test-password",
|
||||
CONF_PIN: "1234",
|
||||
}
|
||||
TEST_LOCAL_CONFIG = {
|
||||
CONF_TYPE: TYPE_LOCAL,
|
||||
CONF_HOST: "test-host",
|
||||
CONF_PORT: 5004,
|
||||
CONF_PIN: "1234",
|
||||
}
|
||||
|
||||
|
||||
@fixture
|
||||
def two_zone_cloud():
|
||||
"""Fixture to mock alarm with two zones."""
|
||||
zone_mocks = {0: zone_mock(), 1: zone_mock()}
|
||||
alarm_mock = MagicMock()
|
||||
with patch.object(
|
||||
zone_mocks[0], "id", new_callable=PropertyMock(return_value=0)
|
||||
), patch.object(
|
||||
zone_mocks[0], "name", new_callable=PropertyMock(return_value="Zone 0")
|
||||
), patch.object(
|
||||
zone_mocks[1], "id", new_callable=PropertyMock(return_value=1)
|
||||
), patch.object(
|
||||
zone_mocks[1], "name", new_callable=PropertyMock(return_value="Zone 1")
|
||||
), patch.object(
|
||||
alarm_mock,
|
||||
"zones",
|
||||
new_callable=PropertyMock(return_value=zone_mocks),
|
||||
), patch(
|
||||
"homeassistant.components.risco.RiscoCloud.get_state",
|
||||
return_value=alarm_mock,
|
||||
):
|
||||
yield zone_mocks
|
||||
|
||||
|
||||
@fixture
|
||||
def options():
|
||||
"""Fixture for default (empty) options."""
|
||||
return {}
|
||||
|
||||
|
||||
@fixture
|
||||
def events():
|
||||
"""Fixture for default (empty) events."""
|
||||
return []
|
||||
|
||||
|
||||
@fixture
|
||||
def cloud_config_entry(hass, options):
|
||||
"""Fixture for a cloud config entry."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN, data=TEST_CLOUD_CONFIG, options=options
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
return config_entry
|
||||
|
||||
|
||||
@fixture
|
||||
def login_with_error(exception):
|
||||
"""Fixture to simulate error on login."""
|
||||
with patch(
|
||||
"homeassistant.components.risco.RiscoCloud.login",
|
||||
side_effect=exception,
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@fixture
|
||||
async def setup_risco_cloud(hass, cloud_config_entry, events):
|
||||
"""Set up a Risco integration for testing."""
|
||||
with patch(
|
||||
"homeassistant.components.risco.RiscoCloud.login",
|
||||
return_value=True,
|
||||
), patch(
|
||||
"homeassistant.components.risco.RiscoCloud.site_uuid",
|
||||
new_callable=PropertyMock(return_value=TEST_SITE_UUID),
|
||||
), patch(
|
||||
"homeassistant.components.risco.RiscoCloud.site_name",
|
||||
new_callable=PropertyMock(return_value=TEST_SITE_NAME),
|
||||
), patch(
|
||||
"homeassistant.components.risco.RiscoCloud.close"
|
||||
), patch(
|
||||
"homeassistant.components.risco.RiscoCloud.get_events",
|
||||
return_value=events,
|
||||
):
|
||||
await hass.config_entries.async_setup(cloud_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
yield cloud_config_entry
|
||||
|
||||
|
||||
@fixture
|
||||
def local_config_entry(hass, options):
|
||||
"""Fixture for a local config entry."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN, data=TEST_LOCAL_CONFIG, options=options
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
return config_entry
|
||||
|
||||
|
||||
@fixture
|
||||
def connect_with_error(exception):
|
||||
"""Fixture to simulate error on connect."""
|
||||
with patch(
|
||||
"homeassistant.components.risco.RiscoLocal.connect",
|
||||
side_effect=exception,
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@fixture
|
||||
async def setup_risco_local(hass, local_config_entry):
|
||||
"""Set up a local Risco integration for testing."""
|
||||
with patch(
|
||||
"homeassistant.components.risco.RiscoLocal.connect",
|
||||
return_value=True,
|
||||
), patch(
|
||||
"homeassistant.components.risco.RiscoLocal.id",
|
||||
new_callable=PropertyMock(return_value=TEST_SITE_UUID),
|
||||
), patch(
|
||||
"homeassistant.components.risco.RiscoLocal.disconnect"
|
||||
):
|
||||
await hass.config_entries.async_setup(local_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
yield local_config_entry
|
Loading…
Add table
Add a link
Reference in a new issue