Skip to content

Commit 21b1122

Browse files
authored
Add test fixture for Tuya cover (home-assistant#148660)
1 parent 09104fc commit 21b1122

File tree

5 files changed

+207
-0
lines changed

5 files changed

+207
-0
lines changed

tests/components/tuya/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
from tests.common import MockConfigEntry
1414

1515
DEVICE_MOCKS = {
16+
"am43_corded_motor_zigbee_cover": [
17+
# https://github.com/home-assistant/core/issues/71242
18+
Platform.SELECT,
19+
Platform.COVER,
20+
],
1621
"clkg_curtain_switch": [
1722
# https://github.com/home-assistant/core/issues/136055
1823
Platform.COVER,
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"id": "zah67ekd",
3+
"name": "Kitchen Blinds",
4+
"category": "cl",
5+
"product_id": "zah67ekd",
6+
"product_name": "AM43拉绳电机-Zigbee",
7+
"online": true,
8+
"function": {
9+
"control": {
10+
"type": "Enum",
11+
"value": { "range": ["open", "stop", "close", "continue"] }
12+
},
13+
"percent_control": {
14+
"type": "Integer",
15+
"value": { "unit": "%", "min": 0, "max": 100, "scale": 0, "step": 1 }
16+
},
17+
"control_back_mode": {
18+
"type": "Enum",
19+
"value": { "range": ["forward", "back"] }
20+
}
21+
},
22+
"status_range": {
23+
"control": {
24+
"type": "Enum",
25+
"value": { "range": ["open", "stop", "close", "continue"] }
26+
},
27+
"percent_control": {
28+
"type": "Integer",
29+
"value": { "unit": "%", "min": 0, "max": 100, "scale": 0, "step": 1 }
30+
},
31+
"percent_state": {
32+
"type": "Integer",
33+
"value": { "unit": "%", "min": 0, "max": 100, "scale": 0, "step": 1 }
34+
},
35+
"control_back_mode": {
36+
"type": "Enum",
37+
"value": { "range": ["forward", "back"] }
38+
},
39+
"work_state": {
40+
"type": "Enum",
41+
"value": { "range": ["opening", "closing"] }
42+
},
43+
"situation_set": {
44+
"type": "Enum",
45+
"value": { "range": ["fully_open", "fully_close"] }
46+
},
47+
"fault": {
48+
"type": "Bitmap",
49+
"value": { "label": ["motor_fault"] }
50+
}
51+
},
52+
"status": {
53+
"control": "stop",
54+
"percent_control": 100,
55+
"percent_state": 52,
56+
"control_back_mode": "forward",
57+
"work_state": "closing",
58+
"situation_set": "fully_open",
59+
"fault": 0
60+
}
61+
}

tests/components/tuya/snapshots/test_cover.ambr

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,55 @@
11
# serializer version: 1
2+
# name: test_platform_setup_and_discovery[am43_corded_motor_zigbee_cover][cover.kitchen_blinds_curtain-entry]
3+
EntityRegistryEntrySnapshot({
4+
'aliases': set({
5+
}),
6+
'area_id': None,
7+
'capabilities': None,
8+
'config_entry_id': <ANY>,
9+
'config_subentry_id': <ANY>,
10+
'device_class': None,
11+
'device_id': <ANY>,
12+
'disabled_by': None,
13+
'domain': 'cover',
14+
'entity_category': None,
15+
'entity_id': 'cover.kitchen_blinds_curtain',
16+
'has_entity_name': True,
17+
'hidden_by': None,
18+
'icon': None,
19+
'id': <ANY>,
20+
'labels': set({
21+
}),
22+
'name': None,
23+
'options': dict({
24+
}),
25+
'original_device_class': <CoverDeviceClass.CURTAIN: 'curtain'>,
26+
'original_icon': None,
27+
'original_name': 'Curtain',
28+
'platform': 'tuya',
29+
'previous_unique_id': None,
30+
'suggested_object_id': None,
31+
'supported_features': <CoverEntityFeature: 15>,
32+
'translation_key': 'curtain',
33+
'unique_id': 'tuya.zah67ekdcontrol',
34+
'unit_of_measurement': None,
35+
})
36+
# ---
37+
# name: test_platform_setup_and_discovery[am43_corded_motor_zigbee_cover][cover.kitchen_blinds_curtain-state]
38+
StateSnapshot({
39+
'attributes': ReadOnlyDict({
40+
'current_position': 48,
41+
'device_class': 'curtain',
42+
'friendly_name': 'Kitchen Blinds Curtain',
43+
'supported_features': <CoverEntityFeature: 15>,
44+
}),
45+
'context': <ANY>,
46+
'entity_id': 'cover.kitchen_blinds_curtain',
47+
'last_changed': <ANY>,
48+
'last_reported': <ANY>,
49+
'last_updated': <ANY>,
50+
'state': 'open',
51+
})
52+
# ---
253
# name: test_platform_setup_and_discovery[clkg_curtain_switch][cover.tapparelle_studio_curtain-entry]
354
EntityRegistryEntrySnapshot({
455
'aliases': set({

tests/components/tuya/snapshots/test_select.ambr

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,61 @@
11
# serializer version: 1
2+
# name: test_platform_setup_and_discovery[am43_corded_motor_zigbee_cover][select.kitchen_blinds_motor_mode-entry]
3+
EntityRegistryEntrySnapshot({
4+
'aliases': set({
5+
}),
6+
'area_id': None,
7+
'capabilities': dict({
8+
'options': list([
9+
'forward',
10+
'back',
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': 'select',
19+
'entity_category': <EntityCategory.CONFIG: 'config'>,
20+
'entity_id': 'select.kitchen_blinds_motor_mode',
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': None,
31+
'original_icon': None,
32+
'original_name': 'Motor mode',
33+
'platform': 'tuya',
34+
'previous_unique_id': None,
35+
'suggested_object_id': None,
36+
'supported_features': 0,
37+
'translation_key': 'curtain_motor_mode',
38+
'unique_id': 'tuya.zah67ekdcontrol_back_mode',
39+
'unit_of_measurement': None,
40+
})
41+
# ---
42+
# name: test_platform_setup_and_discovery[am43_corded_motor_zigbee_cover][select.kitchen_blinds_motor_mode-state]
43+
StateSnapshot({
44+
'attributes': ReadOnlyDict({
45+
'friendly_name': 'Kitchen Blinds Motor mode',
46+
'options': list([
47+
'forward',
48+
'back',
49+
]),
50+
}),
51+
'context': <ANY>,
52+
'entity_id': 'select.kitchen_blinds_motor_mode',
53+
'last_changed': <ANY>,
54+
'last_reported': <ANY>,
55+
'last_updated': <ANY>,
56+
'state': 'forward',
57+
})
58+
# ---
259
# name: test_platform_setup_and_discovery[cs_arete_two_12l_dehumidifier_air_purifier][select.dehumidifier_countdown-entry]
360
EntityRegistryEntrySnapshot({
461
'aliases': set({

tests/components/tuya/test_cover.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,36 @@ async def test_platform_setup_no_discovery(
5555
assert not er.async_entries_for_config_entry(
5656
entity_registry, mock_config_entry.entry_id
5757
)
58+
59+
60+
@pytest.mark.parametrize(
61+
"mock_device_code",
62+
["am43_corded_motor_zigbee_cover"],
63+
)
64+
@pytest.mark.parametrize(
65+
("percent_control", "percent_state"),
66+
[
67+
(100, 52),
68+
(0, 100),
69+
(50, 25),
70+
],
71+
)
72+
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER])
73+
async def test_percent_state_on_cover(
74+
hass: HomeAssistant,
75+
mock_manager: ManagerCompat,
76+
mock_config_entry: MockConfigEntry,
77+
mock_device: CustomerDevice,
78+
percent_control: int,
79+
percent_state: int,
80+
) -> None:
81+
"""Test percent_state attribute on the cover entity."""
82+
mock_device.status["percent_control"] = percent_control
83+
# 100 is closed and 0 is open for Tuya covers
84+
mock_device.status["percent_state"] = 100 - percent_state
85+
86+
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
87+
88+
cover_state = hass.states.get("cover.kitchen_blinds_curtain")
89+
assert cover_state is not None, "cover.kitchen_blinds_curtain does not exist"
90+
assert cover_state.attributes["current_position"] == percent_state

0 commit comments

Comments
 (0)