-
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
Complying to #65 - reading parameters of different bulbs types #67
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
db5065c
Test data for different lights added
matemaciek ab535cf
Test data for different lights added
matemaciek 2a3ee98
Calculating missing hex values
matemaciek 28f990f
Lets comply to flake
matemaciek 2ffa1f2
Add _raw properties
matemaciek df25c06
Let's flake again
matemaciek 902e0dd
LightControl can_set_* properties
matemaciek 483b54c
Rename properties according to review
matemaciek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
from pytradfri.device import Device | ||
|
||
LIGHT_W = { | ||
'3': { | ||
'0': 'IKEA of Sweden', | ||
'1': 'TRADFRI bulb E27 opal 1000lm', | ||
'2': '', | ||
'3': '1.2.214', | ||
'6': 1 | ||
}, | ||
'3311': [ | ||
{ | ||
'5850': 1, | ||
'5851': 96, | ||
'9003': 0 | ||
} | ||
], | ||
'5750': 2, | ||
'9001': 'Light W name', | ||
'9002': 1494695583, | ||
'9003': 65545, | ||
'9019': 1, | ||
'9020': 1507969307, | ||
'9054': 0 | ||
} | ||
|
||
LIGHT_WS = { | ||
'3': { | ||
'0': 'IKEA of Sweden', | ||
'1': 'TRADFRI bulb E27 WS opal 980lm', | ||
'2': '', | ||
'3': '1.2.217', | ||
'6': 1 | ||
}, | ||
'3311': [ | ||
{ | ||
'5706': 'f1e0b5', | ||
'5707': 0, | ||
'5708': 0, | ||
'5709': 30138, | ||
'5710': 26909, | ||
'5711': 0, | ||
'5850': 1, | ||
'5851': 157, | ||
'9003': 0 | ||
} | ||
], | ||
'5750': 2, | ||
'9001': 'Light WS name', | ||
'9002': 1491149680, | ||
'9003': 65537, | ||
'9019': 1, | ||
'9020': 1507970265, | ||
'9054': 0 | ||
} | ||
|
||
LIGHT_WS_CUSTOM_COLOR = { | ||
'3': { | ||
'6': 1, | ||
'0': 'IKEA of Sweden', | ||
'1': 'TRADFRI bulb E27 WS opal 980lm', | ||
'2': '', | ||
'3': '1.2.217' | ||
}, | ||
'3311': [ | ||
{ | ||
'5706': '0', | ||
'5707': 0, | ||
'5708': 0, | ||
'5709': 32228, | ||
'5710': 27203, | ||
'5711': 0, | ||
'5850': 1, | ||
'5851': 157, | ||
'9003': 0 | ||
} | ||
], | ||
'5750': 2, | ||
'9001': 'Light WS name', | ||
'9002': 1491149680, | ||
'9003': 65537, | ||
'9019': 1, | ||
'9020': 1507986461, | ||
'9054': 0 | ||
} | ||
|
||
|
||
LIGHT_CWS = { | ||
'3': { | ||
'6': 1, | ||
'0': 'IKEA of Sweden', | ||
'1': 'TRADFRI bulb E27 CWS opal 600lm', | ||
'2': '', | ||
'3': '1.3.002' | ||
}, | ||
'3311': [ | ||
{ | ||
'5706': 'd9337c', | ||
'5707': 0, | ||
'5708': 0, | ||
'5709': 32768, | ||
'5710': 15729, | ||
'5711': 0, | ||
'5850': 1, | ||
'5851': 254, | ||
'9003': 0 | ||
} | ||
], | ||
'5750': 2, | ||
'9001': 'Light CWS name', | ||
'9002': 1506114735, | ||
'9003': 65544, | ||
'9019': 1, | ||
'9020': 1507970551, | ||
'9054': 0 | ||
} | ||
|
||
LIGHT_CWS_CUSTOM_COLOR = { | ||
'3': { | ||
'0': 'IKEA of Sweden', | ||
'1': 'TRADFRI bulb E27 CWS opal 600lm', | ||
'2': '', | ||
'3': '1.3.002', | ||
'6': 1 | ||
}, | ||
'3311': [ | ||
{ | ||
'5706': '0', | ||
'5707': 0, | ||
'5708': 0, | ||
'5709': 23327, | ||
'5710': 33940, | ||
'5711': 0, | ||
'5850': 1, | ||
'5851': 254, | ||
'9003': 0 | ||
} | ||
], | ||
'5750': 2, | ||
'9001': 'Light CWS name', | ||
'9002': 1506114735, | ||
'9003': 65544, | ||
'9019': 1, | ||
'9020': 1507970551, | ||
'9054': 0, | ||
} | ||
|
||
|
||
def light(raw): | ||
return Device(raw).light_control.lights[0] | ||
|
||
|
||
def test_white_bulb(): | ||
bulb = light(LIGHT_W) | ||
|
||
assert bulb.hex_color == 'c19b57' | ||
assert bulb.xy_color == (30101, 26913) | ||
assert bulb.kelvin_color == 2700 | ||
|
||
|
||
def test_spectrum_bulb(): | ||
bulb = light(LIGHT_WS) | ||
|
||
assert bulb.hex_color == 'f1e0b5' | ||
assert bulb.xy_color == (30138, 26909) | ||
assert bulb.kelvin_color == 2697 | ||
|
||
|
||
def test_spectrum_bulb_custom_color(): | ||
bulb = light(LIGHT_WS_CUSTOM_COLOR) | ||
|
||
assert bulb.hex_color == 'f9bc5a' | ||
assert bulb.xy_color == (32228, 27203) | ||
assert bulb.kelvin_color == 2325 | ||
|
||
|
||
def test_color_bulb(): | ||
bulb = light(LIGHT_CWS) | ||
|
||
assert bulb.hex_color == 'd9337c' | ||
assert bulb.xy_color == (32768, 15729) | ||
assert bulb.kelvin_color == 4866 | ||
|
||
|
||
def test_color_bulb_custom_color(): | ||
bulb = light(LIGHT_CWS_CUSTOM_COLOR) | ||
|
||
assert bulb.hex_color == 'cdff67' | ||
assert bulb.xy_color == (23327, 33940) | ||
assert bulb.kelvin_color == 5046 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm not sure if I'm 100% happy with this.
This property used to be a direct 1:1 mapping with the underlying data from the API. I think that it should stay like that. If we want to offer smarter things on top, maybe we can offer it as a utility function?
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.
It's true for all
hex_color
,xy_color
andkelvin_color
. Maybe each of them need to have two flavours - "raw" and "best guess"? Maybe boolean parameter? Than it can default to one of flavours - which one you'd think would be better?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.
Hm, they're properties, so it conflicts with parametrizing them. So two sets of properties maybe?
[hex|xy|kelvin]_color_[raw|guess]
? Or[hex|xy|kelvin]_color[_best_guess]
, or even[hex|xy|kelvin]_color[_raw]
. I also don't have a good suffix for this new property -guess
,best_guess
,estimate
? Neither captures exact behaviour, which is "If I have a value from API, return it, else estimate from other values from API".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 not talking about something along the line of an inferred value?
https://en.wikipedia.org/wiki/Inference
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.
Yes, inference is the word, thanks! So how do you find a set of properties:
[hex|xy|kelvin]_color_[raw|inferred]
?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.
But then we have inconsistency in
kelvin_color
, which is definitely inferred. And this change would be breaking because homeassistant checks bulb features by verifing ifhex_color
makes sense? So maybe it would be good to introduce breaking change, together withcan_set_
, to introduce more order? I'll then addcan_set_
to this PR soon.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.
Breaking with Home Assistant is fine as HASS uses pinned requirements. If we messed up with
kelvin_color
, let's fix it.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.
OK, so which convention should we follow:
[hex|xy]_color[_raw]
andkelvin_color
[hex|xy]_color[_inferred]
andkelvin_color_inferred
[hex|xy]_color_[raw|inferred]
andkelvin_color_inferred
? (My order from most to least preferred: 1, 3, 2)
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.
I don't follow your convention list. This is what I would prefer:
_inferred
.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.
OK, so what's you're describing is I guess 2)
[hex|xy]_color[_inferred]
andkelvin_color_inferred
. which means 5 properties:hex_color
,xy_color
,hex_color_inferred
,xy_color_inferred
,kelvin_color_inferred
.I'll change properties name that way.