Refactor temperature retrieval with None check - #157
Open
digidolphin wants to merge 1 commit into
Open
Conversation
When the stored value is `0`, the condition evaluates to `False` (0 is falsy in Python), so the restore is skipped and the entity keeps the `DEFAULT_TEMP` (21) assigned in `__init__`. The `DEFAULT_TEMP` fallback in `.get()` is redundant and has been removed: if the attribute is missing, the default set in `__init__` already applies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the target temperature is set to
0and Home Assistant restarts,the climate entity resets to
21(DEFAULT_TEMP). Any other value(e.g. 1–15) is restored correctly — only
0is affected.Cause
In
async_added_to_hassthe restored temperature is checked fortruthiness via the walrus operator:
When the stored value is
0, the condition evaluates toFalse(0 is falsy in Python), so the restore is skipped and the entity
keeps the
DEFAULT_TEMP(21) assigned in__init__.Fix
Check explicitly for
Noneinstead of truthiness:The
DEFAULT_TEMPfallback in.get()is redundant and has beenremoved: if the attribute is missing, the default set in
__init__already applies.
Testing