Skip to content

Commit 73c9d99

Browse files
authored
Add tuya snapshot tests for wxkg category (home-assistant#148609)
1 parent ec5991b commit 73c9d99

File tree

5 files changed

+284
-0
lines changed

5 files changed

+284
-0
lines changed

tests/components/tuya/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@
8888
# https://github.com/home-assistant/core/issues/102769
8989
Platform.SENSOR,
9090
],
91+
"wxkg_wireless_switch": [
92+
# https://github.com/home-assistant/core/issues/93975
93+
Platform.EVENT,
94+
Platform.SENSOR,
95+
],
9196
"zndb_smart_meter": [
9297
# https://github.com/home-assistant/core/issues/138372
9398
Platform.SENSOR,
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"endpoint": "https://openapi.tuyaeu.com",
3+
"auth_type": 0,
4+
"country_code": "44",
5+
"app_type": "smartlife",
6+
"mqtt_connected": true,
7+
"disabled_by": null,
8+
"disabled_polling": false,
9+
"name": "Bathroom Smart Switch",
10+
"model": "LKWSW201",
11+
"category": "wxkg",
12+
"product_id": "l8yaz4um5b3pwyvf",
13+
"product_name": "Wireless Switch",
14+
"online": true,
15+
"sub": false,
16+
"time_zone": "+00:00",
17+
"active_time": "2023-01-05T20:12:39+00:00",
18+
"create_time": "2023-01-05T20:12:39+00:00",
19+
"update_time": "2023-05-30T17:17:47+00:00",
20+
"function": {},
21+
"status_range": {
22+
"switch_mode1": {
23+
"type": "Enum",
24+
"value": {
25+
"range": ["click", "press"]
26+
}
27+
},
28+
"switch_mode2": {
29+
"type": "Enum",
30+
"value": {
31+
"range": ["click", "press"]
32+
}
33+
},
34+
"battery_percentage": {
35+
"type": "Integer",
36+
"value": {
37+
"unit": "%",
38+
"min": 0,
39+
"max": 100,
40+
"scale": 0,
41+
"step": 1
42+
}
43+
}
44+
},
45+
"status": {
46+
"switch_mode1": "click",
47+
"switch_mode2": "click",
48+
"battery_percentage": 100
49+
}
50+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# serializer version: 1
2+
# name: test_platform_setup_and_discovery[wxkg_wireless_switch][event.bathroom_smart_switch_button_1-entry]
3+
EntityRegistryEntrySnapshot({
4+
'aliases': set({
5+
}),
6+
'area_id': None,
7+
'capabilities': dict({
8+
'event_types': list([
9+
'click',
10+
'press',
11+
]),
12+
}),
13+
'config_entry_id': <ANY>,
14+
'config_subentry_id': <ANY>,
15+
'device_class': None,
16+
'device_id': <ANY>,
17+
'disabled_by': None,
18+
'domain': 'event',
19+
'entity_category': None,
20+
'entity_id': 'event.bathroom_smart_switch_button_1',
21+
'has_entity_name': True,
22+
'hidden_by': None,
23+
'icon': None,
24+
'id': <ANY>,
25+
'labels': set({
26+
}),
27+
'name': None,
28+
'options': dict({
29+
}),
30+
'original_device_class': <EventDeviceClass.BUTTON: 'button'>,
31+
'original_icon': None,
32+
'original_name': 'Button 1',
33+
'platform': 'tuya',
34+
'previous_unique_id': None,
35+
'suggested_object_id': None,
36+
'supported_features': 0,
37+
'translation_key': 'numbered_button',
38+
'unique_id': 'tuya.mocked_device_idswitch_mode1',
39+
'unit_of_measurement': None,
40+
})
41+
# ---
42+
# name: test_platform_setup_and_discovery[wxkg_wireless_switch][event.bathroom_smart_switch_button_1-state]
43+
StateSnapshot({
44+
'attributes': ReadOnlyDict({
45+
'device_class': 'button',
46+
'event_type': None,
47+
'event_types': list([
48+
'click',
49+
'press',
50+
]),
51+
'friendly_name': 'Bathroom Smart Switch Button 1',
52+
}),
53+
'context': <ANY>,
54+
'entity_id': 'event.bathroom_smart_switch_button_1',
55+
'last_changed': <ANY>,
56+
'last_reported': <ANY>,
57+
'last_updated': <ANY>,
58+
'state': 'unknown',
59+
})
60+
# ---
61+
# name: test_platform_setup_and_discovery[wxkg_wireless_switch][event.bathroom_smart_switch_button_2-entry]
62+
EntityRegistryEntrySnapshot({
63+
'aliases': set({
64+
}),
65+
'area_id': None,
66+
'capabilities': dict({
67+
'event_types': list([
68+
'click',
69+
'press',
70+
]),
71+
}),
72+
'config_entry_id': <ANY>,
73+
'config_subentry_id': <ANY>,
74+
'device_class': None,
75+
'device_id': <ANY>,
76+
'disabled_by': None,
77+
'domain': 'event',
78+
'entity_category': None,
79+
'entity_id': 'event.bathroom_smart_switch_button_2',
80+
'has_entity_name': True,
81+
'hidden_by': None,
82+
'icon': None,
83+
'id': <ANY>,
84+
'labels': set({
85+
}),
86+
'name': None,
87+
'options': dict({
88+
}),
89+
'original_device_class': <EventDeviceClass.BUTTON: 'button'>,
90+
'original_icon': None,
91+
'original_name': 'Button 2',
92+
'platform': 'tuya',
93+
'previous_unique_id': None,
94+
'suggested_object_id': None,
95+
'supported_features': 0,
96+
'translation_key': 'numbered_button',
97+
'unique_id': 'tuya.mocked_device_idswitch_mode2',
98+
'unit_of_measurement': None,
99+
})
100+
# ---
101+
# name: test_platform_setup_and_discovery[wxkg_wireless_switch][event.bathroom_smart_switch_button_2-state]
102+
StateSnapshot({
103+
'attributes': ReadOnlyDict({
104+
'device_class': 'button',
105+
'event_type': None,
106+
'event_types': list([
107+
'click',
108+
'press',
109+
]),
110+
'friendly_name': 'Bathroom Smart Switch Button 2',
111+
}),
112+
'context': <ANY>,
113+
'entity_id': 'event.bathroom_smart_switch_button_2',
114+
'last_changed': <ANY>,
115+
'last_reported': <ANY>,
116+
'last_updated': <ANY>,
117+
'state': 'unknown',
118+
})
119+
# ---

tests/components/tuya/snapshots/test_sensor.ambr

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,59 @@
14671467
'state': '18.5',
14681468
})
14691469
# ---
1470+
# name: test_platform_setup_and_discovery[wxkg_wireless_switch][sensor.bathroom_smart_switch_battery-entry]
1471+
EntityRegistryEntrySnapshot({
1472+
'aliases': set({
1473+
}),
1474+
'area_id': None,
1475+
'capabilities': dict({
1476+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
1477+
}),
1478+
'config_entry_id': <ANY>,
1479+
'config_subentry_id': <ANY>,
1480+
'device_class': None,
1481+
'device_id': <ANY>,
1482+
'disabled_by': None,
1483+
'domain': 'sensor',
1484+
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
1485+
'entity_id': 'sensor.bathroom_smart_switch_battery',
1486+
'has_entity_name': True,
1487+
'hidden_by': None,
1488+
'icon': None,
1489+
'id': <ANY>,
1490+
'labels': set({
1491+
}),
1492+
'name': None,
1493+
'options': dict({
1494+
}),
1495+
'original_device_class': <SensorDeviceClass.BATTERY: 'battery'>,
1496+
'original_icon': None,
1497+
'original_name': 'Battery',
1498+
'platform': 'tuya',
1499+
'previous_unique_id': None,
1500+
'suggested_object_id': None,
1501+
'supported_features': 0,
1502+
'translation_key': 'battery',
1503+
'unique_id': 'tuya.mocked_device_idbattery_percentage',
1504+
'unit_of_measurement': '%',
1505+
})
1506+
# ---
1507+
# name: test_platform_setup_and_discovery[wxkg_wireless_switch][sensor.bathroom_smart_switch_battery-state]
1508+
StateSnapshot({
1509+
'attributes': ReadOnlyDict({
1510+
'device_class': 'battery',
1511+
'friendly_name': 'Bathroom Smart Switch Battery',
1512+
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
1513+
'unit_of_measurement': '%',
1514+
}),
1515+
'context': <ANY>,
1516+
'entity_id': 'sensor.bathroom_smart_switch_battery',
1517+
'last_changed': <ANY>,
1518+
'last_reported': <ANY>,
1519+
'last_updated': <ANY>,
1520+
'state': '100.0',
1521+
})
1522+
# ---
14701523
# name: test_platform_setup_and_discovery[zndb_smart_meter][sensor.meter_phase_a_current-entry]
14711524
EntityRegistryEntrySnapshot({
14721525
'aliases': set({
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""Test Tuya event platform."""
2+
3+
from __future__ import annotations
4+
5+
from unittest.mock import patch
6+
7+
import pytest
8+
from syrupy.assertion import SnapshotAssertion
9+
from tuya_sharing import CustomerDevice
10+
11+
from homeassistant.components.tuya import ManagerCompat
12+
from homeassistant.const import Platform
13+
from homeassistant.core import HomeAssistant
14+
from homeassistant.helpers import entity_registry as er
15+
16+
from . import DEVICE_MOCKS, initialize_entry
17+
18+
from tests.common import MockConfigEntry, snapshot_platform
19+
20+
21+
@pytest.mark.parametrize(
22+
"mock_device_code",
23+
[k for k, v in DEVICE_MOCKS.items() if Platform.EVENT in v],
24+
)
25+
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.EVENT])
26+
async def test_platform_setup_and_discovery(
27+
hass: HomeAssistant,
28+
mock_manager: ManagerCompat,
29+
mock_config_entry: MockConfigEntry,
30+
mock_device: CustomerDevice,
31+
entity_registry: er.EntityRegistry,
32+
snapshot: SnapshotAssertion,
33+
) -> None:
34+
"""Test platform setup and discovery."""
35+
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
36+
37+
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
38+
39+
40+
@pytest.mark.parametrize(
41+
"mock_device_code",
42+
[k for k, v in DEVICE_MOCKS.items() if Platform.EVENT not in v],
43+
)
44+
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.EVENT])
45+
async def test_platform_setup_no_discovery(
46+
hass: HomeAssistant,
47+
mock_manager: ManagerCompat,
48+
mock_config_entry: MockConfigEntry,
49+
mock_device: CustomerDevice,
50+
entity_registry: er.EntityRegistry,
51+
) -> None:
52+
"""Test platform setup without discovery."""
53+
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
54+
55+
assert not er.async_entries_for_config_entry(
56+
entity_registry, mock_config_entry.entry_id
57+
)

0 commit comments

Comments
 (0)