2021-01-10 23:08:25 +00:00
|
|
|
"""Provide common Z-Wave JS fixtures."""
|
|
|
|
import json
|
2021-01-25 12:12:58 +00:00
|
|
|
from unittest.mock import DEFAULT, Mock, patch
|
2021-01-10 23:08:25 +00:00
|
|
|
|
|
|
|
import pytest
|
2021-01-18 15:08:52 +00:00
|
|
|
from zwave_js_server.event import Event
|
2021-01-10 23:08:25 +00:00
|
|
|
from zwave_js_server.model.driver import Driver
|
|
|
|
from zwave_js_server.model.node import Node
|
2021-01-15 14:17:40 +00:00
|
|
|
from zwave_js_server.version import VersionInfo
|
2021-01-10 23:08:25 +00:00
|
|
|
|
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-27 07:56:16 +00:00
|
|
|
@pytest.fixture(name="discovery_info")
|
|
|
|
def discovery_info_fixture():
|
|
|
|
"""Return the discovery info from the supervisor."""
|
|
|
|
return DEFAULT
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="discovery_info_side_effect")
|
|
|
|
def discovery_info_side_effect_fixture():
|
|
|
|
"""Return the discovery info from the supervisor."""
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="get_addon_discovery_info")
|
|
|
|
def mock_get_addon_discovery_info(discovery_info, discovery_info_side_effect):
|
|
|
|
"""Mock get add-on discovery info."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.hassio.async_get_addon_discovery_info",
|
|
|
|
side_effect=discovery_info_side_effect,
|
|
|
|
return_value=discovery_info,
|
|
|
|
) as get_addon_discovery_info:
|
|
|
|
yield get_addon_discovery_info
|
|
|
|
|
|
|
|
|
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"))
|
|
|
|
|
|
|
|
|
2021-01-15 14:17:40 +00:00
|
|
|
@pytest.fixture(name="version_state", scope="session")
|
|
|
|
def version_state_fixture():
|
|
|
|
"""Load the version state fixture data."""
|
|
|
|
return {
|
|
|
|
"type": "version",
|
|
|
|
"driverVersion": "6.0.0-beta.0",
|
|
|
|
"serverVersion": "1.0.0",
|
|
|
|
"homeId": 1234567890,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-10 23:08:25 +00:00
|
|
|
@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-15 14:15:03 +00:00
|
|
|
@pytest.fixture(name="ecolink_door_sensor_state", scope="session")
|
|
|
|
def ecolink_door_sensor_state_fixture():
|
|
|
|
"""Load the Ecolink Door/Window Sensor node state fixture data."""
|
|
|
|
return json.loads(load_fixture("zwave_js/ecolink_door_sensor_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-13 15:28:51 +00:00
|
|
|
@pytest.fixture(name="bulb_6_multi_color_state", scope="session")
|
|
|
|
def bulb_6_multi_color_state_fixture():
|
|
|
|
"""Load the bulb 6 multi-color node state fixture data."""
|
|
|
|
return json.loads(load_fixture("zwave_js/bulb_6_multi_color_state.json"))
|
|
|
|
|
|
|
|
|
2021-01-25 21:09:12 +00:00
|
|
|
@pytest.fixture(name="eaton_rf9640_dimmer_state", scope="session")
|
|
|
|
def eaton_rf9640_dimmer_state_fixture():
|
|
|
|
"""Load the bulb 6 multi-color node state fixture data."""
|
|
|
|
return json.loads(load_fixture("zwave_js/eaton_rf9640_dimmer_state.json"))
|
|
|
|
|
|
|
|
|
2021-01-16 16:43:25 +00:00
|
|
|
@pytest.fixture(name="lock_schlage_be469_state", scope="session")
|
|
|
|
def lock_schlage_be469_state_fixture():
|
|
|
|
"""Load the schlage lock node state fixture data."""
|
|
|
|
return json.loads(load_fixture("zwave_js/lock_schlage_be469_state.json"))
|
|
|
|
|
|
|
|
|
2021-01-25 14:50:21 +00:00
|
|
|
@pytest.fixture(name="lock_august_asl03_state", scope="session")
|
|
|
|
def lock_august_asl03_state_fixture():
|
|
|
|
"""Load the August Pro lock node state fixture data."""
|
|
|
|
return json.loads(load_fixture("zwave_js/lock_august_asl03_state.json"))
|
|
|
|
|
|
|
|
|
2021-01-18 02:45:06 +00:00
|
|
|
@pytest.fixture(name="climate_radio_thermostat_ct100_plus_state", scope="session")
|
|
|
|
def climate_radio_thermostat_ct100_plus_state_fixture():
|
|
|
|
"""Load the climate radio thermostat ct100 plus node state fixture data."""
|
|
|
|
return json.loads(
|
|
|
|
load_fixture("zwave_js/climate_radio_thermostat_ct100_plus_state.json")
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-02-01 19:46:06 +00:00
|
|
|
@pytest.fixture(
|
|
|
|
name="climate_radio_thermostat_ct100_plus_different_endpoints_state",
|
|
|
|
scope="session",
|
|
|
|
)
|
|
|
|
def climate_radio_thermostat_ct100_plus_different_endpoints_state_fixture():
|
|
|
|
"""Load the thermostat fixture state with values on different endpoints.
|
|
|
|
|
|
|
|
This device is a radio thermostat ct100.
|
|
|
|
"""
|
|
|
|
return json.loads(
|
|
|
|
load_fixture(
|
|
|
|
"zwave_js/climate_radio_thermostat_ct100_plus_different_endpoints_state.json"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-01-18 15:08:52 +00:00
|
|
|
@pytest.fixture(name="nortek_thermostat_state", scope="session")
|
|
|
|
def nortek_thermostat_state_fixture():
|
|
|
|
"""Load the nortek thermostat node state fixture data."""
|
|
|
|
return json.loads(load_fixture("zwave_js/nortek_thermostat_state.json"))
|
|
|
|
|
|
|
|
|
2021-01-22 16:51:39 +00:00
|
|
|
@pytest.fixture(name="chain_actuator_zws12_state", scope="session")
|
|
|
|
def window_cover_state_fixture():
|
|
|
|
"""Load the window cover node state fixture data."""
|
|
|
|
return json.loads(load_fixture("zwave_js/chain_actuator_zws12_state.json"))
|
|
|
|
|
|
|
|
|
2021-01-22 23:11:32 +00:00
|
|
|
@pytest.fixture(name="in_wall_smart_fan_control_state", scope="session")
|
|
|
|
def in_wall_smart_fan_control_state_fixture():
|
|
|
|
"""Load the fan node state fixture data."""
|
|
|
|
return json.loads(load_fixture("zwave_js/in_wall_smart_fan_control_state.json"))
|
|
|
|
|
|
|
|
|
2021-01-10 23:08:25 +00:00
|
|
|
@pytest.fixture(name="client")
|
2021-01-15 14:17:40 +00:00
|
|
|
def mock_client_fixture(controller_state, version_state):
|
2021-01-10 23:08:25 +00:00
|
|
|
"""Mock a client."""
|
2021-01-25 12:12:58 +00:00
|
|
|
|
|
|
|
def mock_callback():
|
|
|
|
callbacks = []
|
|
|
|
|
|
|
|
def add_callback(cb):
|
|
|
|
callbacks.append(cb)
|
|
|
|
return DEFAULT
|
|
|
|
|
|
|
|
return callbacks, Mock(side_effect=add_callback)
|
|
|
|
|
2021-01-10 23:08:25 +00:00
|
|
|
with patch(
|
|
|
|
"homeassistant.components.zwave_js.ZwaveClient", autospec=True
|
|
|
|
) as client_class:
|
2021-01-25 12:12:58 +00:00
|
|
|
client = client_class.return_value
|
|
|
|
|
|
|
|
connect_callback, client.register_on_connect = mock_callback()
|
|
|
|
initialized_callback, client.register_on_initialized = mock_callback()
|
|
|
|
|
|
|
|
async def connect():
|
|
|
|
for cb in connect_callback:
|
|
|
|
await cb()
|
|
|
|
|
|
|
|
for cb in initialized_callback:
|
|
|
|
await cb()
|
|
|
|
|
|
|
|
client.connect = Mock(side_effect=connect)
|
|
|
|
client.driver = Driver(client, controller_state)
|
|
|
|
client.version = VersionInfo.from_message(version_state)
|
|
|
|
client.ws_server_url = "ws://test:3000/zjs"
|
|
|
|
client.state = "connected"
|
|
|
|
yield client
|
2021-01-10 23:08:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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-15 14:15:03 +00:00
|
|
|
@pytest.fixture(name="ecolink_door_sensor")
|
|
|
|
def legacy_binary_sensor_fixture(client, ecolink_door_sensor_state):
|
|
|
|
"""Mock a legacy_binary_sensor node."""
|
|
|
|
node = Node(client, ecolink_door_sensor_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-13 15:28:51 +00:00
|
|
|
@pytest.fixture(name="bulb_6_multi_color")
|
|
|
|
def bulb_6_multi_color_fixture(client, bulb_6_multi_color_state):
|
|
|
|
"""Mock a bulb 6 multi-color node."""
|
|
|
|
node = Node(client, bulb_6_multi_color_state)
|
|
|
|
client.driver.controller.nodes[node.node_id] = node
|
|
|
|
return node
|
|
|
|
|
|
|
|
|
2021-01-25 21:09:12 +00:00
|
|
|
@pytest.fixture(name="eaton_rf9640_dimmer")
|
|
|
|
def eaton_rf9640_dimmer_fixture(client, eaton_rf9640_dimmer_state):
|
|
|
|
"""Mock a Eaton RF9640 (V4 compatible) dimmer node."""
|
|
|
|
node = Node(client, eaton_rf9640_dimmer_state)
|
|
|
|
client.driver.controller.nodes[node.node_id] = node
|
|
|
|
return node
|
|
|
|
|
|
|
|
|
2021-01-16 16:43:25 +00:00
|
|
|
@pytest.fixture(name="lock_schlage_be469")
|
|
|
|
def lock_schlage_be469_fixture(client, lock_schlage_be469_state):
|
|
|
|
"""Mock a schlage lock node."""
|
|
|
|
node = Node(client, lock_schlage_be469_state)
|
|
|
|
client.driver.controller.nodes[node.node_id] = node
|
|
|
|
return node
|
|
|
|
|
|
|
|
|
2021-01-25 14:50:21 +00:00
|
|
|
@pytest.fixture(name="lock_august_pro")
|
|
|
|
def lock_august_asl03_fixture(client, lock_august_asl03_state):
|
|
|
|
"""Mock a August Pro lock node."""
|
|
|
|
node = Node(client, lock_august_asl03_state)
|
|
|
|
client.driver.controller.nodes[node.node_id] = node
|
|
|
|
return node
|
|
|
|
|
|
|
|
|
2021-01-18 02:45:06 +00:00
|
|
|
@pytest.fixture(name="climate_radio_thermostat_ct100_plus")
|
|
|
|
def climate_radio_thermostat_ct100_plus_fixture(
|
|
|
|
client, climate_radio_thermostat_ct100_plus_state
|
|
|
|
):
|
|
|
|
"""Mock a climate radio thermostat ct100 plus node."""
|
|
|
|
node = Node(client, climate_radio_thermostat_ct100_plus_state)
|
|
|
|
client.driver.controller.nodes[node.node_id] = node
|
|
|
|
return node
|
|
|
|
|
|
|
|
|
2021-02-01 19:46:06 +00:00
|
|
|
@pytest.fixture(name="climate_radio_thermostat_ct100_plus_different_endpoints")
|
|
|
|
def climate_radio_thermostat_ct100_plus_different_endpoints_fixture(
|
|
|
|
client, climate_radio_thermostat_ct100_plus_different_endpoints_state
|
|
|
|
):
|
|
|
|
"""Mock a climate radio thermostat ct100 plus node with values on different endpoints."""
|
|
|
|
node = Node(client, climate_radio_thermostat_ct100_plus_different_endpoints_state)
|
|
|
|
client.driver.controller.nodes[node.node_id] = node
|
|
|
|
return node
|
|
|
|
|
|
|
|
|
2021-01-18 15:08:52 +00:00
|
|
|
@pytest.fixture(name="nortek_thermostat")
|
|
|
|
def nortek_thermostat_fixture(client, nortek_thermostat_state):
|
|
|
|
"""Mock a nortek thermostat node."""
|
|
|
|
node = Node(client, nortek_thermostat_state)
|
|
|
|
client.driver.controller.nodes[node.node_id] = node
|
|
|
|
return node
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="nortek_thermostat_added_event")
|
|
|
|
def nortek_thermostat_added_event_fixture(client):
|
|
|
|
"""Mock a Nortek thermostat node added event."""
|
|
|
|
event_data = json.loads(load_fixture("zwave_js/nortek_thermostat_added_event.json"))
|
|
|
|
event = Event("node added", event_data)
|
|
|
|
return event
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="nortek_thermostat_removed_event")
|
|
|
|
def nortek_thermostat_removed_event_fixture(client):
|
|
|
|
"""Mock a Nortek thermostat node removed event."""
|
|
|
|
event_data = json.loads(
|
|
|
|
load_fixture("zwave_js/nortek_thermostat_removed_event.json")
|
|
|
|
)
|
|
|
|
event = Event("node removed", event_data)
|
|
|
|
return event
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
return entry
|
2021-01-22 16:51:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="chain_actuator_zws12")
|
|
|
|
def window_cover_fixture(client, chain_actuator_zws12_state):
|
|
|
|
"""Mock a window cover node."""
|
|
|
|
node = Node(client, chain_actuator_zws12_state)
|
|
|
|
client.driver.controller.nodes[node.node_id] = node
|
|
|
|
return node
|
2021-01-22 23:11:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="in_wall_smart_fan_control")
|
|
|
|
def in_wall_smart_fan_control_fixture(client, in_wall_smart_fan_control_state):
|
|
|
|
"""Mock a fan node."""
|
|
|
|
node = Node(client, in_wall_smart_fan_control_state)
|
|
|
|
client.driver.controller.nodes[node.node_id] = node
|
|
|
|
return node
|
2021-02-02 09:30:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="multiple_devices")
|
|
|
|
def multiple_devices_fixture(
|
|
|
|
client, climate_radio_thermostat_ct100_plus_state, lock_schlage_be469_state
|
|
|
|
):
|
|
|
|
"""Mock a client with multiple devices."""
|
|
|
|
node = Node(client, climate_radio_thermostat_ct100_plus_state)
|
|
|
|
client.driver.controller.nodes[node.node_id] = node
|
|
|
|
node = Node(client, lock_schlage_be469_state)
|
|
|
|
client.driver.controller.nodes[node.node_id] = node
|
|
|
|
return client.driver.controller.nodes
|