Add velbus diagnostics tests (#134621)

This commit is contained in:
Maikel Punie 2025-01-04 09:10:34 +01:00 committed by GitHub
parent 197ff932af
commit c9dbb205dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 159 additions and 0 deletions

View File

@ -14,6 +14,7 @@ from velbusaio.channels import (
SensorNumber,
Temperature,
)
from velbusaio.module import Module
from homeassistant.components.velbus import VelbusConfigEntry
from homeassistant.components.velbus.const import DOMAIN
@ -35,6 +36,8 @@ def mock_controller(
mock_sensornumber: AsyncMock,
mock_lightsensor: AsyncMock,
mock_dimmer: AsyncMock,
mock_module_no_subdevices: AsyncMock,
mock_module_subdevices: AsyncMock,
) -> Generator[AsyncMock]:
"""Mock a successful velbus controller."""
with (
@ -58,9 +61,44 @@ def mock_controller(
]
cont.get_all_light.return_value = [mock_dimmer]
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
@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
def mock_button() -> AsyncMock:
"""Mock a successful velbus channel."""

View 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',
}),
]),
})
# ---

View 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"))