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

Additional properties of the Xiaomi Air Purifier 2 introduced #132

Merged
merged 11 commits into from Nov 26, 2017

Conversation

syssi
Copy link
Collaborator

@syssi syssi commented Nov 26, 2017

Some comments improved.
Some code clean-up.

@@ -1,5 +1,6 @@
import logging
import enum
import math

Choose a reason for hiding this comment

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

'math' imported but unused

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.009%) to 46.029% when pulling e516138 on syssi:feature/update-some-comments-and-fixmes into 3bed026 on rytilahti:master.

1 similar comment
@coveralls
Copy link

coveralls commented Nov 26, 2017

Coverage Status

Coverage decreased (-0.009%) to 46.029% when pulling e516138 on syssi:feature/update-some-comments-and-fixmes into 3bed026 on rytilahti:master.

@coveralls
Copy link

coveralls commented Nov 26, 2017

Coverage Status

Coverage decreased (-0.03%) to 46.008% when pulling d21e954 on syssi:feature/update-some-comments-and-fixmes into 3bed026 on rytilahti:master.


assert self.is_on() is True
assert self.state().temperature == \
self.device.start_state["temp_dec"] / 10.0

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

assert child_lock() == True

self.device.set_child_lock(False)
assert child_lock() == False

Choose a reason for hiding this comment

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

comparison to False should be 'if cond is False:' or 'if not cond:'

return self.device.status().child_lock

self.device.set_child_lock(True)
assert child_lock() == True

Choose a reason for hiding this comment

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

comparison to True should be 'if cond is True:' or 'if cond:'

assert buzzer() == True

self.device.set_buzzer(False)
assert buzzer() == False

Choose a reason for hiding this comment

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

comparison to False should be 'if cond is False:' or 'if not cond:'

return self.device.status().buzzer

self.device.set_buzzer(True)
assert buzzer() == True

Choose a reason for hiding this comment

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

comparison to True should be 'if cond is True:' or 'if cond:'

assert led() == True

self.device.set_led(False)
assert led() == False

Choose a reason for hiding this comment

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

comparison to False should be 'if cond is False:' or 'if not cond:'

assert self.state().mode == OperationMode(self.device.start_state["mode"])
assert self.state().favorite_level == self.device.start_state["favorite_level"]
assert self.state().filter_life_remaining == self.device.start_state["filter1_life"]
assert self.state().filter_hours_used == self.device.start_state["f1_hour_used"]

Choose a reason for hiding this comment

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

line too long (88 > 79 characters)

assert self.state().humidity == self.device.start_state["humidity"]
assert self.state().mode == OperationMode(self.device.start_state["mode"])
assert self.state().favorite_level == self.device.start_state["favorite_level"]
assert self.state().filter_life_remaining == self.device.start_state["filter1_life"]

Choose a reason for hiding this comment

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

line too long (92 > 79 characters)

assert self.state().temperature == self.device.start_state["temp_dec"] / 10.0
assert self.state().humidity == self.device.start_state["humidity"]
assert self.state().mode == OperationMode(self.device.start_state["mode"])
assert self.state().favorite_level == self.device.start_state["favorite_level"]

Choose a reason for hiding this comment

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

line too long (87 > 79 characters)

assert self.state().average_aqi == self.device.start_state["average_aqi"]
assert self.state().temperature == self.device.start_state["temp_dec"] / 10.0
assert self.state().humidity == self.device.start_state["humidity"]
assert self.state().mode == OperationMode(self.device.start_state["mode"])

Choose a reason for hiding this comment

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

line too long (82 > 79 characters)

assert self.is_on() is True
assert self.state().aqi == self.device.start_state["aqi"]
assert self.state().average_aqi == self.device.start_state["average_aqi"]
assert self.state().temperature == self.device.start_state["temp_dec"] / 10.0

Choose a reason for hiding this comment

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

line too long (85 > 79 characters)

@coveralls
Copy link

coveralls commented Nov 26, 2017

Coverage Status

Coverage increased (+3.4%) to 49.448% when pulling 85b0f10 on syssi:feature/update-some-comments-and-fixmes into 3bed026 on rytilahti:master.

self.device.state["bright"] = self.device.state["led_b"]
del self.device.state["led_b"]

assert self.state().led_brightness == LedBrightness(self.device.start_state["led_b"])

Choose a reason for hiding this comment

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

line too long (93 > 79 characters)


# The LED brightness of a Air Purifier Pro cannot be set so far.
self.device.set_led(True)
assert led() == True

Choose a reason for hiding this comment

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

comparison to True should be 'if cond is True:' or 'if cond:'

@coveralls
Copy link

Coverage Status

Coverage increased (+3.9%) to 49.924% when pulling e5c83c3 on syssi:feature/update-some-comments-and-fixmes into 3bed026 on rytilahti:master.

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.

Thanks for fixing docstrings and new tests! I added a couple of comments behind, feel free to merge if you consider things are fine as they are / after changing those (and fixing those hound warnings where deemed necessary, i.e. the None checks at least) :-)


values = self.send(
"get_prop",
properties
properties[0:13]
Copy link
Owner

Choose a reason for hiding this comment

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

Mind leaving a comment behind to explain why using only a slice here? Same below too.


# This is the property name of the Air Purifier Pro
if self.data["bright"] is not None:
return LedBrightness(self.data["bright"])
Copy link
Owner

Choose a reason for hiding this comment

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

Does this mean that when the device is not air purifier pro, the "led_b" will be empty? If yes, then it's fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep. The air purifier provides a "bright" property XOR a "led_b" property.

return self.device.status().favorite_level

self.device.set_favorite_level(1)
assert favorite_level() == 1
Copy link
Owner

Choose a reason for hiding this comment

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

Is it known what values are allowed for favorite level? If yes, it makes probably sense to add an exception if out-of-range values are inputed, and to add a test for that also here (https://docs.pytest.org/en/latest/assert.html#assertions-about-expected-exceptions).

@coveralls
Copy link

coveralls commented Nov 26, 2017

Coverage Status

Coverage increased (+3.8%) to 49.867% when pulling 7b96492 on syssi:feature/update-some-comments-and-fixmes into 3bed026 on rytilahti:master.

del self.device.state["led_b"]

assert self.state().led_brightness == \
LedBrightness(self.device.start_state["led_b"])

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent


assert self.is_on() is True
assert self.state().aqi == self.device.start_state["aqi"]
assert self.state().average_aqi == self.device.start_state["average_aqi"]

Choose a reason for hiding this comment

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

line too long (81 > 79 characters)

del self.device.state["led_b"]

assert self.state().led_brightness == \
LedBrightness(self.device.start_state["led_b"])

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent


assert self.is_on() is True
assert self.state().aqi == self.device.start_state["aqi"]
assert self.state().average_aqi == self.device.start_state["average_aqi"]

Choose a reason for hiding this comment

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

line too long (81 > 79 characters)

@coveralls
Copy link

coveralls commented Nov 26, 2017

Coverage Status

Coverage increased (+4.04%) to 50.075% when pulling fc596f8 on syssi:feature/update-some-comments-and-fixmes into 3bed026 on rytilahti:master.

@coveralls
Copy link

coveralls commented Nov 26, 2017

Coverage Status

Coverage increased (+4.04%) to 50.075% when pulling 3911b40 on syssi:feature/update-some-comments-and-fixmes into 3bed026 on rytilahti:master.

def test_status_string(self):
self.device._reset_state()

assert self.state().__str__
Copy link
Owner

Choose a reason for hiding this comment

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

The status string should be __repr__ instead of __str__, right? https://stackoverflow.com/questions/1436703/difference-between-str-and-repr-in-python


use_time and motor1_speed is missing because a request is limitted
to 16 properties. We request 15 properties at the moment.
A request is limitted to 16 properties.
Copy link
Owner

Choose a reason for hiding this comment

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

limited

@syssi syssi force-pushed the feature/update-some-comments-and-fixmes branch from 3911b40 to cf5a544 Compare November 26, 2017 20:45
@coveralls
Copy link

coveralls commented Nov 26, 2017

Coverage Status

Coverage increased (+3.2%) to 57.797% when pulling cf5a544 on syssi:feature/update-some-comments-and-fixmes into 3df66fd on rytilahti:master.

@coveralls
Copy link

coveralls commented Nov 26, 2017

Coverage Status

Coverage increased (+3.2%) to 57.797% when pulling 9f1e4c1 on syssi:feature/update-some-comments-and-fixmes into 3df66fd on rytilahti:master.

@coveralls
Copy link

coveralls commented Nov 26, 2017

Coverage Status

Coverage increased (+3.3%) to 57.854% when pulling 779bb83 on syssi:feature/update-some-comments-and-fixmes into 3df66fd on rytilahti:master.

@coveralls
Copy link

coveralls commented Nov 26, 2017

Coverage Status

Coverage increased (+3.2%) to 57.797% when pulling c22086a on syssi:feature/update-some-comments-and-fixmes into 3df66fd on rytilahti:master.

@syssi syssi merged commit 5ba379e into rytilahti:master Nov 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants