|
11 | 11 | from homeassistant.components.tuya import ManagerCompat |
12 | 12 | from homeassistant.const import Platform |
13 | 13 | from homeassistant.core import HomeAssistant |
| 14 | +from homeassistant.exceptions import ServiceNotSupported |
14 | 15 | from homeassistant.helpers import entity_registry as er |
15 | 16 |
|
16 | 17 | from . import DEVICE_MOCKS, initialize_entry |
@@ -55,3 +56,66 @@ async def test_platform_setup_no_discovery( |
55 | 56 | assert not er.async_entries_for_config_entry( |
56 | 57 | entity_registry, mock_config_entry.entry_id |
57 | 58 | ) |
| 59 | + |
| 60 | + |
| 61 | +@pytest.mark.parametrize( |
| 62 | + "mock_device_code", |
| 63 | + ["kt_serenelife_slpac905wuk_air_conditioner"], |
| 64 | +) |
| 65 | +async def test_fan_mode_windspeed( |
| 66 | + hass: HomeAssistant, |
| 67 | + mock_manager: ManagerCompat, |
| 68 | + mock_config_entry: MockConfigEntry, |
| 69 | + mock_device: CustomerDevice, |
| 70 | +) -> None: |
| 71 | + """Test fan mode with windspeed.""" |
| 72 | + await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) |
| 73 | + |
| 74 | + state = hass.states.get("climate.air_conditioner") |
| 75 | + assert state is not None, "climate.air_conditioner does not exist" |
| 76 | + assert state.attributes["fan_mode"] == 1 |
| 77 | + await hass.services.async_call( |
| 78 | + Platform.CLIMATE, |
| 79 | + "set_fan_mode", |
| 80 | + { |
| 81 | + "entity_id": "climate.air_conditioner", |
| 82 | + "fan_mode": 2, |
| 83 | + }, |
| 84 | + ) |
| 85 | + await hass.async_block_till_done() |
| 86 | + mock_manager.send_commands.assert_called_once_with( |
| 87 | + mock_device.id, [{"code": "windspeed", "value": "2"}] |
| 88 | + ) |
| 89 | + |
| 90 | + |
| 91 | +@pytest.mark.parametrize( |
| 92 | + "mock_device_code", |
| 93 | + ["kt_serenelife_slpac905wuk_air_conditioner"], |
| 94 | +) |
| 95 | +async def test_fan_mode_no_valid_code( |
| 96 | + hass: HomeAssistant, |
| 97 | + mock_manager: ManagerCompat, |
| 98 | + mock_config_entry: MockConfigEntry, |
| 99 | + mock_device: CustomerDevice, |
| 100 | +) -> None: |
| 101 | + """Test fan mode with no valid code.""" |
| 102 | + # Remove windspeed DPCode to simulate a device with no valid fan mode |
| 103 | + mock_device.function.pop("windspeed", None) |
| 104 | + mock_device.status_range.pop("windspeed", None) |
| 105 | + mock_device.status.pop("windspeed", None) |
| 106 | + |
| 107 | + await initialize_entry(hass, mock_manager, mock_config_entry, mock_device) |
| 108 | + |
| 109 | + state = hass.states.get("climate.air_conditioner") |
| 110 | + assert state is not None, "climate.air_conditioner does not exist" |
| 111 | + assert state.attributes.get("fan_mode") is None |
| 112 | + with pytest.raises(ServiceNotSupported): |
| 113 | + await hass.services.async_call( |
| 114 | + Platform.CLIMATE, |
| 115 | + "set_fan_mode", |
| 116 | + { |
| 117 | + "entity_id": "climate.air_conditioner", |
| 118 | + "fan_mode": 2, |
| 119 | + }, |
| 120 | + blocking=True, |
| 121 | + ) |
0 commit comments