Skip to content

Commit e6da6d9

Browse files
cereal2ndjoostlek
andauthored
Add velbus light and sensor platform testcases (#134485)
Co-authored-by: Joost Lekkerkerker <[email protected]>
1 parent d4f3809 commit e6da6d9

File tree

5 files changed

+631
-1
lines changed

5 files changed

+631
-1
lines changed

tests/components/velbus/conftest.py

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44
from unittest.mock import AsyncMock, MagicMock, patch
55

66
import pytest
7-
from velbusaio.channels import Button, Relay, SelectedProgram, Temperature
7+
from velbusaio.channels import (
8+
Button,
9+
ButtonCounter,
10+
Dimmer,
11+
LightSensor,
12+
Relay,
13+
SelectedProgram,
14+
SensorNumber,
15+
Temperature,
16+
)
817

918
from homeassistant.components.velbus import VelbusConfigEntry
1019
from homeassistant.components.velbus.const import DOMAIN
@@ -22,6 +31,10 @@ def mock_controller(
2231
mock_relay: AsyncMock,
2332
mock_temperature: AsyncMock,
2433
mock_select: AsyncMock,
34+
mock_buttoncounter: AsyncMock,
35+
mock_sensornumber: AsyncMock,
36+
mock_lightsensor: AsyncMock,
37+
mock_dimmer: AsyncMock,
2538
) -> Generator[AsyncMock]:
2639
"""Mock a successful velbus controller."""
2740
with (
@@ -37,6 +50,14 @@ def mock_controller(
3750
cont.get_all_switch.return_value = [mock_relay]
3851
cont.get_all_climate.return_value = [mock_temperature]
3952
cont.get_all_select.return_value = [mock_select]
53+
cont.get_all_sensor.return_value = [
54+
mock_buttoncounter,
55+
mock_temperature,
56+
mock_sensornumber,
57+
mock_lightsensor,
58+
]
59+
cont.get_all_light.return_value = [mock_dimmer]
60+
cont.get_all_led.return_value = [mock_button]
4061
yield controller
4162

4263

@@ -53,6 +74,7 @@ def mock_button() -> AsyncMock:
5374
channel.get_module_sw_version.return_value = "1.0.0"
5475
channel.get_module_serial.return_value = "a1b2c3d4e5f6"
5576
channel.is_closed.return_value = True
77+
channel.is_on.return_value = False
5678
return channel
5779

5880

@@ -68,6 +90,7 @@ def mock_temperature() -> AsyncMock:
6890
channel.get_full_name.return_value = "Channel full name"
6991
channel.get_module_sw_version.return_value = "3.0.0"
7092
channel.get_module_serial.return_value = "asdfghjk"
93+
channel.is_counter_channel.return_value = False
7194
channel.get_class.return_value = "temperature"
7295
channel.get_unit.return_value = "°C"
7396
channel.get_state.return_value = 20.0
@@ -114,6 +137,82 @@ def mock_select() -> AsyncMock:
114137
return channel
115138

116139

140+
@pytest.fixture
141+
def mock_buttoncounter() -> AsyncMock:
142+
"""Mock a successful velbus channel."""
143+
channel = AsyncMock(spec=ButtonCounter)
144+
channel.get_categories.return_value = ["sensor"]
145+
channel.get_name.return_value = "ButtonCounter"
146+
channel.get_module_address.return_value = 2
147+
channel.get_channel_number.return_value = 2
148+
channel.get_module_type_name.return_value = "VMB7IN"
149+
channel.get_full_name.return_value = "Channel full name"
150+
channel.get_module_sw_version.return_value = "1.0.0"
151+
channel.get_module_serial.return_value = "a1b2c3d4e5f6"
152+
channel.is_counter_channel.return_value = True
153+
channel.is_temperature.return_value = False
154+
channel.get_state.return_value = 100
155+
channel.get_unit.return_value = "W"
156+
channel.get_counter_state.return_value = 100
157+
channel.get_counter_unit.return_value = "kWh"
158+
return channel
159+
160+
161+
@pytest.fixture
162+
def mock_sensornumber() -> AsyncMock:
163+
"""Mock a successful velbus channel."""
164+
channel = AsyncMock(spec=SensorNumber)
165+
channel.get_categories.return_value = ["sensor"]
166+
channel.get_name.return_value = "SensorNumber"
167+
channel.get_module_address.return_value = 2
168+
channel.get_channel_number.return_value = 3
169+
channel.get_module_type_name.return_value = "VMB7IN"
170+
channel.get_full_name.return_value = "Channel full name"
171+
channel.get_module_sw_version.return_value = "1.0.0"
172+
channel.get_module_serial.return_value = "a1b2c3d4e5f6"
173+
channel.is_counter_channel.return_value = False
174+
channel.is_temperature.return_value = False
175+
channel.get_unit.return_value = "m"
176+
channel.get_state.return_value = 10
177+
return channel
178+
179+
180+
@pytest.fixture
181+
def mock_lightsensor() -> AsyncMock:
182+
"""Mock a successful velbus channel."""
183+
channel = AsyncMock(spec=LightSensor)
184+
channel.get_categories.return_value = ["sensor"]
185+
channel.get_name.return_value = "LightSensor"
186+
channel.get_module_address.return_value = 2
187+
channel.get_channel_number.return_value = 4
188+
channel.get_module_type_name.return_value = "VMB7IN"
189+
channel.get_full_name.return_value = "Channel full name"
190+
channel.get_module_sw_version.return_value = "1.0.0"
191+
channel.get_module_serial.return_value = "a1b2c3d4e5f6"
192+
channel.is_counter_channel.return_value = False
193+
channel.is_temperature.return_value = False
194+
channel.get_unit.return_value = "illuminance"
195+
channel.get_state.return_value = 250
196+
return channel
197+
198+
199+
@pytest.fixture
200+
def mock_dimmer() -> AsyncMock:
201+
"""Mock a successful velbus channel."""
202+
channel = AsyncMock(spec=Dimmer)
203+
channel.get_categories.return_value = ["light"]
204+
channel.get_name.return_value = "Dimmer"
205+
channel.get_module_address.return_value = 3
206+
channel.get_channel_number.return_value = 1
207+
channel.get_module_type_name.return_value = "VMBDN1"
208+
channel.get_full_name.return_value = "Dimmer full name"
209+
channel.get_module_sw_version.return_value = "1.0.0"
210+
channel.get_module_serial.return_value = "a1b2c3d4e5f6g7"
211+
channel.is_on.return_value = False
212+
channel.get_dimmer_state.return_value = 33
213+
return channel
214+
215+
117216
@pytest.fixture(name="config_entry")
118217
async def mock_config_entry(
119218
hass: HomeAssistant,
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# serializer version: 1
2+
# name: test_entities[light.dimmer-entry]
3+
EntityRegistryEntrySnapshot({
4+
'aliases': set({
5+
}),
6+
'area_id': None,
7+
'capabilities': dict({
8+
'supported_color_modes': list([
9+
<ColorMode.BRIGHTNESS: 'brightness'>,
10+
]),
11+
}),
12+
'config_entry_id': <ANY>,
13+
'device_class': None,
14+
'device_id': <ANY>,
15+
'disabled_by': None,
16+
'domain': 'light',
17+
'entity_category': None,
18+
'entity_id': 'light.dimmer',
19+
'has_entity_name': False,
20+
'hidden_by': None,
21+
'icon': None,
22+
'id': <ANY>,
23+
'labels': set({
24+
}),
25+
'name': None,
26+
'options': dict({
27+
}),
28+
'original_device_class': None,
29+
'original_icon': None,
30+
'original_name': 'Dimmer',
31+
'platform': 'velbus',
32+
'previous_unique_id': None,
33+
'supported_features': <LightEntityFeature: 32>,
34+
'translation_key': None,
35+
'unique_id': 'a1b2c3d4e5f6g7-1',
36+
'unit_of_measurement': None,
37+
})
38+
# ---
39+
# name: test_entities[light.dimmer-state]
40+
StateSnapshot({
41+
'attributes': ReadOnlyDict({
42+
'brightness': None,
43+
'color_mode': None,
44+
'friendly_name': 'Dimmer',
45+
'supported_color_modes': list([
46+
<ColorMode.BRIGHTNESS: 'brightness'>,
47+
]),
48+
'supported_features': <LightEntityFeature: 32>,
49+
}),
50+
'context': <ANY>,
51+
'entity_id': 'light.dimmer',
52+
'last_changed': <ANY>,
53+
'last_reported': <ANY>,
54+
'last_updated': <ANY>,
55+
'state': 'off',
56+
})
57+
# ---
58+
# name: test_entities[light.led_buttonon-entry]
59+
EntityRegistryEntrySnapshot({
60+
'aliases': set({
61+
}),
62+
'area_id': None,
63+
'capabilities': dict({
64+
'supported_color_modes': list([
65+
<ColorMode.ONOFF: 'onoff'>,
66+
]),
67+
}),
68+
'config_entry_id': <ANY>,
69+
'device_class': None,
70+
'device_id': <ANY>,
71+
'disabled_by': None,
72+
'domain': 'light',
73+
'entity_category': <EntityCategory.CONFIG: 'config'>,
74+
'entity_id': 'light.led_buttonon',
75+
'has_entity_name': False,
76+
'hidden_by': None,
77+
'icon': None,
78+
'id': <ANY>,
79+
'labels': set({
80+
}),
81+
'name': None,
82+
'options': dict({
83+
}),
84+
'original_device_class': None,
85+
'original_icon': None,
86+
'original_name': 'LED ButtonOn',
87+
'platform': 'velbus',
88+
'previous_unique_id': None,
89+
'supported_features': <LightEntityFeature: 8>,
90+
'translation_key': None,
91+
'unique_id': 'a1b2c3d4e5f6-1',
92+
'unit_of_measurement': None,
93+
})
94+
# ---
95+
# name: test_entities[light.led_buttonon-state]
96+
StateSnapshot({
97+
'attributes': ReadOnlyDict({
98+
'color_mode': None,
99+
'friendly_name': 'LED ButtonOn',
100+
'supported_color_modes': list([
101+
<ColorMode.ONOFF: 'onoff'>,
102+
]),
103+
'supported_features': <LightEntityFeature: 8>,
104+
}),
105+
'context': <ANY>,
106+
'entity_id': 'light.led_buttonon',
107+
'last_changed': <ANY>,
108+
'last_reported': <ANY>,
109+
'last_updated': <ANY>,
110+
'state': 'off',
111+
})
112+
# ---

0 commit comments

Comments
 (0)