mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Improve Slide Local device tests (#133197)
This commit is contained in:
parent
bce6127264
commit
d2dfba3116
@ -1,6 +1,6 @@
|
|||||||
"""Entities for slide_local integration."""
|
"""Entities for slide_local integration."""
|
||||||
|
|
||||||
from homeassistant.const import CONF_MAC
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
@ -12,18 +12,16 @@ class SlideEntity(CoordinatorEntity[SlideCoordinator]):
|
|||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, coordinator: SlideCoordinator) -> None:
|
||||||
self,
|
|
||||||
coordinator: SlideCoordinator,
|
|
||||||
) -> None:
|
|
||||||
"""Initialize the Slide device."""
|
"""Initialize the Slide device."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
|
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
manufacturer="Innovation in Motion",
|
manufacturer="Innovation in Motion",
|
||||||
connections={(CONF_MAC, coordinator.data["mac"])},
|
connections={(dr.CONNECTION_NETWORK_MAC, coordinator.data["mac"])},
|
||||||
name=coordinator.data["device_name"],
|
name=coordinator.data["device_name"],
|
||||||
sw_version=coordinator.api_version,
|
sw_version=coordinator.api_version,
|
||||||
|
hw_version=coordinator.data["board_rev"],
|
||||||
serial_number=coordinator.data["mac"],
|
serial_number=coordinator.data["mac"],
|
||||||
configuration_url=f"http://{coordinator.host}",
|
configuration_url=f"http://{coordinator.host}",
|
||||||
)
|
)
|
||||||
|
@ -6,7 +6,7 @@ from unittest.mock import AsyncMock, patch
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.slide_local.const import CONF_INVERT_POSITION, DOMAIN
|
from homeassistant.components.slide_local.const import CONF_INVERT_POSITION, DOMAIN
|
||||||
from homeassistant.const import CONF_API_VERSION, CONF_HOST
|
from homeassistant.const import CONF_API_VERSION, CONF_HOST, CONF_MAC
|
||||||
|
|
||||||
from .const import HOST, SLIDE_INFO_DATA
|
from .const import HOST, SLIDE_INFO_DATA
|
||||||
|
|
||||||
@ -22,6 +22,7 @@ def mock_config_entry() -> MockConfigEntry:
|
|||||||
data={
|
data={
|
||||||
CONF_HOST: HOST,
|
CONF_HOST: HOST,
|
||||||
CONF_API_VERSION: 2,
|
CONF_API_VERSION: 2,
|
||||||
|
CONF_MAC: "12:34:56:78:90:ab",
|
||||||
},
|
},
|
||||||
options={
|
options={
|
||||||
CONF_INVERT_POSITION: False,
|
CONF_INVERT_POSITION: False,
|
||||||
@ -33,25 +34,22 @@ def mock_config_entry() -> MockConfigEntry:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_slide_api():
|
def mock_slide_api() -> Generator[AsyncMock]:
|
||||||
"""Build a fixture for the SlideLocalApi that connects successfully and returns one device."""
|
"""Build a fixture for the SlideLocalApi that connects successfully and returns one device."""
|
||||||
|
|
||||||
mock_slide_local_api = AsyncMock()
|
|
||||||
mock_slide_local_api.slide_info.return_value = SLIDE_INFO_DATA
|
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.components.slide_local.SlideLocalApi",
|
"homeassistant.components.slide_local.coordinator.SlideLocalApi",
|
||||||
autospec=True,
|
autospec=True,
|
||||||
return_value=mock_slide_local_api,
|
) as mock_slide_local_api,
|
||||||
),
|
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.components.slide_local.config_flow.SlideLocalApi",
|
"homeassistant.components.slide_local.config_flow.SlideLocalApi",
|
||||||
autospec=True,
|
new=mock_slide_local_api,
|
||||||
return_value=mock_slide_local_api,
|
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
yield mock_slide_local_api
|
client = mock_slide_local_api.return_value
|
||||||
|
client.slide_info.return_value = SLIDE_INFO_DATA
|
||||||
|
yield client
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"slide_id": "slide_300000000000",
|
"slide_id": "slide_1234567890ab",
|
||||||
"mac": "300000000000",
|
"mac": "1234567890ab",
|
||||||
"board_rev": 1,
|
"board_rev": 1,
|
||||||
"device_name": "slide bedroom",
|
"device_name": "slide bedroom",
|
||||||
"zone_name": "bedroom",
|
"zone_name": "bedroom",
|
||||||
|
33
tests/components/slide_local/snapshots/test_init.ambr
Normal file
33
tests/components/slide_local/snapshots/test_init.ambr
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_device_info
|
||||||
|
DeviceRegistryEntrySnapshot({
|
||||||
|
'area_id': None,
|
||||||
|
'config_entries': <ANY>,
|
||||||
|
'configuration_url': 'http://127.0.0.2',
|
||||||
|
'connections': set({
|
||||||
|
tuple(
|
||||||
|
'mac',
|
||||||
|
'12:34:56:78:90:ab',
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
'disabled_by': None,
|
||||||
|
'entry_type': None,
|
||||||
|
'hw_version': 1,
|
||||||
|
'id': <ANY>,
|
||||||
|
'identifiers': set({
|
||||||
|
}),
|
||||||
|
'is_new': False,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'manufacturer': 'Innovation in Motion',
|
||||||
|
'model': None,
|
||||||
|
'model_id': None,
|
||||||
|
'name': 'slide bedroom',
|
||||||
|
'name_by_user': None,
|
||||||
|
'primary_config_entry': <ANY>,
|
||||||
|
'serial_number': '1234567890ab',
|
||||||
|
'suggested_area': None,
|
||||||
|
'sw_version': 2,
|
||||||
|
'via_device_id': None,
|
||||||
|
})
|
||||||
|
# ---
|
@ -63,7 +63,7 @@ async def test_user(
|
|||||||
assert result2["data"][CONF_HOST] == HOST
|
assert result2["data"][CONF_HOST] == HOST
|
||||||
assert result2["data"][CONF_PASSWORD] == "pwd"
|
assert result2["data"][CONF_PASSWORD] == "pwd"
|
||||||
assert result2["data"][CONF_API_VERSION] == 2
|
assert result2["data"][CONF_API_VERSION] == 2
|
||||||
assert result2["result"].unique_id == "30:00:00:00:00:00"
|
assert result2["result"].unique_id == "12:34:56:78:90:ab"
|
||||||
assert not result2["options"][CONF_INVERT_POSITION]
|
assert not result2["options"][CONF_INVERT_POSITION]
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ async def test_user_api_1(
|
|||||||
assert result2["data"][CONF_HOST] == HOST
|
assert result2["data"][CONF_HOST] == HOST
|
||||||
assert result2["data"][CONF_PASSWORD] == "pwd"
|
assert result2["data"][CONF_PASSWORD] == "pwd"
|
||||||
assert result2["data"][CONF_API_VERSION] == 1
|
assert result2["data"][CONF_API_VERSION] == 1
|
||||||
assert result2["result"].unique_id == "30:00:00:00:00:00"
|
assert result2["result"].unique_id == "12:34:56:78:90:ab"
|
||||||
assert not result2["options"][CONF_INVERT_POSITION]
|
assert not result2["options"][CONF_INVERT_POSITION]
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ async def test_user_api_error(
|
|||||||
assert result2["data"][CONF_HOST] == HOST
|
assert result2["data"][CONF_HOST] == HOST
|
||||||
assert result2["data"][CONF_PASSWORD] == "pwd"
|
assert result2["data"][CONF_PASSWORD] == "pwd"
|
||||||
assert result2["data"][CONF_API_VERSION] == 1
|
assert result2["data"][CONF_API_VERSION] == 1
|
||||||
assert result2["result"].unique_id == "30:00:00:00:00:00"
|
assert result2["result"].unique_id == "12:34:56:78:90:ab"
|
||||||
assert not result2["options"][CONF_INVERT_POSITION]
|
assert not result2["options"][CONF_INVERT_POSITION]
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
@ -259,7 +259,7 @@ async def test_abort_if_already_setup(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test we abort if the device is already setup."""
|
"""Test we abort if the device is already setup."""
|
||||||
|
|
||||||
MockConfigEntry(domain=DOMAIN, unique_id="30:00:00:00:00:00").add_to_hass(hass)
|
MockConfigEntry(domain=DOMAIN, unique_id="12:34:56:78:90:ab").add_to_hass(hass)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
29
tests/components/slide_local/test_init.py
Normal file
29
tests/components/slide_local/test_init.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
"""Tests for the Slide Local integration."""
|
||||||
|
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
|
from syrupy import SnapshotAssertion
|
||||||
|
|
||||||
|
from homeassistant.const import Platform
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
|
from . import setup_platform
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
async def test_device_info(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
mock_slide_api: AsyncMock,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
) -> None:
|
||||||
|
"""Test device registry integration."""
|
||||||
|
await setup_platform(hass, mock_config_entry, [Platform.COVER])
|
||||||
|
device_entry = device_registry.async_get_device(
|
||||||
|
connections={(dr.CONNECTION_NETWORK_MAC, "1234567890ab")}
|
||||||
|
)
|
||||||
|
assert device_entry is not None
|
||||||
|
assert device_entry == snapshot
|
Loading…
x
Reference in New Issue
Block a user