Fix lookin set temperature when device is off (#61411)

This commit is contained in:
J. Nick Koston 2021-12-09 21:35:07 -10:00 committed by GitHub
parent 9a46d238f7
commit fe17c9ffb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@ from aiolookin import Climate, MeteoSensor, SensorID
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (
ATTR_HVAC_MODE,
FAN_AUTO,
FAN_HIGH,
FAN_LOW,
@ -151,6 +152,28 @@ class ConditionerEntity(LookinCoordinatorEntity, ClimateEntity):
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
return
self._climate.temp_celsius = int(temperature)
lookin_index = LOOKIN_HVAC_MODE_IDX_TO_HASS
if hvac_mode := kwargs.get(ATTR_HVAC_MODE):
self._climate.hvac_mode = HASS_TO_LOOKIN_HVAC_MODE[hvac_mode]
elif self._climate.hvac_mode == lookin_index.index(HVAC_MODE_OFF):
#
# If the device is off, and the user didn't specify an HVAC mode
# (which is the default when using the HA UI), the device won't turn
# on without having an HVAC mode passed.
#
# We picked the hvac mode based on the current temp if its available
# since only some units support auto, but most support either heat
# or cool otherwise we set auto since we don't have a way to make
# an educated guess.
#
meteo_data: MeteoSensor = self._meteo_coordinator.data
current_temp = meteo_data.temperature
if not current_temp:
self._climate.hvac_mode = lookin_index.index(HVAC_MODE_AUTO)
elif current_temp >= self._climate.temp_celsius:
self._climate.hvac_mode = lookin_index.index(HVAC_MODE_COOL)
else:
self._climate.hvac_mode = lookin_index.index(HVAC_MODE_HEAT)
await self._async_update_conditioner()
async def async_set_fan_mode(self, fan_mode: str) -> None: