Skip to content

Fix water_level calculation for humidifiers - #1140

Merged
rytilahti merged 12 commits into
rytilahti:masterfrom
bieniu:bieniu/fix_water_level
Oct 3, 2021
Merged

Fix water_level calculation for humidifiers#1140
rytilahti merged 12 commits into
rytilahti:masterfrom
bieniu:bieniu/fix_water_level

Conversation

@bieniu

@bieniu bieniu commented Sep 17, 2021

Copy link
Copy Markdown
Contributor

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

Fix: #1135

@bieniu

bieniu commented Sep 23, 2021

Copy link
Copy Markdown
Contributor Author

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

@rytilahti

Copy link
Copy Markdown
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

codecov-commenter commented Sep 26, 2021

Copy link
Copy Markdown

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.

@rytilahti rytilahti left a comment

Copy link
Copy Markdown
Owner

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?

Comment thread miio/airhumidifier.py Outdated
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
Copy Markdown
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?

@bieniu bieniu Sep 28, 2021

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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
Copy Markdown
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

bieniu commented Sep 28, 2021

Copy link
Copy Markdown
Contributor Author

Yes, I'll try to add some tests.

Comment thread miio/tests/test_airhumidifier.py Outdated
Comment thread miio/tests/test_airhumidifier.py Outdated
Comment thread miio/tests/test_airhumidifier_miot.py Outdated
@bieniu

bieniu commented Oct 3, 2021

Copy link
Copy Markdown
Contributor Author

@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