-
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
Lamp value range validation without mistakes #140
Lamp value range validation without mistakes #140
Conversation
Rebase fork
Also: Fixed references to Hue and Sat that where flipped.
There are some lamp values that can be set individually, but others can't. XY: When setting X you must also set Y, otherwise Y=0 When setting either of these 4 values as |
pytradfri/const.py
Outdated
@@ -56,8 +56,8 @@ | |||
ATTR_LIGHT_COLOR_HEX = "5706" # string representing a value in hex | |||
ATTR_LIGHT_COLOR_X = "5709" | |||
ATTR_LIGHT_COLOR_Y = "5710" | |||
ATTR_LIGHT_COLOR_HUE = "5707" | |||
ATTR_LIGHT_COLOR_SATURATION = "5708" | |||
ATTR_LIGHT_COLOR_HUE = "5708" |
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.
Are you certain about this? Looking at the constants in the Android app, it should be the other way around: https://hastebin.com/zofoqucibe.php
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.
You are right, I've changed a bit too much here. The other places I flipped hue with sat are correct though.
@Lakitna can you please also add a few tests for the stuff you've added? |
tests/test_device.py
Outdated
dev.light_control._value_validate(9, rnge) | ||
with pytest.raises(ValueError) as e_info: | ||
dev.light_control._value_validate(-1, rnge) | ||
with pytest.raises(ValueError) as e_info: |
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.
local variable 'e_info' is assigned to but never used
Added default `None` for brightness in `set_hsb()`. This is the only value that's not required here.
While I'm at it... These functions are very similar anyways.
Trying to minimize repetitive tests of the same function.
|
||
command = dev.light_control.set_hex_color("RandomString") | ||
data = command.data[ATTR_LIGHT_CONTROL][0] | ||
assert len(data) is 1 |
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.
Is it a problem that every string is accepted in set_hex_color
? Perhaps we should limit the string length to 6, that could prevent accidental network overload.
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.
Not needed now, let's do it in another PR later on.
@Lakitna I guess this can be merged now? |
Yes, if you agree it can be merged :) |
Thank you @Lakitna! Adding those tests is very appreciated. I've pushed this to pypi now. |
I've made a mistake validating what I did in #139.