Insteon Device Control Panel (#70834)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
9af8cd030a
commit
a9ca774e7e
19 changed files with 650 additions and 519 deletions
|
@ -1,6 +1,11 @@
|
|||
"""Test the device level APIs."""
|
||||
import asyncio
|
||||
from unittest.mock import patch
|
||||
|
||||
from pyinsteon.constants import DeviceAction
|
||||
from pyinsteon.topics import DEVICE_LIST_CHANGED
|
||||
from pyinsteon.utils import publish_topic
|
||||
|
||||
from homeassistant.components import insteon
|
||||
from homeassistant.components.insteon.api import async_load_api
|
||||
from homeassistant.components.insteon.api.device import (
|
||||
|
@ -11,7 +16,7 @@ from homeassistant.components.insteon.api.device import (
|
|||
TYPE,
|
||||
async_device_name,
|
||||
)
|
||||
from homeassistant.components.insteon.const import DOMAIN
|
||||
from homeassistant.components.insteon.const import DOMAIN, MULTIPLE
|
||||
from homeassistant.helpers.device_registry import async_get_registry
|
||||
|
||||
from .const import MOCK_USER_INPUT_PLM
|
||||
|
@ -137,3 +142,47 @@ async def test_get_ha_device_name(hass, hass_ws_client):
|
|||
# Test no HA or Insteon device
|
||||
name = await async_device_name(device_reg, "BB.BB.BB")
|
||||
assert name == ""
|
||||
|
||||
|
||||
async def test_add_device_api(hass, hass_ws_client):
|
||||
"""Test adding an Insteon device."""
|
||||
|
||||
ws_client, devices, _, _ = await _async_setup(hass, hass_ws_client)
|
||||
with patch.object(insteon.api.device, "devices", devices):
|
||||
await ws_client.send_json({ID: 2, TYPE: "insteon/device/add", MULTIPLE: True})
|
||||
|
||||
await asyncio.sleep(0.01)
|
||||
assert devices.async_add_device_called_with.get("address") is None
|
||||
assert devices.async_add_device_called_with["multiple"] is True
|
||||
|
||||
msg = await ws_client.receive_json()
|
||||
assert msg["event"]["type"] == "device_added"
|
||||
assert msg["event"]["address"] == "aa.bb.cc"
|
||||
|
||||
msg = await ws_client.receive_json()
|
||||
assert msg["event"]["type"] == "device_added"
|
||||
assert msg["event"]["address"] == "bb.cc.dd"
|
||||
|
||||
publish_topic(
|
||||
DEVICE_LIST_CHANGED,
|
||||
address=None,
|
||||
action=DeviceAction.COMPLETED,
|
||||
)
|
||||
msg = await ws_client.receive_json()
|
||||
assert msg["event"]["type"] == "linking_stopped"
|
||||
|
||||
|
||||
async def test_cancel_add_device(hass, hass_ws_client):
|
||||
"""Test cancelling adding of a new device."""
|
||||
|
||||
ws_client, devices, _, _ = await _async_setup(hass, hass_ws_client)
|
||||
|
||||
with patch.object(insteon.api.aldb, "devices", devices):
|
||||
await ws_client.send_json(
|
||||
{
|
||||
ID: 2,
|
||||
TYPE: "insteon/device/add/cancel",
|
||||
}
|
||||
)
|
||||
msg = await ws_client.receive_json()
|
||||
assert msg["success"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue