-
Notifications
You must be signed in to change notification settings - Fork 61
Add a granularity property to round to nearest 0.5C #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,10 +157,19 @@ def queue_command(self, name: str, value) -> None: | |
| # Device mode is set using t_control_value | ||
| if issubclass(data_type, enum.Enum): | ||
| data_value = data_type[value] | ||
| elif data_type is int and type(value) is str and '.' in value: | ||
| # Round rather than fail if the input is a float. | ||
| # This is commonly the case for temperatures converted by HA from Celsius. | ||
| data_value = round(float(value)) | ||
| elif data_type is int: | ||
| # incoming data may be an int or float; it's likely to be a float for | ||
| # temperatures converted by HA to/from Celsius. | ||
| float_val = float(value) | ||
|
|
||
| # Granularity may be 0.5, in which case we round to the nearest 0.5, then apply precision | ||
| granularity = self._properties.get_granularity(name) | ||
| precision = self._properties.get_precision(name) | ||
| float_val = (round(float_val / granularity) * granularity) / precision | ||
|
|
||
| # Update value precision for value to be sent to the A/C | ||
| # We assume that only int types have a precision value | ||
| data_value = round(float_val) | ||
| else: | ||
| data_value = data_type(value) | ||
|
|
||
|
|
@@ -174,11 +183,6 @@ def queue_command(self, name: str, value) -> None: | |
| data_value = data_value.value | ||
| typed_value = data_type[value] | ||
|
|
||
| # Update value precision for value to be sent to the A/C | ||
| precision = self._properties.get_precision(name) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since precision only makes sense if the property is an |
||
| if precision != 1: | ||
| data_value = round(data_value / precision) | ||
|
|
||
| command = self._build_command(name, data_value) | ||
| # There are (usually) no acks on commands, so also queue an update to the | ||
| # property, to be run once the command is sent. | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason to check for "." here, if it's an int value that doesn't have a decimal place the float logic won't affect it.