Skip to content
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

Use round instead of int #371

Merged
merged 1 commit into from
Oct 21, 2021
Merged

Conversation

DurgNomis-drol
Copy link
Collaborator

@DurgNomis-drol DurgNomis-drol commented Oct 20, 2021

Fixes #359 (comment)

Should we also round the float to less decimals?

@DurgNomis-drol DurgNomis-drol added the bug Something isn't working label Oct 20, 2021
@DurgNomis-drol DurgNomis-drol self-assigned this Oct 20, 2021
Copy link
Owner

@leikoilja leikoilja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for the quickfix! 🚀 Just a small comment and we good to merge

@@ -342,7 +342,7 @@ async def update_alarm_volume(
if JSON_ALARM_VOLUME in response:
if polling:
volume_raw = str(response[JSON_ALARM_VOLUME])
volume_int = int(float(volume_raw) * 100)
volume_int = round(float(volume_raw) * 100)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is volume_int variable and we made Number entity to store the values as integer we would still need to cast it to int here, since round returns float as 88.0 for example :)

Suggested change
volume_int = round(float(volume_raw) * 100)
volume_int = int(round(volume_raw * 100))

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure i understand what you mean, round() returns an integer if number of digits are not defined.

>>> round(2.555)
3

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha, what de heck 😄 please just disregard my comment, @DurgNomis-drol, @KapJI
image
sorry, i got quick reference from here and used the python instance that I had by hand... and guess where the magic is... we still use python 2.7 at work 🤦

haha, you're absolutely right, in python 3 it's integer:
image
Sorry my fault 😄

Copy link
Owner

@leikoilja leikoilja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, apart from the misunderstanding i had, it's perf 🚀 thanks for implementing it

@leikoilja leikoilja merged commit 099b7da into leikoilja:master Oct 21, 2021
@DurgNomis-drol DurgNomis-drol deleted the fix-number branch October 21, 2021 20:12
@DurgNomis-drol
Copy link
Collaborator Author

@leikoilja Haha 😆 No problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Volume is not a percentage
2 participants