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

Lamp value range validation without mistakes #140

Merged

Conversation

Lakitna
Copy link
Contributor

@Lakitna Lakitna commented Jan 19, 2018

I've made a mistake validating what I did in #139.

Lakitna and others added 3 commits January 17, 2018 14:41
Also: Fixed references to Hue and Sat that where flipped.
@Lakitna
Copy link
Contributor Author

Lakitna commented Jan 19, 2018

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
HS: When setting Hue you must also set Saturation, otherwise Saturation=0

When setting either of these 4 values as None they will become 0.

@coveralls
Copy link

coveralls commented Jan 19, 2018

Coverage Status

Coverage decreased (-0.1%) to 60.415% when pulling 8710707 on Lakitna:Lamp-value-range-validation into 807ef60 on ggravlingen:master.

@@ -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"
Copy link
Member

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

Copy link
Contributor Author

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.

@ggravlingen
Copy link
Member

@Lakitna can you please also add a few tests for the stuff you've added?

@ggravlingen ggravlingen changed the title Lamp value range validation without mistakes WIP: Lamp value range validation without mistakes Jan 20, 2018
@coveralls
Copy link

coveralls commented Jan 20, 2018

Coverage Status

Coverage decreased (-0.1%) to 60.415% when pulling 9d83e9c on Lakitna:Lamp-value-range-validation into 807ef60 on ggravlingen:master.

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:

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

@coveralls
Copy link

coveralls commented Jan 20, 2018

Coverage Status

Coverage increased (+0.08%) to 60.622% when pulling 6dee151 on Lakitna:Lamp-value-range-validation into 807ef60 on ggravlingen:master.

Added default `None` for brightness in `set_hsb()`. This is the only value that's not required here.
@coveralls
Copy link

coveralls commented Jan 20, 2018

Coverage Status

Coverage increased (+1.01%) to 61.554% when pulling 7f73237 on Lakitna:Lamp-value-range-validation into 807ef60 on ggravlingen:master.

While I'm at it... These functions are very similar anyways.
@coveralls
Copy link

coveralls commented Jan 20, 2018

Coverage Status

Coverage increased (+2.8%) to 63.316% when pulling 8d6b421 on Lakitna:Lamp-value-range-validation into 807ef60 on ggravlingen:master.

Trying to minimize repetitive tests of the same function.
@coveralls
Copy link

coveralls commented Jan 20, 2018

Coverage Status

Coverage increased (+2.8%) to 63.316% when pulling bf92e91 on Lakitna:Lamp-value-range-validation into 807ef60 on ggravlingen:master.


command = dev.light_control.set_hex_color("RandomString")
data = command.data[ATTR_LIGHT_CONTROL][0]
assert len(data) is 1
Copy link
Contributor Author

@Lakitna Lakitna Jan 20, 2018

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.

Copy link
Member

@ggravlingen ggravlingen Jan 20, 2018

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.

@coveralls
Copy link

coveralls commented Jan 20, 2018

Coverage Status

Coverage increased (+2.9%) to 63.42% when pulling 033c93b on Lakitna:Lamp-value-range-validation into 807ef60 on ggravlingen:master.

@ggravlingen
Copy link
Member

@Lakitna I guess this can be merged now?

@Lakitna
Copy link
Contributor Author

Lakitna commented Jan 20, 2018

Yes, if you agree it can be merged :)

@ggravlingen ggravlingen changed the title WIP: Lamp value range validation without mistakes Lamp value range validation without mistakes Jan 20, 2018
@ggravlingen ggravlingen merged commit 4a8e2e6 into home-assistant-libs:master Jan 20, 2018
@ggravlingen
Copy link
Member

Thank you @Lakitna! Adding those tests is very appreciated. I've pushed this to pypi now.

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.

4 participants