Fix race condition in Advantage Air (#53439)

This commit is contained in:
Brett 2021-08-10 13:21:24 +10:00 committed by GitHub
parent f60fbf7197
commit b76899f546
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,7 +15,6 @@ from homeassistant.components.climate.const import (
SUPPORT_TARGET_TEMPERATURE,
)
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS
from homeassistant.core import callback
from homeassistant.helpers import entity_platform
from .const import (
@ -166,19 +165,22 @@ class AdvantageAirZone(AdvantageAirClimateEntity):
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}'
)
async def async_added_to_hass(self):
"""When entity is added to hass."""
self.async_on_remove(self.coordinator.async_add_listener(self._update_callback))
@callback
def _update_callback(self) -> None:
"""Load data from integration."""
self._attr_current_temperature = self._zone["measuredTemp"]
self._attr_target_temperature = self._zone["setTemp"]
self._attr_hvac_mode = HVAC_MODE_OFF
@property
def hvac_mode(self):
"""Return the current state as HVAC mode."""
if self._zone["state"] == ADVANTAGE_AIR_STATE_OPEN:
self._attr_hvac_mode = HVAC_MODE_FAN_ONLY
self.async_write_ha_state()
return HVAC_MODE_FAN_ONLY
return HVAC_MODE_OFF
@property
def current_temperature(self):
"""Return the current temperature."""
return self._zone["measuredTemp"]
@property
def target_temperature(self):
"""Return the target temperature."""
return self._zone["setTemp"]
async def async_set_hvac_mode(self, hvac_mode):
"""Set the HVAC Mode and State."""