Restore SmartThings A/C on/off services (#25259)
* Restore ST A/C on/off services * Use correct OFF const * Support AC HVAC_MODE_OFFpull/25280/head
parent
ec3cb11e2f
commit
46cdbd273a
|
@ -323,6 +323,9 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateDevice):
|
|||
|
||||
async def async_set_hvac_mode(self, hvac_mode):
|
||||
"""Set new target operation mode."""
|
||||
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)
|
||||
# State is set optimistically in the command above, therefore update
|
||||
|
@ -344,18 +347,32 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateDevice):
|
|||
# the entity state ahead of receiving the confirming push updates
|
||||
self.async_schedule_update_ha_state()
|
||||
|
||||
async def async_turn_on(self):
|
||||
"""Turn device on."""
|
||||
await self._device.switch_on(set_status=True)
|
||||
# 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()
|
||||
|
||||
async def async_turn_off(self):
|
||||
"""Turn device off."""
|
||||
await self._device.switch_off(set_status=True)
|
||||
# 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()
|
||||
|
||||
async def async_update(self):
|
||||
"""Update the calculated fields of the AC."""
|
||||
operations = set()
|
||||
modes = {HVAC_MODE_OFF}
|
||||
for mode in self._device.status.supported_ac_modes:
|
||||
state = AC_MODE_TO_STATE.get(mode)
|
||||
if state is not None:
|
||||
operations.add(state)
|
||||
modes.add(state)
|
||||
else:
|
||||
_LOGGER.debug('Device %s (%s) returned an invalid supported '
|
||||
'AC mode: %s', self._device.label,
|
||||
self._device.device_id, mode)
|
||||
self._hvac_modes = operations
|
||||
self._hvac_modes = modes
|
||||
|
||||
@property
|
||||
def current_temperature(self):
|
||||
|
@ -400,6 +417,8 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateDevice):
|
|||
@property
|
||||
def hvac_mode(self):
|
||||
"""Return current operation ie. heat, cool, idle."""
|
||||
if not self._device.status.switch:
|
||||
return HVAC_MODE_OFF
|
||||
return AC_MODE_TO_STATE.get(self._device.status.air_conditioner_mode)
|
||||
|
||||
@property
|
||||
|
|
|
@ -13,15 +13,15 @@ from homeassistant.components.climate.const import (
|
|||
ATTR_FAN_MODES, ATTR_HVAC_ACTIONS, ATTR_HVAC_MODE, ATTR_HVAC_MODES,
|
||||
ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW, CURRENT_HVAC_IDLE,
|
||||
DOMAIN as CLIMATE_DOMAIN, HVAC_MODE_AUTO, HVAC_MODE_COOL, HVAC_MODE_DRY,
|
||||
HVAC_MODE_FAN_ONLY, HVAC_MODE_HEAT, HVAC_MODE_HEAT_COOL,
|
||||
HVAC_MODE_FAN_ONLY, HVAC_MODE_HEAT, HVAC_MODE_HEAT_COOL, HVAC_MODE_OFF,
|
||||
SERVICE_SET_FAN_MODE, SERVICE_SET_HVAC_MODE, SERVICE_SET_TEMPERATURE,
|
||||
SUPPORT_FAN_MODE, SUPPORT_TARGET_TEMPERATURE,
|
||||
SUPPORT_TARGET_TEMPERATURE_RANGE)
|
||||
from homeassistant.components.smartthings import climate
|
||||
from homeassistant.components.smartthings.const import DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, ATTR_SUPPORTED_FEATURES, ATTR_TEMPERATURE, STATE_OFF,
|
||||
STATE_UNKNOWN)
|
||||
ATTR_ENTITY_ID, ATTR_SUPPORTED_FEATURES, ATTR_TEMPERATURE,
|
||||
SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_UNKNOWN)
|
||||
|
||||
from .conftest import setup_platform
|
||||
|
||||
|
@ -172,7 +172,7 @@ async def test_legacy_thermostat_entity_state(hass, legacy_thermostat):
|
|||
assert state.attributes[ATTR_HVAC_ACTIONS] == 'idle'
|
||||
assert state.attributes[ATTR_HVAC_MODES] == {
|
||||
HVAC_MODE_AUTO, HVAC_MODE_COOL, HVAC_MODE_HEAT_COOL, HVAC_MODE_HEAT,
|
||||
STATE_OFF}
|
||||
HVAC_MODE_OFF}
|
||||
assert state.attributes[ATTR_FAN_MODE] == 'auto'
|
||||
assert state.attributes[ATTR_FAN_MODES] == ['auto', 'on']
|
||||
assert state.attributes[ATTR_TARGET_TEMP_LOW] == 20 # celsius
|
||||
|
@ -184,12 +184,12 @@ async def test_basic_thermostat_entity_state(hass, basic_thermostat):
|
|||
"""Tests the state attributes properly match the thermostat type."""
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[basic_thermostat])
|
||||
state = hass.states.get('climate.basic_thermostat')
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == HVAC_MODE_OFF
|
||||
assert state.attributes[ATTR_SUPPORTED_FEATURES] == \
|
||||
SUPPORT_TARGET_TEMPERATURE_RANGE | SUPPORT_TARGET_TEMPERATURE
|
||||
assert ATTR_HVAC_ACTIONS not in state.attributes
|
||||
assert state.attributes[ATTR_HVAC_MODES] == {
|
||||
STATE_OFF, HVAC_MODE_HEAT_COOL, HVAC_MODE_HEAT, HVAC_MODE_COOL}
|
||||
HVAC_MODE_OFF, HVAC_MODE_HEAT_COOL, HVAC_MODE_HEAT, HVAC_MODE_COOL}
|
||||
assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 21.1 # celsius
|
||||
|
||||
|
||||
|
@ -205,7 +205,7 @@ async def test_thermostat_entity_state(hass, thermostat):
|
|||
assert state.attributes[ATTR_HVAC_ACTIONS] == CURRENT_HVAC_IDLE
|
||||
assert state.attributes[ATTR_HVAC_MODES] == {
|
||||
HVAC_MODE_AUTO, HVAC_MODE_COOL, HVAC_MODE_HEAT, HVAC_MODE_HEAT_COOL,
|
||||
STATE_OFF}
|
||||
HVAC_MODE_OFF}
|
||||
assert state.attributes[ATTR_FAN_MODE] == 'on'
|
||||
assert state.attributes[ATTR_FAN_MODES] == ['auto', 'on']
|
||||
assert state.attributes[ATTR_TEMPERATURE] == 20 # celsius
|
||||
|
@ -245,7 +245,7 @@ async def test_air_conditioner_entity_state(hass, air_conditioner):
|
|||
SUPPORT_TARGET_TEMPERATURE
|
||||
assert sorted(state.attributes[ATTR_HVAC_MODES]) == [
|
||||
HVAC_MODE_COOL, HVAC_MODE_DRY, HVAC_MODE_FAN_ONLY, HVAC_MODE_HEAT,
|
||||
HVAC_MODE_HEAT_COOL]
|
||||
HVAC_MODE_HEAT_COOL, HVAC_MODE_OFF]
|
||||
assert state.attributes[ATTR_FAN_MODE] == 'medium'
|
||||
assert sorted(state.attributes[ATTR_FAN_MODES]) == \
|
||||
['auto', 'high', 'low', 'medium', 'turbo']
|
||||
|
@ -277,8 +277,8 @@ async def test_set_fan_mode(hass, thermostat, air_conditioner):
|
|||
assert state.attributes[ATTR_FAN_MODE] == 'auto', entity_id
|
||||
|
||||
|
||||
async def test_set_operation_mode(hass, thermostat, air_conditioner):
|
||||
"""Test the operation mode is set successfully."""
|
||||
async def test_set_hvac_mode(hass, thermostat, air_conditioner):
|
||||
"""Test the hvac mode is set successfully."""
|
||||
await setup_platform(hass, CLIMATE_DOMAIN,
|
||||
devices=[thermostat, air_conditioner])
|
||||
entity_ids = ['climate.thermostat', 'climate.air_conditioner']
|
||||
|
@ -293,6 +293,20 @@ async def test_set_operation_mode(hass, thermostat, air_conditioner):
|
|||
assert state.state == HVAC_MODE_COOL, entity_id
|
||||
|
||||
|
||||
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])
|
||||
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_OFF},
|
||||
blocking=True)
|
||||
state = hass.states.get('climate.air_conditioner')
|
||||
assert state.state == HVAC_MODE_OFF
|
||||
|
||||
|
||||
async def test_set_temperature_heat_mode(hass, thermostat):
|
||||
"""Test the temperature is set successfully when in heat mode."""
|
||||
thermostat.status.thermostat_mode = 'heat'
|
||||
|
@ -378,6 +392,31 @@ async def test_set_temperature_with_mode(hass, thermostat):
|
|||
assert state.state == HVAC_MODE_HEAT_COOL
|
||||
|
||||
|
||||
async def test_set_turn_off(hass, air_conditioner):
|
||||
"""Test the a/c is turned off successfully."""
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[air_conditioner])
|
||||
state = hass.states.get('climate.air_conditioner')
|
||||
assert state.state == HVAC_MODE_HEAT_COOL
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN, SERVICE_TURN_OFF,
|
||||
blocking=True)
|
||||
state = hass.states.get('climate.air_conditioner')
|
||||
assert state.state == HVAC_MODE_OFF
|
||||
|
||||
|
||||
async def test_set_turn_on(hass, air_conditioner):
|
||||
"""Test the a/c is turned on successfully."""
|
||||
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_TURN_ON,
|
||||
blocking=True)
|
||||
state = hass.states.get('climate.air_conditioner')
|
||||
assert state.state == HVAC_MODE_HEAT_COOL
|
||||
|
||||
|
||||
async def test_entity_and_device_attributes(hass, thermostat):
|
||||
"""Test the attributes of the entries are correct."""
|
||||
await setup_platform(hass, CLIMATE_DOMAIN, devices=[thermostat])
|
||||
|
|
Loading…
Reference in New Issue