Fixed race condition in Generic Thermostat#15784
Fixed race condition in Generic Thermostat#15784amelchio merged 2 commits intohome-assistant:devfrom
Conversation
|
@amelchio @balloob @MartinHjelmare |
amelchio
left a comment
There was a problem hiding this comment.
Looks good to me.
I enjoyed your thorough description, it makes reading the diff that much easier.
| self.heater_entity_id) | ||
| self._heater_turn_off() | ||
| await self._async_heater_turn_off() | ||
| elif time is not None: |
There was a problem hiding this comment.
This looks a bit odd, maybe add a comment or named variable that tells the reader that this is the keepalive case?
There was a problem hiding this comment.
You're right, I'll add a comment.
| (not self.ac_mode and too_cold): | ||
| _LOGGER.info("Turning on heater %s", self.heater_entity_id) | ||
| self._heater_turn_on() | ||
| await self._async_heater_turn_on() |
There was a problem hiding this comment.
You have removed the logging that mentions AC and I think that is okay because the configuration for the entity_id is indeed named heater, even in ac_mode.
There was a problem hiding this comment.
Yup. I hope we can come up with a better, more neutral naming convention (as heater is very, well, heating-oriented :) ), and when we do, I'll update the logging accordingly.
* Fixed race condition in Generic Thermostat * Added a comment to clarify the meaning of the `time` argument.
* Fixed race condition in Generic Thermostat * Added a comment to clarify the meaning of the `time` argument.
Description:
Generic Thermostat has a race condition in its keepalive feature when the switching of the heater and the keepalive event happen at the same time. Here's a basic outline of the problem:
On top of the almost instantaneous turning on and off of the compressor (which can't be very healthy for it), the heater gets stuck in the old state for another
min_cycle_duration, causing the temperature to drift further away from the target.The issue is solved in this pull request by introducing a lock. Due to the
asyncnature of the lock, the_async_control_heatingis rewritten asasync. Consequently, all methods that it calls are madeasync, and all the methods that call those methods, and so on. Currently, there's a mix ofasyncand regular methods throughout the code - it's messy, but will be addressed in a future pull request, to limit the number of reviewable changes in this PR.Additionally,
_async_control_heatingwas refactored to be more concise, and accommodate the old keepalive functionality (the oldasync_keep_aliveis now obsolete and, therefore, removed).Checklist:
tox. Your PR cannot be merged unless tests pass