-
Notifications
You must be signed in to change notification settings - Fork 130
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
Update device.py #68
Update device.py #68
Conversation
If the device is an input instead of a lamp then self.raw is None and has_light_control should return False. This change caters for that.
Yay to your first PR! 👍 Let's try to make this thing past the checks. |
pytradfri/device.py
Outdated
@@ -48,8 +48,7 @@ def reachable(self): | |||
|
|||
@property | |||
def has_light_control(self): | |||
return (ATTR_LIGHT_CONTROL in self.raw and | |||
len(self.raw.get(ATTR_LIGHT_CONTROL)) > 0) | |||
return (self.raw is not None and len(self.raw.get(ATTR_LIGHT_CONTROL,"")) > 0) |
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.
Travis returned these errors:
1.60s$ flake8
./pytradfri/device.py:51:77: E231 missing whitespace after ','
./pytradfri/device.py:51:80: E501 line too long (86 > 79 charact```
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.
Which is interpreted as you need to break the line into two as a row many not exceed 79 chars and you need to write (ATTR_LIGHT_CONTROL, "")
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.
When I started doing this, I quickly realized the power of installing pylint and then running:
pylint device.py
It will list the syntax errors (if any) in your code. Travis runs the same checks and will not green flag the change until all tests have pasts. Green flags is, in turn, needed before a merge of the PR is done.
pytradfri/device.py
Outdated
@@ -48,7 +48,8 @@ def reachable(self): | |||
|
|||
@property | |||
def has_light_control(self): | |||
return (self.raw is not None and len(self.raw.get(ATTR_LIGHT_CONTROL,"")) > 0) | |||
return (self.raw is not None and |
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.
Trailing whitespace after "and"
pytradfri/device.py
Outdated
@@ -48,7 +48,8 @@ def reachable(self): | |||
|
|||
@property | |||
def has_light_control(self): | |||
return (self.raw is not None and len(self.raw.get(ATTR_LIGHT_CONTROL,"")) > 0) | |||
return (self.raw is not None and | |||
len(self.raw.get(ATTR_LIGHT_CONTROL,"")) > 0) |
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 whitespace after comma
One down, two to go 👍 If you click "Details" where it says "The Travis CI build failed" on this page and then click one of the rows, for instance where it reads Python 3.6, and then scroll down to where it says |
Great! We should also add a test for the case where the device is an input instead of a lamp just to make sure the code works as expected. Then we're good to merge! |
@rudyvan I'm happy to help out if you want some aid in adding the test |
I would think that a sensor does not have the lightcontrol attribute in the raw variable, so the updated test already caters for that scenario. I would not know what more differentiate between an input and a light and would make the test more complete. I read somewhere that the tradfri system does not return input data back to the gateway. |
Yes, you are probably right, just want to make sure I'm not messing anything up here. 😄 If I understand correctly, your ROOT_DEVICES (15001) looked something like this? And there was nothing else in ROOT_DEVICES?
|
my devs look like the following:
how do i get my ROOT_DEVICES? |
This actually serves as a pretty good example (the initial analysis that inspired this lib): So, what you listed is the content of ROOT_DEVICES (15001):
I'm thinking a test to make sure your code works as expected might then look something like this, where I'm uncertain what has_light_control returns?
|
Dear Patrick, what i understand you mean is to check if there is ONLY ONE endpoint in the gateway at 15001 which is either a remote or a motion sensor but no light. Indeed the has_light_control() code should work in these circumstances on that single non bulb device. Adding an assert statement is not needed in my opinion. KR Rudy |
You are right, my apologies! Your improvement is now released on pypi as 3.0.2. Thank you for contributing to pytradfri! 👍 |
If the device is an input instead of a lamp then self.raw is None and has_light_control should return False.
This change caters for that scenario.