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

Fix water_level calculation for humidifiers #1140

Merged
merged 12 commits into from Oct 3, 2021
Merged

Fix water_level calculation for humidifiers #1140

merged 12 commits into from Oct 3, 2021

Conversation

bieniu
Copy link
Contributor

@bieniu bieniu commented Sep 17, 2021

This PR fixes the calculation of the water_level according to the source of Mi Home app here and here.

Fix: #1135

@bieniu
Copy link
Contributor Author

bieniu commented Sep 23, 2021

@rytilahti Can you help me? Docstring CI fails on multiple files. Should I improve them all in this PR?

@rytilahti
Copy link
Owner

@bieniu yeah, it's better to fix all affected files in cases like this. I'm not sure why it wasn't fixed automatically (and why the doc8 problem got in in the first place), but I just fixed it by running pre-commit run -a & modifying the readme manually.

@codecov-commenter
Copy link

codecov-commenter commented Sep 26, 2021

Codecov Report

Merging #1140 (8497e0d) into master (43d9eaf) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1140      +/-   ##
==========================================
+ Coverage   76.06%   76.10%   +0.03%     
==========================================
  Files          76       76              
  Lines        8921     8926       +5     
  Branches      748      750       +2     
==========================================
+ Hits         6786     6793       +7     
+ Misses       1951     1950       -1     
+ Partials      184      183       -1     
Impacted Files Coverage Δ
miio/airhumidifier.py 90.00% <100.00%> (+0.10%) ⬆️
miio/airhumidifier_miot.py 84.51% <100.00%> (+1.62%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 43d9eaf...8497e0d. Read the comment docs.

Copy link
Owner

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

Do you mind adding some tests for the behavior, so that it won't break in the future?

"""
depth = self.data.get("depth")
if depth is not None and depth <= 125:
return int(depth / 1.25)
return int(max(min(depth / 1.2, 100), 0))
Copy link
Owner

Choose a reason for hiding this comment

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

Why use max(val, 0) here, avoiding negative values?

Copy link
Contributor Author

@bieniu bieniu Sep 28, 2021

Choose a reason for hiding this comment

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

Because we have this

        else if (value === -1) {
          value = 0;
        }

in the app source.

Copy link
Owner

Choose a reason for hiding this comment

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

Sorry for the delay, I see. I think it would be the best to inverse the condition and bail out early

if depth is None or depth < 0:
    return None

return <real value here>

Copy link
Owner

Choose a reason for hiding this comment

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

I did simplify the logic a bit. If it looks okay to you, I think this is ready to be merged after the tests are passing.

@bieniu
Copy link
Contributor Author

bieniu commented Sep 28, 2021

Yes, I'll try to add some tests.

miio/tests/test_airhumidifier.py Outdated Show resolved Hide resolved
miio/tests/test_airhumidifier.py Outdated Show resolved Hide resolved
miio/tests/test_airhumidifier_miot.py Outdated Show resolved Hide resolved
@bieniu
Copy link
Contributor Author

bieniu commented Oct 3, 2021

@rytilahti Wow, you were busy today :) Great work!

@rytilahti rytilahti merged commit b633844 into rytilahti:master Oct 3, 2021
@bieniu bieniu deleted the bieniu/fix_water_level branch October 4, 2021 04:25
@rytilahti rytilahti added the bug label Nov 30, 2021
@rytilahti rytilahti mentioned this pull request Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect water level of air humidifiers
3 participants