Restore SmartThings A/C on/off services (#25259)

* Restore ST A/C on/off services

* Use correct OFF const

* Support AC HVAC_MODE_OFF
This commit is contained in:
Andrew Sayre 2019-07-18 13:14:58 -04:00 committed by Paulus Schoutsen
parent 516bab9969
commit cfc2c58fe0
2 changed files with 71 additions and 13 deletions

View file

@ -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