Cleanup Tuya climate/cover tests (#149157)

This commit is contained in:
epenet 2025-07-21 12:27:37 +02:00 committed by GitHub
parent ff9fb6228b
commit c08aa74496
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 14 deletions

View File

@ -15,8 +15,8 @@ from tests.common import MockConfigEntry
DEVICE_MOCKS = { DEVICE_MOCKS = {
"cl_am43_corded_motor_zigbee_cover": [ "cl_am43_corded_motor_zigbee_cover": [
# https://github.com/home-assistant/core/issues/71242 # https://github.com/home-assistant/core/issues/71242
Platform.SELECT,
Platform.COVER, Platform.COVER,
Platform.SELECT,
], ],
"clkg_curtain_switch": [ "clkg_curtain_switch": [
# https://github.com/home-assistant/core/issues/136055 # https://github.com/home-assistant/core/issues/136055

View File

@ -8,6 +8,10 @@ import pytest
from syrupy.assertion import SnapshotAssertion from syrupy.assertion import SnapshotAssertion
from tuya_sharing import CustomerDevice from tuya_sharing import CustomerDevice
from homeassistant.components.climate import (
DOMAIN as CLIMATE_DOMAIN,
SERVICE_SET_FAN_MODE,
)
from homeassistant.components.tuya import ManagerCompat from homeassistant.components.tuya import ManagerCompat
from homeassistant.const import Platform from homeassistant.const import Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -69,16 +73,17 @@ async def test_fan_mode_windspeed(
mock_device: CustomerDevice, mock_device: CustomerDevice,
) -> None: ) -> None:
"""Test fan mode with windspeed.""" """Test fan mode with windspeed."""
entity_id = "climate.air_conditioner"
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
state = hass.states.get("climate.air_conditioner") state = hass.states.get(entity_id)
assert state is not None, "climate.air_conditioner does not exist" assert state is not None, f"{entity_id} does not exist"
assert state.attributes["fan_mode"] == 1 assert state.attributes["fan_mode"] == 1
await hass.services.async_call( await hass.services.async_call(
Platform.CLIMATE, CLIMATE_DOMAIN,
"set_fan_mode", SERVICE_SET_FAN_MODE,
{ {
"entity_id": "climate.air_conditioner", "entity_id": entity_id,
"fan_mode": 2, "fan_mode": 2,
}, },
) )
@ -104,17 +109,18 @@ async def test_fan_mode_no_valid_code(
mock_device.status_range.pop("windspeed", None) mock_device.status_range.pop("windspeed", None)
mock_device.status.pop("windspeed", None) mock_device.status.pop("windspeed", None)
entity_id = "climate.air_conditioner"
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
state = hass.states.get("climate.air_conditioner") state = hass.states.get(entity_id)
assert state is not None, "climate.air_conditioner does not exist" assert state is not None, f"{entity_id} does not exist"
assert state.attributes.get("fan_mode") is None assert state.attributes.get("fan_mode") is None
with pytest.raises(ServiceNotSupported): with pytest.raises(ServiceNotSupported):
await hass.services.async_call( await hass.services.async_call(
Platform.CLIMATE, CLIMATE_DOMAIN,
"set_fan_mode", SERVICE_SET_FAN_MODE,
{ {
"entity_id": "climate.air_conditioner", "entity_id": entity_id,
"fan_mode": 2, "fan_mode": 2,
}, },
blocking=True, blocking=True,

View File

@ -83,8 +83,9 @@ async def test_percent_state_on_cover(
# 100 is closed and 0 is open for Tuya covers # 100 is closed and 0 is open for Tuya covers
mock_device.status["percent_state"] = 100 - percent_state mock_device.status["percent_state"] = 100 - percent_state
entity_id = "cover.kitchen_blinds_curtain"
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
cover_state = hass.states.get("cover.kitchen_blinds_curtain") state = hass.states.get(entity_id)
assert cover_state is not None, "cover.kitchen_blinds_curtain does not exist" assert state is not None, f"{entity_id} does not exist"
assert cover_state.attributes["current_position"] == percent_state assert state.attributes["current_position"] == percent_state