Samsung AC Wind Mode (#119750)

This commit is contained in:
Jan Čermák 2024-06-21 13:19:42 +02:00 committed by GitHub
parent f0452e9ba0
commit 4707108146
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 85 additions and 6 deletions

View File

@ -56,6 +56,7 @@ OPERATING_STATE_TO_ACTION = {
"pending cool": HVACAction.COOLING, "pending cool": HVACAction.COOLING,
"pending heat": HVACAction.HEATING, "pending heat": HVACAction.HEATING,
"vent economizer": HVACAction.FAN, "vent economizer": HVACAction.FAN,
"wind": HVACAction.FAN,
} }
AC_MODE_TO_STATE = { AC_MODE_TO_STATE = {
@ -67,6 +68,7 @@ AC_MODE_TO_STATE = {
"heat": HVACMode.HEAT, "heat": HVACMode.HEAT,
"heatClean": HVACMode.HEAT, "heatClean": HVACMode.HEAT,
"fanOnly": HVACMode.FAN_ONLY, "fanOnly": HVACMode.FAN_ONLY,
"wind": HVACMode.FAN_ONLY,
} }
STATE_TO_AC_MODE = { STATE_TO_AC_MODE = {
HVACMode.HEAT_COOL: "auto", HVACMode.HEAT_COOL: "auto",
@ -87,7 +89,7 @@ FAN_OSCILLATION_TO_SWING = {
value: key for key, value in SWING_TO_FAN_OSCILLATION.items() value: key for key, value in SWING_TO_FAN_OSCILLATION.items()
} }
WIND = "wind"
WINDFREE = "windFree" WINDFREE = "windFree"
UNIT_MAP = {"C": UnitOfTemperature.CELSIUS, "F": UnitOfTemperature.FAHRENHEIT} UNIT_MAP = {"C": UnitOfTemperature.CELSIUS, "F": UnitOfTemperature.FAHRENHEIT}
@ -390,11 +392,17 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateEntity):
# Turn on the device if it's off before setting mode. # Turn on the device if it's off before setting mode.
if not self._device.status.switch: if not self._device.status.switch:
tasks.append(self._device.switch_on(set_status=True)) tasks.append(self._device.switch_on(set_status=True))
tasks.append(
self._device.set_air_conditioner_mode( mode = STATE_TO_AC_MODE[hvac_mode]
STATE_TO_AC_MODE[hvac_mode], set_status=True # If new hvac_mode is HVAC_MODE_FAN_ONLY and AirConditioner support "wind" mode the AirConditioner new mode has to be "wind"
) # The conversion make the mode change working
) # The conversion is made only for device that wrongly has capability "wind" instead "fan_only"
if hvac_mode == HVACMode.FAN_ONLY:
supported_modes = self._device.status.supported_ac_modes
if WIND in supported_modes:
mode = WIND
tasks.append(self._device.set_air_conditioner_mode(mode, set_status=True))
await asyncio.gather(*tasks) await asyncio.gather(*tasks)
# State is set optimistically in the command above, therefore update # State is set optimistically in the command above, therefore update
# the entity state ahead of receiving the confirming push updates # the entity state ahead of receiving the confirming push updates

View File

@ -202,6 +202,60 @@ def air_conditioner_fixture(device_factory):
return device return device
@pytest.fixture(name="air_conditioner_windfree")
def air_conditioner_windfree_fixture(device_factory):
"""Fixture returns a air conditioner."""
device = device_factory(
"Air Conditioner",
capabilities=[
Capability.air_conditioner_mode,
Capability.demand_response_load_control,
Capability.air_conditioner_fan_mode,
Capability.switch,
Capability.temperature_measurement,
Capability.thermostat_cooling_setpoint,
Capability.fan_oscillation_mode,
],
status={
Attribute.air_conditioner_mode: "auto",
Attribute.supported_ac_modes: [
"cool",
"dry",
"wind",
"auto",
"heat",
"wind",
],
Attribute.drlc_status: {
"duration": 0,
"drlcLevel": -1,
"start": "1970-01-01T00:00:00Z",
"override": False,
},
Attribute.fan_mode: "medium",
Attribute.supported_ac_fan_modes: [
"auto",
"low",
"medium",
"high",
"turbo",
],
Attribute.switch: "on",
Attribute.cooling_setpoint: 23,
"supportedAcOptionalMode": ["windFree"],
Attribute.supported_fan_oscillation_modes: [
"all",
"horizontal",
"vertical",
"fixed",
],
Attribute.fan_oscillation_mode: "vertical",
},
)
device.status.attributes[Attribute.temperature] = Status(24, "C", None)
return device
async def test_legacy_thermostat_entity_state( async def test_legacy_thermostat_entity_state(
hass: HomeAssistant, legacy_thermostat hass: HomeAssistant, legacy_thermostat
) -> None: ) -> None:
@ -424,6 +478,23 @@ async def test_ac_set_hvac_mode_off(hass: HomeAssistant, air_conditioner) -> Non
assert state.state == HVACMode.OFF assert state.state == HVACMode.OFF
async def test_ac_set_hvac_mode_wind(
hass: HomeAssistant, air_conditioner_windfree
) -> None:
"""Test the AC HVAC mode to fan only as wind mode for supported models."""
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner_windfree])
state = hass.states.get("climate.air_conditioner")
assert state.state != HVACMode.OFF
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
{ATTR_ENTITY_ID: "climate.air_conditioner", ATTR_HVAC_MODE: HVACMode.FAN_ONLY},
blocking=True,
)
state = hass.states.get("climate.air_conditioner")
assert state.state == HVACMode.FAN_ONLY
async def test_set_temperature_heat_mode(hass: HomeAssistant, thermostat) -> None: async def test_set_temperature_heat_mode(hass: HomeAssistant, thermostat) -> None:
"""Test the temperature is set successfully when in heat mode.""" """Test the temperature is set successfully when in heat mode."""
thermostat.status.thermostat_mode = "heat" thermostat.status.thermostat_mode = "heat"