mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Cleanup tests for lcn events and device triggers (#61719)
* Return PchkConnectionManager instance from init_integration * Removed ip and port from LCN host model identifer * Fix syntax error * Convert init_integration to a fixture * Rename device model for host * Instantiate MockPchkConnectionManager with arguments from tests * Invert logic for testing devices
This commit is contained in:
parent
615872a5d1
commit
38cb477e7b
@ -58,8 +58,11 @@ async def async_get_triggers(
|
|||||||
"""List device triggers for LCN devices."""
|
"""List device triggers for LCN devices."""
|
||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
device = device_registry.async_get(device_id)
|
device = device_registry.async_get(device_id)
|
||||||
|
if device is None:
|
||||||
|
return []
|
||||||
|
|
||||||
if device.model.startswith(("LCN host", "LCN group", "LCN resource")): # type: ignore[union-attr]
|
identifier = next(iter(device.identifiers))
|
||||||
|
if (identifier[1].count("-") != 1) or device.model.startswith("LCN group"): # type: ignore[union-attr]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
base_trigger = {
|
base_trigger = {
|
||||||
|
@ -256,7 +256,7 @@ def register_lcn_host_device(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
|||||||
identifiers={(DOMAIN, config_entry.entry_id)},
|
identifiers={(DOMAIN, config_entry.entry_id)},
|
||||||
manufacturer="Issendorff",
|
manufacturer="Issendorff",
|
||||||
name=config_entry.title,
|
name=config_entry.title,
|
||||||
model=f"LCN host ({config_entry.data[CONF_IP_ADDRESS]}:{config_entry.data[CONF_PORT]})",
|
model="LCN-PCHK",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,13 +41,6 @@ class MockGroupConnection(GroupConnection):
|
|||||||
class MockPchkConnectionManager(PchkConnectionManager):
|
class MockPchkConnectionManager(PchkConnectionManager):
|
||||||
"""Fake connection handler."""
|
"""Fake connection handler."""
|
||||||
|
|
||||||
return_value = None
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
"""Initialize MockPchkCOnnectionManager."""
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
self.__class__.return_value = self
|
|
||||||
|
|
||||||
async def async_connect(self, timeout=30):
|
async def async_connect(self, timeout=30):
|
||||||
"""Mock establishing a connection to PCHK."""
|
"""Mock establishing a connection to PCHK."""
|
||||||
self.authentication_completed_future.set_result(True)
|
self.authentication_completed_future.set_result(True)
|
||||||
@ -59,9 +52,9 @@ class MockPchkConnectionManager(PchkConnectionManager):
|
|||||||
|
|
||||||
@patch.object(pypck.connection, "ModuleConnection", MockModuleConnection)
|
@patch.object(pypck.connection, "ModuleConnection", MockModuleConnection)
|
||||||
@patch.object(pypck.connection, "GroupConnection", MockGroupConnection)
|
@patch.object(pypck.connection, "GroupConnection", MockGroupConnection)
|
||||||
def get_address_conn(self, addr):
|
def get_address_conn(self, addr, request_serials=False):
|
||||||
"""Get LCN address connection."""
|
"""Get LCN address connection."""
|
||||||
return super().get_address_conn(addr, request_serials=False)
|
return super().get_address_conn(addr, request_serials)
|
||||||
|
|
||||||
send_command = AsyncMock()
|
send_command = AsyncMock()
|
||||||
|
|
||||||
@ -102,11 +95,24 @@ def create_config_entry_myhome():
|
|||||||
return create_config_entry("myhome")
|
return create_config_entry("myhome")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(name="lcn_connection")
|
||||||
async def init_integration(hass, entry):
|
async def init_integration(hass, entry):
|
||||||
"""Set up the LCN integration in Home Assistant."""
|
"""Set up the LCN integration in Home Assistant."""
|
||||||
|
lcn_connection = None
|
||||||
|
|
||||||
|
def lcn_connection_factory(*args, **kwargs):
|
||||||
|
nonlocal lcn_connection
|
||||||
|
lcn_connection = MockPchkConnectionManager(*args, **kwargs)
|
||||||
|
return lcn_connection
|
||||||
|
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
with patch(
|
||||||
|
"pypck.connection.PchkConnectionManager",
|
||||||
|
side_effect=lcn_connection_factory,
|
||||||
|
):
|
||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
yield lcn_connection
|
||||||
|
|
||||||
|
|
||||||
async def setup_component(hass):
|
async def setup_component(hass):
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
"""Tests for LCN device triggers."""
|
"""Tests for LCN device triggers."""
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
from pypck.inputs import ModSendKeysHost, ModStatusAccessControl
|
from pypck.inputs import ModSendKeysHost, ModStatusAccessControl
|
||||||
from pypck.lcn_addr import LcnAddr
|
from pypck.lcn_addr import LcnAddr
|
||||||
from pypck.lcn_defs import AccessControlPeriphery, KeyAction, SendKeyCommand
|
from pypck.lcn_defs import AccessControlPeriphery, KeyAction, SendKeyCommand
|
||||||
@ -13,15 +11,13 @@ from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_PLATFORM, CONF
|
|||||||
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .conftest import MockPchkConnectionManager, get_device, init_integration
|
from .conftest import get_device
|
||||||
|
|
||||||
from tests.common import assert_lists_same, async_get_device_automations
|
from tests.common import assert_lists_same, async_get_device_automations
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_get_triggers_module_device(hass, entry, lcn_connection):
|
||||||
async def test_get_triggers_module_device(hass, entry):
|
|
||||||
"""Test we get the expected triggers from a LCN module device."""
|
"""Test we get the expected triggers from a LCN module device."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
device = get_device(hass, entry, (0, 7, False))
|
device = get_device(hass, entry, (0, 7, False))
|
||||||
|
|
||||||
expected_triggers = [
|
expected_triggers = [
|
||||||
@ -55,25 +51,25 @@ async def test_get_triggers_module_device(hass, entry):
|
|||||||
assert_lists_same(triggers, expected_triggers)
|
assert_lists_same(triggers, expected_triggers)
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_get_triggers_non_module_device(hass, entry, lcn_connection):
|
||||||
async def test_get_triggers_non_module_device(hass, entry):
|
|
||||||
"""Test we get the expected triggers from a LCN non-module device."""
|
"""Test we get the expected triggers from a LCN non-module device."""
|
||||||
not_included_types = ("transmitter", "transponder", "fingerprint", "send_keys")
|
not_included_types = ("transmitter", "transponder", "fingerprint", "send_keys")
|
||||||
|
|
||||||
await init_integration(hass, entry)
|
|
||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
for device_id in device_registry.devices:
|
host_device = device_registry.async_get_device({(DOMAIN, entry.entry_id)})
|
||||||
device = device_registry.async_get(device_id)
|
group_device = get_device(hass, entry, (0, 5, True))
|
||||||
if device.model.startswith(("LCN host", "LCN group", "LCN resource")):
|
resource_device = device_registry.async_get_device(
|
||||||
triggers = await async_get_device_automations(hass, "trigger", device_id)
|
{(DOMAIN, f"{entry.entry_id}-m000007-output1")}
|
||||||
|
)
|
||||||
|
|
||||||
|
for device in (host_device, group_device, resource_device):
|
||||||
|
triggers = await async_get_device_automations(hass, "trigger", device.id)
|
||||||
for trigger in triggers:
|
for trigger in triggers:
|
||||||
assert trigger[CONF_TYPE] not in not_included_types
|
assert trigger[CONF_TYPE] not in not_included_types
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_if_fires_on_transponder_event(hass, calls, entry, lcn_connection):
|
||||||
async def test_if_fires_on_transponder_event(hass, calls, entry):
|
|
||||||
"""Test for transponder event triggers firing."""
|
"""Test for transponder event triggers firing."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
address = (0, 7, False)
|
address = (0, 7, False)
|
||||||
device = get_device(hass, entry, address)
|
device = get_device(hass, entry, address)
|
||||||
|
|
||||||
@ -107,7 +103,6 @@ async def test_if_fires_on_transponder_event(hass, calls, entry):
|
|||||||
code="aabbcc",
|
code="aabbcc",
|
||||||
)
|
)
|
||||||
|
|
||||||
lcn_connection = MockPchkConnectionManager.return_value
|
|
||||||
await lcn_connection.async_process_input(inp)
|
await lcn_connection.async_process_input(inp)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -118,10 +113,8 @@ async def test_if_fires_on_transponder_event(hass, calls, entry):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_if_fires_on_fingerprint_event(hass, calls, entry, lcn_connection):
|
||||||
async def test_if_fires_on_fingerprint_event(hass, calls, entry):
|
|
||||||
"""Test for fingerprint event triggers firing."""
|
"""Test for fingerprint event triggers firing."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
address = (0, 7, False)
|
address = (0, 7, False)
|
||||||
device = get_device(hass, entry, address)
|
device = get_device(hass, entry, address)
|
||||||
|
|
||||||
@ -155,7 +148,6 @@ async def test_if_fires_on_fingerprint_event(hass, calls, entry):
|
|||||||
code="aabbcc",
|
code="aabbcc",
|
||||||
)
|
)
|
||||||
|
|
||||||
lcn_connection = MockPchkConnectionManager.return_value
|
|
||||||
await lcn_connection.async_process_input(inp)
|
await lcn_connection.async_process_input(inp)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -166,10 +158,8 @@ async def test_if_fires_on_fingerprint_event(hass, calls, entry):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_if_fires_on_transmitter_event(hass, calls, entry, lcn_connection):
|
||||||
async def test_if_fires_on_transmitter_event(hass, calls, entry):
|
|
||||||
"""Test for transmitter event triggers firing."""
|
"""Test for transmitter event triggers firing."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
address = (0, 7, False)
|
address = (0, 7, False)
|
||||||
device = get_device(hass, entry, address)
|
device = get_device(hass, entry, address)
|
||||||
|
|
||||||
@ -209,7 +199,6 @@ async def test_if_fires_on_transmitter_event(hass, calls, entry):
|
|||||||
action=KeyAction.HIT,
|
action=KeyAction.HIT,
|
||||||
)
|
)
|
||||||
|
|
||||||
lcn_connection = MockPchkConnectionManager.return_value
|
|
||||||
await lcn_connection.async_process_input(inp)
|
await lcn_connection.async_process_input(inp)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -223,10 +212,8 @@ async def test_if_fires_on_transmitter_event(hass, calls, entry):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_if_fires_on_send_keys_event(hass, calls, entry, lcn_connection):
|
||||||
async def test_if_fires_on_send_keys_event(hass, calls, entry):
|
|
||||||
"""Test for send_keys event triggers firing."""
|
"""Test for send_keys event triggers firing."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
address = (0, 7, False)
|
address = (0, 7, False)
|
||||||
device = get_device(hass, entry, address)
|
device = get_device(hass, entry, address)
|
||||||
|
|
||||||
@ -261,7 +248,6 @@ async def test_if_fires_on_send_keys_event(hass, calls, entry):
|
|||||||
keys=[True, False, False, False, False, False, False, False],
|
keys=[True, False, False, False, False, False, False, False],
|
||||||
)
|
)
|
||||||
|
|
||||||
lcn_connection = MockPchkConnectionManager.return_value
|
|
||||||
await lcn_connection.async_process_input(inp)
|
await lcn_connection.async_process_input(inp)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -273,10 +259,8 @@ async def test_if_fires_on_send_keys_event(hass, calls, entry):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_get_transponder_trigger_capabilities(hass, entry, lcn_connection):
|
||||||
async def test_get_transponder_trigger_capabilities(hass, entry):
|
|
||||||
"""Test we get the expected capabilities from a transponder device trigger."""
|
"""Test we get the expected capabilities from a transponder device trigger."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
address = (0, 7, False)
|
address = (0, 7, False)
|
||||||
device = get_device(hass, entry, address)
|
device = get_device(hass, entry, address)
|
||||||
|
|
||||||
@ -296,10 +280,8 @@ async def test_get_transponder_trigger_capabilities(hass, entry):
|
|||||||
) == [{"name": "code", "optional": True, "type": "string", "lower": True}]
|
) == [{"name": "code", "optional": True, "type": "string", "lower": True}]
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_get_fingerprint_trigger_capabilities(hass, entry, lcn_connection):
|
||||||
async def test_get_fingerprint_trigger_capabilities(hass, entry):
|
|
||||||
"""Test we get the expected capabilities from a fingerprint device trigger."""
|
"""Test we get the expected capabilities from a fingerprint device trigger."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
address = (0, 7, False)
|
address = (0, 7, False)
|
||||||
device = get_device(hass, entry, address)
|
device = get_device(hass, entry, address)
|
||||||
|
|
||||||
@ -319,10 +301,8 @@ async def test_get_fingerprint_trigger_capabilities(hass, entry):
|
|||||||
) == [{"name": "code", "optional": True, "type": "string", "lower": True}]
|
) == [{"name": "code", "optional": True, "type": "string", "lower": True}]
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_get_transmitter_trigger_capabilities(hass, entry, lcn_connection):
|
||||||
async def test_get_transmitter_trigger_capabilities(hass, entry):
|
|
||||||
"""Test we get the expected capabilities from a transmitter device trigger."""
|
"""Test we get the expected capabilities from a transmitter device trigger."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
address = (0, 7, False)
|
address = (0, 7, False)
|
||||||
device = get_device(hass, entry, address)
|
device = get_device(hass, entry, address)
|
||||||
|
|
||||||
@ -352,10 +332,8 @@ async def test_get_transmitter_trigger_capabilities(hass, entry):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_get_send_keys_trigger_capabilities(hass, entry, lcn_connection):
|
||||||
async def test_get_send_keys_trigger_capabilities(hass, entry):
|
|
||||||
"""Test we get the expected capabilities from a send_keys device trigger."""
|
"""Test we get the expected capabilities from a send_keys device trigger."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
address = (0, 7, False)
|
address = (0, 7, False)
|
||||||
device = get_device(hass, entry, address)
|
device = get_device(hass, entry, address)
|
||||||
|
|
||||||
@ -390,10 +368,8 @@ async def test_get_send_keys_trigger_capabilities(hass, entry):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_unknown_trigger_capabilities(hass, entry, lcn_connection):
|
||||||
async def test_unknown_trigger_capabilities(hass, entry):
|
|
||||||
"""Test we get empty capabilities if trigger is unknown."""
|
"""Test we get empty capabilities if trigger is unknown."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
address = (0, 7, False)
|
address = (0, 7, False)
|
||||||
device = get_device(hass, entry, address)
|
device = get_device(hass, entry, address)
|
||||||
|
|
||||||
|
@ -1,20 +1,13 @@
|
|||||||
"""Tests for LCN events."""
|
"""Tests for LCN events."""
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
from pypck.inputs import Input, ModSendKeysHost, ModStatusAccessControl
|
from pypck.inputs import Input, ModSendKeysHost, ModStatusAccessControl
|
||||||
from pypck.lcn_addr import LcnAddr
|
from pypck.lcn_addr import LcnAddr
|
||||||
from pypck.lcn_defs import AccessControlPeriphery, KeyAction, SendKeyCommand
|
from pypck.lcn_defs import AccessControlPeriphery, KeyAction, SendKeyCommand
|
||||||
|
|
||||||
from .conftest import MockPchkConnectionManager, init_integration
|
|
||||||
|
|
||||||
from tests.common import async_capture_events
|
from tests.common import async_capture_events
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_fire_transponder_event(hass, lcn_connection):
|
||||||
async def test_fire_transponder_event(hass, entry):
|
|
||||||
"""Test the transponder event is fired."""
|
"""Test the transponder event is fired."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
|
|
||||||
events = async_capture_events(hass, "lcn_transponder")
|
events = async_capture_events(hass, "lcn_transponder")
|
||||||
|
|
||||||
inp = ModStatusAccessControl(
|
inp = ModStatusAccessControl(
|
||||||
@ -23,7 +16,6 @@ async def test_fire_transponder_event(hass, entry):
|
|||||||
code="aabbcc",
|
code="aabbcc",
|
||||||
)
|
)
|
||||||
|
|
||||||
lcn_connection = MockPchkConnectionManager.return_value
|
|
||||||
await lcn_connection.async_process_input(inp)
|
await lcn_connection.async_process_input(inp)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -32,11 +24,8 @@ async def test_fire_transponder_event(hass, entry):
|
|||||||
assert events[0].data["code"] == "aabbcc"
|
assert events[0].data["code"] == "aabbcc"
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_fire_fingerprint_event(hass, lcn_connection):
|
||||||
async def test_fire_fingerprint_event(hass, entry):
|
|
||||||
"""Test the fingerprint event is fired."""
|
"""Test the fingerprint event is fired."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
|
|
||||||
events = async_capture_events(hass, "lcn_fingerprint")
|
events = async_capture_events(hass, "lcn_fingerprint")
|
||||||
|
|
||||||
inp = ModStatusAccessControl(
|
inp = ModStatusAccessControl(
|
||||||
@ -45,7 +34,6 @@ async def test_fire_fingerprint_event(hass, entry):
|
|||||||
code="aabbcc",
|
code="aabbcc",
|
||||||
)
|
)
|
||||||
|
|
||||||
lcn_connection = MockPchkConnectionManager.return_value
|
|
||||||
await lcn_connection.async_process_input(inp)
|
await lcn_connection.async_process_input(inp)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -54,11 +42,8 @@ async def test_fire_fingerprint_event(hass, entry):
|
|||||||
assert events[0].data["code"] == "aabbcc"
|
assert events[0].data["code"] == "aabbcc"
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_fire_transmitter_event(hass, lcn_connection):
|
||||||
async def test_fire_transmitter_event(hass, entry):
|
|
||||||
"""Test the transmitter event is fired."""
|
"""Test the transmitter event is fired."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
|
|
||||||
events = async_capture_events(hass, "lcn_transmitter")
|
events = async_capture_events(hass, "lcn_transmitter")
|
||||||
|
|
||||||
inp = ModStatusAccessControl(
|
inp = ModStatusAccessControl(
|
||||||
@ -70,7 +55,6 @@ async def test_fire_transmitter_event(hass, entry):
|
|||||||
action=KeyAction.HIT,
|
action=KeyAction.HIT,
|
||||||
)
|
)
|
||||||
|
|
||||||
lcn_connection = MockPchkConnectionManager.return_value
|
|
||||||
await lcn_connection.async_process_input(inp)
|
await lcn_connection.async_process_input(inp)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -82,11 +66,8 @@ async def test_fire_transmitter_event(hass, entry):
|
|||||||
assert events[0].data["action"] == "hit"
|
assert events[0].data["action"] == "hit"
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_fire_sendkeys_event(hass, lcn_connection):
|
||||||
async def test_fire_sendkeys_event(hass, entry):
|
|
||||||
"""Test the send_keys event is fired."""
|
"""Test the send_keys event is fired."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
|
|
||||||
events = async_capture_events(hass, "lcn_send_keys")
|
events = async_capture_events(hass, "lcn_send_keys")
|
||||||
|
|
||||||
inp = ModSendKeysHost(
|
inp = ModSendKeysHost(
|
||||||
@ -95,7 +76,6 @@ async def test_fire_sendkeys_event(hass, entry):
|
|||||||
keys=[True, True, False, False, False, False, False, False],
|
keys=[True, True, False, False, False, False, False, False],
|
||||||
)
|
)
|
||||||
|
|
||||||
lcn_connection = MockPchkConnectionManager.return_value
|
|
||||||
await lcn_connection.async_process_input(inp)
|
await lcn_connection.async_process_input(inp)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -114,13 +94,9 @@ async def test_fire_sendkeys_event(hass, entry):
|
|||||||
assert events[3].data["action"] == "make"
|
assert events[3].data["action"] == "make"
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_dont_fire_on_non_module_input(hass, lcn_connection):
|
||||||
async def test_dont_fire_on_non_module_input(hass, entry):
|
|
||||||
"""Test for no event is fired if a non-module input is received."""
|
"""Test for no event is fired if a non-module input is received."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
|
|
||||||
inp = Input()
|
inp = Input()
|
||||||
lcn_connection = MockPchkConnectionManager.return_value
|
|
||||||
|
|
||||||
for event_name in (
|
for event_name in (
|
||||||
"lcn_transponder",
|
"lcn_transponder",
|
||||||
@ -134,20 +110,15 @@ async def test_dont_fire_on_non_module_input(hass, entry):
|
|||||||
assert len(events) == 0
|
assert len(events) == 0
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_dont_fire_on_unknown_module(hass, lcn_connection):
|
||||||
async def test_dont_fire_on_unknown_module(hass, entry):
|
|
||||||
"""Test for no event is fired if an input from an unknown module is received."""
|
"""Test for no event is fired if an input from an unknown module is received."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
|
|
||||||
inp = ModStatusAccessControl(
|
inp = ModStatusAccessControl(
|
||||||
LcnAddr(0, 10, False), # unknown module
|
LcnAddr(0, 10, False), # unknown module
|
||||||
periphery=AccessControlPeriphery.FINGERPRINT,
|
periphery=AccessControlPeriphery.FINGERPRINT,
|
||||||
code="aabbcc",
|
code="aabbcc",
|
||||||
)
|
)
|
||||||
|
|
||||||
lcn_connection = MockPchkConnectionManager.return_value
|
events = async_capture_events(hass, "lcn_fingerprint")
|
||||||
|
|
||||||
events = async_capture_events(hass, "lcn_transmitter")
|
|
||||||
await lcn_connection.async_process_input(inp)
|
await lcn_connection.async_process_input(inp)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(events) == 0
|
assert len(events) == 0
|
||||||
|
@ -12,14 +12,11 @@ from homeassistant.components.lcn.const import DOMAIN
|
|||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
|
|
||||||
from .conftest import MockPchkConnectionManager, init_integration, setup_component
|
from .conftest import MockPchkConnectionManager, setup_component
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
async def test_async_setup_entry(hass, entry, lcn_connection):
|
||||||
async def test_async_setup_entry(hass, entry):
|
|
||||||
"""Test a successful setup entry and unload of entry."""
|
"""Test a successful setup entry and unload of entry."""
|
||||||
await init_integration(hass, entry)
|
|
||||||
|
|
||||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||||
assert entry.state == ConfigEntryState.LOADED
|
assert entry.state == ConfigEntryState.LOADED
|
||||||
|
|
||||||
@ -30,13 +27,14 @@ async def test_async_setup_entry(hass, entry):
|
|||||||
assert not hass.data.get(DOMAIN)
|
assert not hass.data.get(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
|
||||||
async def test_async_setup_multiple_entries(hass, entry, entry2):
|
async def test_async_setup_multiple_entries(hass, entry, entry2):
|
||||||
"""Test a successful setup and unload of multiple entries."""
|
"""Test a successful setup and unload of multiple entries."""
|
||||||
|
with patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager):
|
||||||
for config_entry in (entry, entry2):
|
for config_entry in (entry, entry2):
|
||||||
await init_integration(hass, config_entry)
|
config_entry.add_to_hass(hass)
|
||||||
assert config_entry.state == ConfigEntryState.LOADED
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
assert config_entry.state == ConfigEntryState.LOADED
|
||||||
|
|
||||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 2
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 2
|
||||||
|
|
||||||
@ -49,7 +47,6 @@ async def test_async_setup_multiple_entries(hass, entry, entry2):
|
|||||||
assert not hass.data.get(DOMAIN)
|
assert not hass.data.get(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
|
||||||
async def test_async_setup_entry_update(hass, entry):
|
async def test_async_setup_entry_update(hass, entry):
|
||||||
"""Test a successful setup entry if entry with same id already exists."""
|
"""Test a successful setup entry if entry with same id already exists."""
|
||||||
# setup first entry
|
# setup first entry
|
||||||
@ -74,6 +71,7 @@ async def test_async_setup_entry_update(hass, entry):
|
|||||||
assert dummy_device in device_registry.devices.values()
|
assert dummy_device in device_registry.devices.values()
|
||||||
|
|
||||||
# setup new entry with same data via import step (should cleanup dummy device)
|
# setup new entry with same data via import step (should cleanup dummy device)
|
||||||
|
with patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager):
|
||||||
await hass.config_entries.flow.async_init(
|
await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=entry.data
|
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=entry.data
|
||||||
)
|
)
|
||||||
@ -87,7 +85,10 @@ async def test_async_setup_entry_raises_authentication_error(hass, entry):
|
|||||||
with patch.object(
|
with patch.object(
|
||||||
PchkConnectionManager, "async_connect", side_effect=PchkAuthenticationError
|
PchkConnectionManager, "async_connect", side_effect=PchkAuthenticationError
|
||||||
):
|
):
|
||||||
await init_integration(hass, entry)
|
entry.add_to_hass(hass)
|
||||||
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert entry.state == ConfigEntryState.SETUP_ERROR
|
assert entry.state == ConfigEntryState.SETUP_ERROR
|
||||||
|
|
||||||
|
|
||||||
@ -96,22 +97,28 @@ async def test_async_setup_entry_raises_license_error(hass, entry):
|
|||||||
with patch.object(
|
with patch.object(
|
||||||
PchkConnectionManager, "async_connect", side_effect=PchkLicenseError
|
PchkConnectionManager, "async_connect", side_effect=PchkLicenseError
|
||||||
):
|
):
|
||||||
await init_integration(hass, entry)
|
entry.add_to_hass(hass)
|
||||||
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert entry.state == ConfigEntryState.SETUP_ERROR
|
assert entry.state == ConfigEntryState.SETUP_ERROR
|
||||||
|
|
||||||
|
|
||||||
async def test_async_setup_entry_raises_timeout_error(hass, entry):
|
async def test_async_setup_entry_raises_timeout_error(hass, entry):
|
||||||
"""Test that an authentication error is handled properly."""
|
"""Test that an authentication error is handled properly."""
|
||||||
with patch.object(PchkConnectionManager, "async_connect", side_effect=TimeoutError):
|
with patch.object(PchkConnectionManager, "async_connect", side_effect=TimeoutError):
|
||||||
await init_integration(hass, entry)
|
entry.add_to_hass(hass)
|
||||||
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert entry.state == ConfigEntryState.SETUP_ERROR
|
assert entry.state == ConfigEntryState.SETUP_ERROR
|
||||||
|
|
||||||
|
|
||||||
@patch("pypck.connection.PchkConnectionManager", MockPchkConnectionManager)
|
|
||||||
async def test_async_setup_from_configuration_yaml(hass):
|
async def test_async_setup_from_configuration_yaml(hass):
|
||||||
"""Test a successful setup using data from configuration.yaml."""
|
"""Test a successful setup using data from configuration.yaml."""
|
||||||
|
with patch(
|
||||||
with patch("homeassistant.components.lcn.async_setup_entry") as async_setup_entry:
|
"pypck.connection.PchkConnectionManager", MockPchkConnectionManager
|
||||||
|
), patch("homeassistant.components.lcn.async_setup_entry") as async_setup_entry:
|
||||||
await setup_component(hass)
|
await setup_component(hass)
|
||||||
|
|
||||||
assert async_setup_entry.await_count == 2
|
assert async_setup_entry.await_count == 2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user