-
Notifications
You must be signed in to change notification settings - Fork 92
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
More accurately convert colortemp to xy and hs #146
base: dev
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
from itertools import repeat | ||
|
||
import voluptuous as vol | ||
import colour | ||
|
||
import homeassistant.helpers.config_validation as cv | ||
from homeassistant.components.light import ( | ||
|
@@ -299,7 +300,7 @@ def _calc_rgb(self): | |
return color_temperature_to_rgb(self._color_temperature()) | ||
|
||
def _calc_xy(self): | ||
return color_RGB_to_xy(*self._calc_rgb()) | ||
return list(colour.temperature.CCT_to_xy_CIE_D(self._color_temperature())) | ||
|
||
def _calc_hs(self): | ||
return color_xy_to_hs(*self._calc_xy()) | ||
|
@@ -352,7 +353,8 @@ async def _adjust_lights(self, lights, transition): | |
if not is_on(self.hass, light): | ||
continue | ||
|
||
service_data = {ATTR_ENTITY_ID: light, ATTR_TRANSITION: transition} | ||
service_data = {ATTR_ENTITY_ID: light} | ||
service_data[ATTR_TRANSITION] = transition | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there an advantage to breaking this into two lines? Have you run into issues where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah well spotted! I actually didn't intend to commit this, but I forgot to remove it after I tested it on my system. The problem is that IKEA light bulbs don't handle transition and color changes commands issued at the same time very well. Particularly, they don't change the color when this happens, so I just commented out the transition part on my system. |
||
if self._brightness is not None: | ||
service_data[ATTR_BRIGHTNESS] = int((self._brightness / 100) * 254) | ||
|
||
|
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.
This is something that's bothered me too but adding additional package requirements has always caused problems in the past for users that have non "standard" installations. If the
colour-science
package fails to install then the entire CL integration will break. I think a better solution would be to wrap this in a try and if an exception occurs to use the current built-in method. I can make that change when I get a chance or feel free to handle it if you're so inclined.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.
Hey, thanks for the feedback. Yep, agree with your point, also because currently the packaged version of
colour-science
has a problem when running on raspberry-pi (this was fixed ~8 months ago on their repo, but it is not yet on the release version). I'll add this check by the end of the week :)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.
If the only method used is
color.temperature.CCT_to_xy_CIE_D()
another option would be to just extract the code for this method (https://github.com/colour-science/colour/blob/a412b670448534987fc25d3a1a09cedc2a3ea5f2/colour/temperature/cie_d.py#L127-L183) from the package and omit the rest of it.This would completely ditch the dependency while still providing the same functionality.