Skip to content

Commit

Permalink
Add velbus light and sensor platform testcases (#134485)
Browse files Browse the repository at this point in the history
Co-authored-by: Joost Lekkerkerker <[email protected]>
  • Loading branch information
cereal2nd and joostlek authored Jan 3, 2025
1 parent d4f3809 commit e6da6d9
Show file tree
Hide file tree
Showing 5 changed files with 631 additions and 1 deletion.
101 changes: 100 additions & 1 deletion tests/components/velbus/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
from unittest.mock import AsyncMock, MagicMock, patch

import pytest
from velbusaio.channels import Button, Relay, SelectedProgram, Temperature
from velbusaio.channels import (
Button,
ButtonCounter,
Dimmer,
LightSensor,
Relay,
SelectedProgram,
SensorNumber,
Temperature,
)

from homeassistant.components.velbus import VelbusConfigEntry
from homeassistant.components.velbus.const import DOMAIN
Expand All @@ -22,6 +31,10 @@ def mock_controller(
mock_relay: AsyncMock,
mock_temperature: AsyncMock,
mock_select: AsyncMock,
mock_buttoncounter: AsyncMock,
mock_sensornumber: AsyncMock,
mock_lightsensor: AsyncMock,
mock_dimmer: AsyncMock,
) -> Generator[AsyncMock]:
"""Mock a successful velbus controller."""
with (
Expand All @@ -37,6 +50,14 @@ def mock_controller(
cont.get_all_switch.return_value = [mock_relay]
cont.get_all_climate.return_value = [mock_temperature]
cont.get_all_select.return_value = [mock_select]
cont.get_all_sensor.return_value = [
mock_buttoncounter,
mock_temperature,
mock_sensornumber,
mock_lightsensor,
]
cont.get_all_light.return_value = [mock_dimmer]
cont.get_all_led.return_value = [mock_button]
yield controller


Expand All @@ -53,6 +74,7 @@ def mock_button() -> AsyncMock:
channel.get_module_sw_version.return_value = "1.0.0"
channel.get_module_serial.return_value = "a1b2c3d4e5f6"
channel.is_closed.return_value = True
channel.is_on.return_value = False
return channel


Expand All @@ -68,6 +90,7 @@ def mock_temperature() -> AsyncMock:
channel.get_full_name.return_value = "Channel full name"
channel.get_module_sw_version.return_value = "3.0.0"
channel.get_module_serial.return_value = "asdfghjk"
channel.is_counter_channel.return_value = False
channel.get_class.return_value = "temperature"
channel.get_unit.return_value = "°C"
channel.get_state.return_value = 20.0
Expand Down Expand Up @@ -114,6 +137,82 @@ def mock_select() -> AsyncMock:
return channel


@pytest.fixture
def mock_buttoncounter() -> AsyncMock:
"""Mock a successful velbus channel."""
channel = AsyncMock(spec=ButtonCounter)
channel.get_categories.return_value = ["sensor"]
channel.get_name.return_value = "ButtonCounter"
channel.get_module_address.return_value = 2
channel.get_channel_number.return_value = 2
channel.get_module_type_name.return_value = "VMB7IN"
channel.get_full_name.return_value = "Channel full name"
channel.get_module_sw_version.return_value = "1.0.0"
channel.get_module_serial.return_value = "a1b2c3d4e5f6"
channel.is_counter_channel.return_value = True
channel.is_temperature.return_value = False
channel.get_state.return_value = 100
channel.get_unit.return_value = "W"
channel.get_counter_state.return_value = 100
channel.get_counter_unit.return_value = "kWh"
return channel


@pytest.fixture
def mock_sensornumber() -> AsyncMock:
"""Mock a successful velbus channel."""
channel = AsyncMock(spec=SensorNumber)
channel.get_categories.return_value = ["sensor"]
channel.get_name.return_value = "SensorNumber"
channel.get_module_address.return_value = 2
channel.get_channel_number.return_value = 3
channel.get_module_type_name.return_value = "VMB7IN"
channel.get_full_name.return_value = "Channel full name"
channel.get_module_sw_version.return_value = "1.0.0"
channel.get_module_serial.return_value = "a1b2c3d4e5f6"
channel.is_counter_channel.return_value = False
channel.is_temperature.return_value = False
channel.get_unit.return_value = "m"
channel.get_state.return_value = 10
return channel


@pytest.fixture
def mock_lightsensor() -> AsyncMock:
"""Mock a successful velbus channel."""
channel = AsyncMock(spec=LightSensor)
channel.get_categories.return_value = ["sensor"]
channel.get_name.return_value = "LightSensor"
channel.get_module_address.return_value = 2
channel.get_channel_number.return_value = 4
channel.get_module_type_name.return_value = "VMB7IN"
channel.get_full_name.return_value = "Channel full name"
channel.get_module_sw_version.return_value = "1.0.0"
channel.get_module_serial.return_value = "a1b2c3d4e5f6"
channel.is_counter_channel.return_value = False
channel.is_temperature.return_value = False
channel.get_unit.return_value = "illuminance"
channel.get_state.return_value = 250
return channel


@pytest.fixture
def mock_dimmer() -> AsyncMock:
"""Mock a successful velbus channel."""
channel = AsyncMock(spec=Dimmer)
channel.get_categories.return_value = ["light"]
channel.get_name.return_value = "Dimmer"
channel.get_module_address.return_value = 3
channel.get_channel_number.return_value = 1
channel.get_module_type_name.return_value = "VMBDN1"
channel.get_full_name.return_value = "Dimmer full name"
channel.get_module_sw_version.return_value = "1.0.0"
channel.get_module_serial.return_value = "a1b2c3d4e5f6g7"
channel.is_on.return_value = False
channel.get_dimmer_state.return_value = 33
return channel


@pytest.fixture(name="config_entry")
async def mock_config_entry(
hass: HomeAssistant,
Expand Down
112 changes: 112 additions & 0 deletions tests/components/velbus/snapshots/test_light.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# serializer version: 1
# name: test_entities[light.dimmer-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'supported_color_modes': list([
<ColorMode.BRIGHTNESS: 'brightness'>,
]),
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'light',
'entity_category': None,
'entity_id': 'light.dimmer',
'has_entity_name': False,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Dimmer',
'platform': 'velbus',
'previous_unique_id': None,
'supported_features': <LightEntityFeature: 32>,
'translation_key': None,
'unique_id': 'a1b2c3d4e5f6g7-1',
'unit_of_measurement': None,
})
# ---
# name: test_entities[light.dimmer-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'brightness': None,
'color_mode': None,
'friendly_name': 'Dimmer',
'supported_color_modes': list([
<ColorMode.BRIGHTNESS: 'brightness'>,
]),
'supported_features': <LightEntityFeature: 32>,
}),
'context': <ANY>,
'entity_id': 'light.dimmer',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_entities[light.led_buttonon-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'supported_color_modes': list([
<ColorMode.ONOFF: 'onoff'>,
]),
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'light',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'light.led_buttonon',
'has_entity_name': False,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'LED ButtonOn',
'platform': 'velbus',
'previous_unique_id': None,
'supported_features': <LightEntityFeature: 8>,
'translation_key': None,
'unique_id': 'a1b2c3d4e5f6-1',
'unit_of_measurement': None,
})
# ---
# name: test_entities[light.led_buttonon-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'color_mode': None,
'friendly_name': 'LED ButtonOn',
'supported_color_modes': list([
<ColorMode.ONOFF: 'onoff'>,
]),
'supported_features': <LightEntityFeature: 8>,
}),
'context': <ANY>,
'entity_id': 'light.led_buttonon',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
Loading

0 comments on commit e6da6d9

Please sign in to comment.