mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 08:07:45 +00:00
Add test fixture for Tuya cover (#148660)
This commit is contained in:
parent
09104fca4d
commit
21b1122f83
@ -13,6 +13,11 @@ from homeassistant.core import HomeAssistant
|
|||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
DEVICE_MOCKS = {
|
DEVICE_MOCKS = {
|
||||||
|
"am43_corded_motor_zigbee_cover": [
|
||||||
|
# https://github.com/home-assistant/core/issues/71242
|
||||||
|
Platform.SELECT,
|
||||||
|
Platform.COVER,
|
||||||
|
],
|
||||||
"clkg_curtain_switch": [
|
"clkg_curtain_switch": [
|
||||||
# https://github.com/home-assistant/core/issues/136055
|
# https://github.com/home-assistant/core/issues/136055
|
||||||
Platform.COVER,
|
Platform.COVER,
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"id": "zah67ekd",
|
||||||
|
"name": "Kitchen Blinds",
|
||||||
|
"category": "cl",
|
||||||
|
"product_id": "zah67ekd",
|
||||||
|
"product_name": "AM43拉绳电机-Zigbee",
|
||||||
|
"online": true,
|
||||||
|
"function": {
|
||||||
|
"control": {
|
||||||
|
"type": "Enum",
|
||||||
|
"value": { "range": ["open", "stop", "close", "continue"] }
|
||||||
|
},
|
||||||
|
"percent_control": {
|
||||||
|
"type": "Integer",
|
||||||
|
"value": { "unit": "%", "min": 0, "max": 100, "scale": 0, "step": 1 }
|
||||||
|
},
|
||||||
|
"control_back_mode": {
|
||||||
|
"type": "Enum",
|
||||||
|
"value": { "range": ["forward", "back"] }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"status_range": {
|
||||||
|
"control": {
|
||||||
|
"type": "Enum",
|
||||||
|
"value": { "range": ["open", "stop", "close", "continue"] }
|
||||||
|
},
|
||||||
|
"percent_control": {
|
||||||
|
"type": "Integer",
|
||||||
|
"value": { "unit": "%", "min": 0, "max": 100, "scale": 0, "step": 1 }
|
||||||
|
},
|
||||||
|
"percent_state": {
|
||||||
|
"type": "Integer",
|
||||||
|
"value": { "unit": "%", "min": 0, "max": 100, "scale": 0, "step": 1 }
|
||||||
|
},
|
||||||
|
"control_back_mode": {
|
||||||
|
"type": "Enum",
|
||||||
|
"value": { "range": ["forward", "back"] }
|
||||||
|
},
|
||||||
|
"work_state": {
|
||||||
|
"type": "Enum",
|
||||||
|
"value": { "range": ["opening", "closing"] }
|
||||||
|
},
|
||||||
|
"situation_set": {
|
||||||
|
"type": "Enum",
|
||||||
|
"value": { "range": ["fully_open", "fully_close"] }
|
||||||
|
},
|
||||||
|
"fault": {
|
||||||
|
"type": "Bitmap",
|
||||||
|
"value": { "label": ["motor_fault"] }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"control": "stop",
|
||||||
|
"percent_control": 100,
|
||||||
|
"percent_state": 52,
|
||||||
|
"control_back_mode": "forward",
|
||||||
|
"work_state": "closing",
|
||||||
|
"situation_set": "fully_open",
|
||||||
|
"fault": 0
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,55 @@
|
|||||||
# serializer version: 1
|
# serializer version: 1
|
||||||
|
# name: test_platform_setup_and_discovery[am43_corded_motor_zigbee_cover][cover.kitchen_blinds_curtain-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'cover',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'cover.kitchen_blinds_curtain',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <CoverDeviceClass.CURTAIN: 'curtain'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Curtain',
|
||||||
|
'platform': 'tuya',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'suggested_object_id': None,
|
||||||
|
'supported_features': <CoverEntityFeature: 15>,
|
||||||
|
'translation_key': 'curtain',
|
||||||
|
'unique_id': 'tuya.zah67ekdcontrol',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_platform_setup_and_discovery[am43_corded_motor_zigbee_cover][cover.kitchen_blinds_curtain-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'current_position': 48,
|
||||||
|
'device_class': 'curtain',
|
||||||
|
'friendly_name': 'Kitchen Blinds Curtain',
|
||||||
|
'supported_features': <CoverEntityFeature: 15>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'cover.kitchen_blinds_curtain',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'open',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
# name: test_platform_setup_and_discovery[clkg_curtain_switch][cover.tapparelle_studio_curtain-entry]
|
# name: test_platform_setup_and_discovery[clkg_curtain_switch][cover.tapparelle_studio_curtain-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
|
@ -1,4 +1,61 @@
|
|||||||
# serializer version: 1
|
# serializer version: 1
|
||||||
|
# name: test_platform_setup_and_discovery[am43_corded_motor_zigbee_cover][select.kitchen_blinds_motor_mode-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': dict({
|
||||||
|
'options': list([
|
||||||
|
'forward',
|
||||||
|
'back',
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'select',
|
||||||
|
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||||
|
'entity_id': 'select.kitchen_blinds_motor_mode',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Motor mode',
|
||||||
|
'platform': 'tuya',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'suggested_object_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'curtain_motor_mode',
|
||||||
|
'unique_id': 'tuya.zah67ekdcontrol_back_mode',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_platform_setup_and_discovery[am43_corded_motor_zigbee_cover][select.kitchen_blinds_motor_mode-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Kitchen Blinds Motor mode',
|
||||||
|
'options': list([
|
||||||
|
'forward',
|
||||||
|
'back',
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'select.kitchen_blinds_motor_mode',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'forward',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
# name: test_platform_setup_and_discovery[cs_arete_two_12l_dehumidifier_air_purifier][select.dehumidifier_countdown-entry]
|
# name: test_platform_setup_and_discovery[cs_arete_two_12l_dehumidifier_air_purifier][select.dehumidifier_countdown-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
|
@ -55,3 +55,36 @@ async def test_platform_setup_no_discovery(
|
|||||||
assert not er.async_entries_for_config_entry(
|
assert not er.async_entries_for_config_entry(
|
||||||
entity_registry, mock_config_entry.entry_id
|
entity_registry, mock_config_entry.entry_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"mock_device_code",
|
||||||
|
["am43_corded_motor_zigbee_cover"],
|
||||||
|
)
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("percent_control", "percent_state"),
|
||||||
|
[
|
||||||
|
(100, 52),
|
||||||
|
(0, 100),
|
||||||
|
(50, 25),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
@patch("homeassistant.components.tuya.PLATFORMS", [Platform.COVER])
|
||||||
|
async def test_percent_state_on_cover(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_manager: ManagerCompat,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
mock_device: CustomerDevice,
|
||||||
|
percent_control: int,
|
||||||
|
percent_state: int,
|
||||||
|
) -> None:
|
||||||
|
"""Test percent_state attribute on the cover entity."""
|
||||||
|
mock_device.status["percent_control"] = percent_control
|
||||||
|
# 100 is closed and 0 is open for Tuya covers
|
||||||
|
mock_device.status["percent_state"] = 100 - percent_state
|
||||||
|
|
||||||
|
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
|
||||||
|
|
||||||
|
cover_state = hass.states.get("cover.kitchen_blinds_curtain")
|
||||||
|
assert cover_state is not None, "cover.kitchen_blinds_curtain does not exist"
|
||||||
|
assert cover_state.attributes["current_position"] == percent_state
|
||||||
|
Loading…
x
Reference in New Issue
Block a user