Add tuya snapshot tests for wxkg category (#148609)

This commit is contained in:
epenet 2025-07-11 13:55:01 +02:00 committed by GitHub
parent ec5991bc68
commit 73c9d99abf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 284 additions and 0 deletions

View File

@ -88,6 +88,11 @@ DEVICE_MOCKS = {
# https://github.com/home-assistant/core/issues/102769 # https://github.com/home-assistant/core/issues/102769
Platform.SENSOR, Platform.SENSOR,
], ],
"wxkg_wireless_switch": [
# https://github.com/home-assistant/core/issues/93975
Platform.EVENT,
Platform.SENSOR,
],
"zndb_smart_meter": [ "zndb_smart_meter": [
# https://github.com/home-assistant/core/issues/138372 # https://github.com/home-assistant/core/issues/138372
Platform.SENSOR, Platform.SENSOR,

View File

@ -0,0 +1,50 @@
{
"endpoint": "https://openapi.tuyaeu.com",
"auth_type": 0,
"country_code": "44",
"app_type": "smartlife",
"mqtt_connected": true,
"disabled_by": null,
"disabled_polling": false,
"name": "Bathroom Smart Switch",
"model": "LKWSW201",
"category": "wxkg",
"product_id": "l8yaz4um5b3pwyvf",
"product_name": "Wireless Switch",
"online": true,
"sub": false,
"time_zone": "+00:00",
"active_time": "2023-01-05T20:12:39+00:00",
"create_time": "2023-01-05T20:12:39+00:00",
"update_time": "2023-05-30T17:17:47+00:00",
"function": {},
"status_range": {
"switch_mode1": {
"type": "Enum",
"value": {
"range": ["click", "press"]
}
},
"switch_mode2": {
"type": "Enum",
"value": {
"range": ["click", "press"]
}
},
"battery_percentage": {
"type": "Integer",
"value": {
"unit": "%",
"min": 0,
"max": 100,
"scale": 0,
"step": 1
}
}
},
"status": {
"switch_mode1": "click",
"switch_mode2": "click",
"battery_percentage": 100
}
}

View File

@ -0,0 +1,119 @@
# serializer version: 1
# name: test_platform_setup_and_discovery[wxkg_wireless_switch][event.bathroom_smart_switch_button_1-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'event_types': list([
'click',
'press',
]),
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'event',
'entity_category': None,
'entity_id': 'event.bathroom_smart_switch_button_1',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <EventDeviceClass.BUTTON: 'button'>,
'original_icon': None,
'original_name': 'Button 1',
'platform': 'tuya',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'numbered_button',
'unique_id': 'tuya.mocked_device_idswitch_mode1',
'unit_of_measurement': None,
})
# ---
# name: test_platform_setup_and_discovery[wxkg_wireless_switch][event.bathroom_smart_switch_button_1-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'button',
'event_type': None,
'event_types': list([
'click',
'press',
]),
'friendly_name': 'Bathroom Smart Switch Button 1',
}),
'context': <ANY>,
'entity_id': 'event.bathroom_smart_switch_button_1',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# ---
# name: test_platform_setup_and_discovery[wxkg_wireless_switch][event.bathroom_smart_switch_button_2-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'event_types': list([
'click',
'press',
]),
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'event',
'entity_category': None,
'entity_id': 'event.bathroom_smart_switch_button_2',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <EventDeviceClass.BUTTON: 'button'>,
'original_icon': None,
'original_name': 'Button 2',
'platform': 'tuya',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'numbered_button',
'unique_id': 'tuya.mocked_device_idswitch_mode2',
'unit_of_measurement': None,
})
# ---
# name: test_platform_setup_and_discovery[wxkg_wireless_switch][event.bathroom_smart_switch_button_2-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'button',
'event_type': None,
'event_types': list([
'click',
'press',
]),
'friendly_name': 'Bathroom Smart Switch Button 2',
}),
'context': <ANY>,
'entity_id': 'event.bathroom_smart_switch_button_2',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# ---

View File

@ -1467,6 +1467,59 @@
'state': '18.5', 'state': '18.5',
}) })
# --- # ---
# name: test_platform_setup_and_discovery[wxkg_wireless_switch][sensor.bathroom_smart_switch_battery-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.bathroom_smart_switch_battery',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.BATTERY: 'battery'>,
'original_icon': None,
'original_name': 'Battery',
'platform': 'tuya',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'battery',
'unique_id': 'tuya.mocked_device_idbattery_percentage',
'unit_of_measurement': '%',
})
# ---
# name: test_platform_setup_and_discovery[wxkg_wireless_switch][sensor.bathroom_smart_switch_battery-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'battery',
'friendly_name': 'Bathroom Smart Switch Battery',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': '%',
}),
'context': <ANY>,
'entity_id': 'sensor.bathroom_smart_switch_battery',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '100.0',
})
# ---
# name: test_platform_setup_and_discovery[zndb_smart_meter][sensor.meter_phase_a_current-entry] # name: test_platform_setup_and_discovery[zndb_smart_meter][sensor.meter_phase_a_current-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({

View File

@ -0,0 +1,57 @@
"""Test Tuya event platform."""
from __future__ import annotations
from unittest.mock import patch
import pytest
from syrupy.assertion import SnapshotAssertion
from tuya_sharing import CustomerDevice
from homeassistant.components.tuya import ManagerCompat
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from . import DEVICE_MOCKS, initialize_entry
from tests.common import MockConfigEntry, snapshot_platform
@pytest.mark.parametrize(
"mock_device_code",
[k for k, v in DEVICE_MOCKS.items() if Platform.EVENT in v],
)
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.EVENT])
async def test_platform_setup_and_discovery(
hass: HomeAssistant,
mock_manager: ManagerCompat,
mock_config_entry: MockConfigEntry,
mock_device: CustomerDevice,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test platform setup and discovery."""
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
@pytest.mark.parametrize(
"mock_device_code",
[k for k, v in DEVICE_MOCKS.items() if Platform.EVENT not in v],
)
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.EVENT])
async def test_platform_setup_no_discovery(
hass: HomeAssistant,
mock_manager: ManagerCompat,
mock_config_entry: MockConfigEntry,
mock_device: CustomerDevice,
entity_registry: er.EntityRegistry,
) -> None:
"""Test platform setup without discovery."""
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
assert not er.async_entries_for_config_entry(
entity_registry, mock_config_entry.entry_id
)