Adjust climate

This commit is contained in:
epenet 2025-07-21 11:56:01 +00:00
parent 94739f45d0
commit 5dd916b5ba
2 changed files with 64 additions and 6 deletions

View File

@ -308,18 +308,16 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
def set_fan_mode(self, fan_mode: str) -> None:
"""Set new target fan mode."""
if TYPE_CHECKING:
# We can rely on supported_features from __init__
# guarded by supported features
assert self._fan_mode_dp_code is not None
self._send_command([{"code": self._fan_mode_dp_code, "value": fan_mode}])
def set_humidity(self, humidity: int) -> None:
"""Set new target humidity."""
if self._set_humidity is None:
raise ServiceValidationError(
translation_domain=DOMAIN,
translation_key="action_dpcode_not_found",
)
if TYPE_CHECKING:
# guarded by supported features
assert self._set_humidity is not None
self._send_command(
[

View File

@ -11,6 +11,8 @@ from tuya_sharing import CustomerDevice
from homeassistant.components.climate import (
DOMAIN as CLIMATE_DOMAIN,
SERVICE_SET_FAN_MODE,
SERVICE_SET_HUMIDITY,
SERVICE_SET_TEMPERATURE,
)
from homeassistant.components.tuya import ManagerCompat
from homeassistant.const import Platform
@ -62,6 +64,36 @@ async def test_platform_setup_no_discovery(
)
@pytest.mark.parametrize(
"mock_device_code",
["kt_serenelife_slpac905wuk_air_conditioner"],
)
async def test_set_temperature(
hass: HomeAssistant,
mock_manager: ManagerCompat,
mock_config_entry: MockConfigEntry,
mock_device: CustomerDevice,
) -> None:
"""Test set temperature service."""
entity_id = "climate.air_conditioner"
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
state = hass.states.get(entity_id)
assert state is not None, f"{entity_id} does not exist"
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_TEMPERATURE,
{
"entity_id": entity_id,
"temperature": 22.7,
},
)
await hass.async_block_till_done()
mock_manager.send_commands.assert_called_once_with(
mock_device.id, [{"code": "temp_set", "value": 22}]
)
@pytest.mark.parametrize(
"mock_device_code",
["kt_serenelife_slpac905wuk_air_conditioner"],
@ -125,3 +157,31 @@ async def test_fan_mode_no_valid_code(
},
blocking=True,
)
@pytest.mark.parametrize(
"mock_device_code",
["kt_serenelife_slpac905wuk_air_conditioner"],
)
async def test_set_humidity_not_supported(
hass: HomeAssistant,
mock_manager: ManagerCompat,
mock_config_entry: MockConfigEntry,
mock_device: CustomerDevice,
) -> None:
"""Test set humidity service (not available on this device)."""
entity_id = "climate.air_conditioner"
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
state = hass.states.get(entity_id)
assert state is not None, f"{entity_id} does not exist"
with pytest.raises(ServiceNotSupported):
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_HUMIDITY,
{
"entity_id": entity_id,
"humidity": 50,
},
blocking=True,
)