Check that a state update is valid before updating device values#116
Open
anderjoshai wants to merge 1 commit intoflz:masterfrom
Open
Check that a state update is valid before updating device values#116anderjoshai wants to merge 1 commit intoflz:masterfrom
anderjoshai wants to merge 1 commit intoflz:masterfrom
Conversation
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:
The Jandy api sends out a garbage state update after the lights are set (for some reason). We need to ignore these messages, otherwise the invalid system state will cause all commands for the next ~30 seconds to fail in strange ways.
For example, failing to set the value of lights and switches with the error "'
NaN' is not a valid Aqualink state" OrValueError: could not convert string to float: ''. See related open HA issue described: home-assistant/core#156960Here is what the update from the API looks like after turning a light on or off:
Solution:
The jandy api provides two separate sets of update data. One is "home screen" and one is "devices screen" each corresponding to a page in the jandy native mobile app.
Devices Screen:
After a light is set, the devices screen update will have mostly 'NaN' values as the update data. However, it may also have various random numerical value or empty values as well. If we see any NaN values in the update, we can assume that the entire update is unreliable and skip it. This circumvents the issue of needing to know whether a devices' state should be in the list of valid "Aqualink states" or if it should be a numerical value, or if it should allow empty values. If it is not flagged as a bad update by having NaN values, we will simply assume that the jandy api is giving us good data and allow it all through.
Home Screen:
After a light is set, the home screen will have mostly empty values, however sadly the presence of empty values is not a good way to determine if the update is bad since there will likely always be some empty values present depending on how the system is configured. And so in this case, we simply skip any empty values on an individual basis. However, I allow empty values through for pool_temp or spa_temp, because an empty update is valid for current temperature depending on the mode of the pool/spa system.
Note: This fix only applies to the iaqua system, a similar fix may be needed for other systems
Confidence Testing:
Able to switch lights on and off, and control other switches immediately after toggling a light, without any errors.