2021-01-10 23:08:25 +00:00
|
|
|
"""Provide common Z-Wave JS fixtures."""
|
|
|
|
import json
|
2021-01-11 15:05:11 +00:00
|
|
|
from unittest.mock import DEFAULT, patch
|
2021-01-10 23:08:25 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
from zwave_js_server.model.driver import Driver
|
|
|
|
from zwave_js_server.model.node import Node
|
|
|
|
|
2021-01-11 15:05:11 +00:00
|
|
|
from homeassistant.helpers.device_registry import (
|
|
|
|
async_get_registry as async_get_device_registry,
|
|
|
|
)
|
|
|
|
|
2021-01-10 23:08:25 +00:00
|
|
|
from tests.common import MockConfigEntry, load_fixture
|
|
|
|
|
|
|
|
|
2021-01-11 15:05:11 +00:00
|
|
|
@pytest.fixture(name="device_registry")
|
|
|
|
async def device_registry_fixture(hass):
|
|
|
|
"""Return the device registry."""
|
|
|
|
return await async_get_device_registry(hass)
|
|
|
|
|
|
|
|
|
2021-01-10 23:08:25 +00:00
|
|
|
@pytest.fixture(name="controller_state", scope="session")
|
|
|
|
def controller_state_fixture():
|
|
|
|
"""Load the controller state fixture data."""
|
|
|
|
return json.loads(load_fixture("zwave_js/controller_state.json"))
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="multisensor_6_state", scope="session")
|
|
|
|
def multisensor_6_state_fixture():
|
|
|
|
"""Load the multisensor 6 node state fixture data."""
|
|
|
|
return json.loads(load_fixture("zwave_js/multisensor_6_state.json"))
|
|
|
|
|
|
|
|
|
2021-01-11 23:40:39 +00:00
|
|
|
@pytest.fixture(name="hank_binary_switch_state", scope="session")
|
|
|
|
def binary_switch_state_fixture():
|
|
|
|
"""Load the hank binary switch node state fixture data."""
|
|
|
|
return json.loads(load_fixture("zwave_js/hank_binary_switch_state.json"))
|
|
|
|
|
|
|
|
|
2021-01-10 23:08:25 +00:00
|
|
|
@pytest.fixture(name="client")
|
|
|
|
def mock_client_fixture(controller_state):
|
|
|
|
"""Mock a client."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.zwave_js.ZwaveClient", autospec=True
|
|
|
|
) as client_class:
|
|
|
|
driver = Driver(client_class.return_value, controller_state)
|
|
|
|
client_class.return_value.driver = driver
|
|
|
|
yield client_class.return_value
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="multisensor_6")
|
|
|
|
def multisensor_6_fixture(client, multisensor_6_state):
|
|
|
|
"""Mock a multisensor 6 node."""
|
|
|
|
node = Node(client, multisensor_6_state)
|
|
|
|
client.driver.controller.nodes[node.node_id] = node
|
|
|
|
return node
|
|
|
|
|
|
|
|
|
2021-01-11 23:40:39 +00:00
|
|
|
@pytest.fixture(name="hank_binary_switch")
|
|
|
|
def hank_binary_switch_fixture(client, hank_binary_switch_state):
|
|
|
|
"""Mock a binary switch node."""
|
|
|
|
node = Node(client, hank_binary_switch_state)
|
|
|
|
client.driver.controller.nodes[node.node_id] = node
|
|
|
|
return node
|
|
|
|
|
|
|
|
|
2021-01-10 23:08:25 +00:00
|
|
|
@pytest.fixture(name="integration")
|
|
|
|
async def integration_fixture(hass, client):
|
|
|
|
"""Set up the zwave_js integration."""
|
|
|
|
entry = MockConfigEntry(domain="zwave_js", data={"url": "ws://test.org"})
|
|
|
|
entry.add_to_hass(hass)
|
|
|
|
|
|
|
|
def initialize_client(async_on_initialized):
|
|
|
|
"""Init the client."""
|
|
|
|
hass.async_create_task(async_on_initialized())
|
2021-01-11 15:05:11 +00:00
|
|
|
return DEFAULT
|
2021-01-10 23:08:25 +00:00
|
|
|
|
|
|
|
client.register_on_initialized.side_effect = initialize_client
|
|
|
|
|
|
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
return entry
|