mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 07:47:08 +00:00
Add velbus diagnostics tests (#134621)
This commit is contained in:
parent
197ff932af
commit
c9dbb205dd
@ -14,6 +14,7 @@ from velbusaio.channels import (
|
|||||||
SensorNumber,
|
SensorNumber,
|
||||||
Temperature,
|
Temperature,
|
||||||
)
|
)
|
||||||
|
from velbusaio.module import Module
|
||||||
|
|
||||||
from homeassistant.components.velbus import VelbusConfigEntry
|
from homeassistant.components.velbus import VelbusConfigEntry
|
||||||
from homeassistant.components.velbus.const import DOMAIN
|
from homeassistant.components.velbus.const import DOMAIN
|
||||||
@ -35,6 +36,8 @@ def mock_controller(
|
|||||||
mock_sensornumber: AsyncMock,
|
mock_sensornumber: AsyncMock,
|
||||||
mock_lightsensor: AsyncMock,
|
mock_lightsensor: AsyncMock,
|
||||||
mock_dimmer: AsyncMock,
|
mock_dimmer: AsyncMock,
|
||||||
|
mock_module_no_subdevices: AsyncMock,
|
||||||
|
mock_module_subdevices: AsyncMock,
|
||||||
) -> Generator[AsyncMock]:
|
) -> Generator[AsyncMock]:
|
||||||
"""Mock a successful velbus controller."""
|
"""Mock a successful velbus controller."""
|
||||||
with (
|
with (
|
||||||
@ -58,9 +61,44 @@ def mock_controller(
|
|||||||
]
|
]
|
||||||
cont.get_all_light.return_value = [mock_dimmer]
|
cont.get_all_light.return_value = [mock_dimmer]
|
||||||
cont.get_all_led.return_value = [mock_button]
|
cont.get_all_led.return_value = [mock_button]
|
||||||
|
cont.get_modules.return_value = {
|
||||||
|
1: mock_module_no_subdevices,
|
||||||
|
2: mock_module_no_subdevices,
|
||||||
|
3: mock_module_no_subdevices,
|
||||||
|
4: mock_module_no_subdevices,
|
||||||
|
99: mock_module_subdevices,
|
||||||
|
}
|
||||||
yield controller
|
yield controller
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_module_no_subdevices(
|
||||||
|
mock_relay: AsyncMock,
|
||||||
|
) -> AsyncMock:
|
||||||
|
"""Mock a velbus module."""
|
||||||
|
module = AsyncMock(spec=Module)
|
||||||
|
module.get_type_name.return_value = "VMB4RYLD"
|
||||||
|
module.get_addresses.return_value = [1, 2, 3, 4]
|
||||||
|
module.get_name.return_value = "BedRoom"
|
||||||
|
module.get_sw_version.return_value = "1.0.0"
|
||||||
|
module.is_loaded.return_value = True
|
||||||
|
module.get_channels.return_value = {}
|
||||||
|
return module
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_module_subdevices() -> AsyncMock:
|
||||||
|
"""Mock a velbus module."""
|
||||||
|
module = AsyncMock(spec=Module)
|
||||||
|
module.get_type_name.return_value = "VMB2BLE"
|
||||||
|
module.get_addresses.return_value = [99]
|
||||||
|
module.get_name.return_value = "Kitchen"
|
||||||
|
module.get_sw_version.return_value = "2.0.0"
|
||||||
|
module.is_loaded.return_value = True
|
||||||
|
module.get_channels.return_value = {}
|
||||||
|
return module
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_button() -> AsyncMock:
|
def mock_button() -> AsyncMock:
|
||||||
"""Mock a successful velbus channel."""
|
"""Mock a successful velbus channel."""
|
||||||
|
93
tests/components/velbus/snapshots/test_diagnostics.ambr
Normal file
93
tests/components/velbus/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_entry_diagnostics
|
||||||
|
dict({
|
||||||
|
'entry': dict({
|
||||||
|
'data': dict({
|
||||||
|
'name': 'velbus home',
|
||||||
|
'port': '127.0.1.0.1:3788',
|
||||||
|
}),
|
||||||
|
'disabled_by': None,
|
||||||
|
'discovery_keys': dict({
|
||||||
|
}),
|
||||||
|
'domain': 'velbus',
|
||||||
|
'minor_version': 1,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'pref_disable_new_entities': False,
|
||||||
|
'pref_disable_polling': False,
|
||||||
|
'source': 'user',
|
||||||
|
'title': 'Mock Title',
|
||||||
|
'unique_id': None,
|
||||||
|
'version': 2,
|
||||||
|
}),
|
||||||
|
'modules': list([
|
||||||
|
dict({
|
||||||
|
'address': list([
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
]),
|
||||||
|
'channels': dict({
|
||||||
|
}),
|
||||||
|
'is_loaded': True,
|
||||||
|
'name': 'BedRoom',
|
||||||
|
'sw_version': '1.0.0',
|
||||||
|
'type': 'VMB4RYLD',
|
||||||
|
}),
|
||||||
|
dict({
|
||||||
|
'address': list([
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
]),
|
||||||
|
'channels': dict({
|
||||||
|
}),
|
||||||
|
'is_loaded': True,
|
||||||
|
'name': 'BedRoom',
|
||||||
|
'sw_version': '1.0.0',
|
||||||
|
'type': 'VMB4RYLD',
|
||||||
|
}),
|
||||||
|
dict({
|
||||||
|
'address': list([
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
]),
|
||||||
|
'channels': dict({
|
||||||
|
}),
|
||||||
|
'is_loaded': True,
|
||||||
|
'name': 'BedRoom',
|
||||||
|
'sw_version': '1.0.0',
|
||||||
|
'type': 'VMB4RYLD',
|
||||||
|
}),
|
||||||
|
dict({
|
||||||
|
'address': list([
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
4,
|
||||||
|
]),
|
||||||
|
'channels': dict({
|
||||||
|
}),
|
||||||
|
'is_loaded': True,
|
||||||
|
'name': 'BedRoom',
|
||||||
|
'sw_version': '1.0.0',
|
||||||
|
'type': 'VMB4RYLD',
|
||||||
|
}),
|
||||||
|
dict({
|
||||||
|
'address': list([
|
||||||
|
99,
|
||||||
|
]),
|
||||||
|
'channels': dict({
|
||||||
|
}),
|
||||||
|
'is_loaded': True,
|
||||||
|
'name': 'Kitchen',
|
||||||
|
'sw_version': '2.0.0',
|
||||||
|
'type': 'VMB2BLE',
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
# ---
|
28
tests/components/velbus/test_diagnostics.py
Normal file
28
tests/components/velbus/test_diagnostics.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
"""Test Velbus diagnostics."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from syrupy import SnapshotAssertion
|
||||||
|
from syrupy.filters import props
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from . import init_integration
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||||
|
async def test_entry_diagnostics(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
config_entry: MockConfigEntry,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
) -> None:
|
||||||
|
"""Test config entry diagnostics."""
|
||||||
|
await init_integration(hass, config_entry)
|
||||||
|
|
||||||
|
result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
||||||
|
|
||||||
|
assert result == snapshot(exclude=props("created_at", "modified_at", "entry_id"))
|
Loading…
x
Reference in New Issue
Block a user