Turn on device before setting mode (#25314)
parent
662c33af85
commit
b4481269ec
homeassistant/components/smartthings
tests/components/smartthings
|
@ -326,8 +326,13 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateDevice):
|
|||
if hvac_mode == HVAC_MODE_OFF:
|
||||
await self.async_turn_off()
|
||||
return
|
||||
await self._device.set_air_conditioner_mode(
|
||||
STATE_TO_AC_MODE[hvac_mode], set_status=True)
|
||||
tasks = []
|
||||
# Turn on the device if it's off before setting mode.
|
||||
if not self._device.status.switch:
|
||||
tasks.append(self._device.switch_on(set_status=True))
|
||||
tasks.append(self._device.set_air_conditioner_mode(
|
||||
STATE_TO_AC_MODE[hvac_mode], set_status=True))
|
||||
await asyncio.gather(*tasks)
|
||||
# State is set optimistically in the command above, therefore update
|
||||
# the entity state ahead of receiving the confirming push updates
|
||||
self.async_schedule_update_ha_state()
|
||||
|
@ -338,7 +343,12 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateDevice):
|
|||
# operation mode
|
||||
operation_mode = kwargs.get(ATTR_HVAC_MODE)
|
||||
if operation_mode:
|
||||
tasks.append(self.async_set_hvac_mode(operation_mode))
|
||||
if operation_mode == HVAC_MODE_OFF:
|
||||
tasks.append(self._device.switch_off(set_status=True))
|
||||
else:
|
||||
if not self._device.status.switch:
|
||||
tasks.append(self._device.switch_on(set_status=True))
|
||||
tasks.append(self.async_set_hvac_mode(operation_mode))
|
||||
# temperature
|
||||
tasks.append(self._device.set_cooling_setpoint(
|
||||
kwargs[ATTR_TEMPERATURE], set_status=True))
|
||||
|
|
|
@ -293,6 +293,23 @@ async def test_set_hvac_mode(hass, thermostat, air_conditioner):
|
|||
assert state.state == HVAC_MODE_COOL, entity_id
|
||||
|
||||
|
||||
async def test_ac_set_hvac_mode_from_off(hass, air_conditioner):
|
||||
"""Test setting HVAC mode when the unit is off."""
|
||||
air_conditioner.status.update_attribute_value(
|
||||
Attribute.air_conditioner_mode, 'heat')
|
||||
air_conditioner.status.update_attribute_value(Attribute.switch, 'off')
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||
state = hass.states.get('climate.air_conditioner')
|
||||
assert state.state == HVAC_MODE_OFF
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN, SERVICE_SET_HVAC_MODE, {
|
||||
ATTR_ENTITY_ID: 'climate.air_conditioner',
|
||||
ATTR_HVAC_MODE: HVAC_MODE_HEAT_COOL},
|
||||
blocking=True)
|
||||
state = hass.states.get('climate.air_conditioner')
|
||||
assert state.state == HVAC_MODE_HEAT_COOL
|
||||
|
||||
|
||||
async def test_ac_set_hvac_mode_off(hass, air_conditioner):
|
||||
"""Test the AC HVAC mode can be turned off set successfully."""
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||
|
@ -376,6 +393,39 @@ async def test_set_temperature_ac_with_mode(hass, air_conditioner):
|
|||
assert state.state == HVAC_MODE_COOL
|
||||
|
||||
|
||||
async def test_set_temperature_ac_with_mode_from_off(hass, air_conditioner):
|
||||
"""Test the temp and mode is set successfully when the unit is off."""
|
||||
air_conditioner.status.update_attribute_value(
|
||||
Attribute.air_conditioner_mode, 'heat')
|
||||
air_conditioner.status.update_attribute_value(Attribute.switch, 'off')
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||
assert hass.states.get('climate.air_conditioner').state == HVAC_MODE_OFF
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN, SERVICE_SET_TEMPERATURE, {
|
||||
ATTR_ENTITY_ID: 'climate.air_conditioner',
|
||||
ATTR_TEMPERATURE: 27,
|
||||
ATTR_HVAC_MODE: HVAC_MODE_COOL},
|
||||
blocking=True)
|
||||
state = hass.states.get('climate.air_conditioner')
|
||||
assert state.attributes[ATTR_TEMPERATURE] == 27
|
||||
assert state.state == HVAC_MODE_COOL
|
||||
|
||||
|
||||
async def test_set_temperature_ac_with_mode_to_off(hass, air_conditioner):
|
||||
"""Test the temp and mode is set successfully to turn off the unit."""
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||
assert hass.states.get('climate.air_conditioner').state != HVAC_MODE_OFF
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN, SERVICE_SET_TEMPERATURE, {
|
||||
ATTR_ENTITY_ID: 'climate.air_conditioner',
|
||||
ATTR_TEMPERATURE: 27,
|
||||
ATTR_HVAC_MODE: HVAC_MODE_OFF},
|
||||
blocking=True)
|
||||
state = hass.states.get('climate.air_conditioner')
|
||||
assert state.attributes[ATTR_TEMPERATURE] == 27
|
||||
assert state.state == HVAC_MODE_OFF
|
||||
|
||||
|
||||
async def test_set_temperature_with_mode(hass, thermostat):
|
||||
"""Test the temperature and mode is set successfully."""
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[thermostat])
|
||||
|
|
Loading…
Reference in New Issue