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

More accurately convert colortemp to xy and hs #146

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion custom_components/circadian_lighting/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"issue_tracker": "https://github.com/claytonjn/hass-circadian_lighting/issues",
"dependencies": ["sensor","switch"],
"codeowners": ["@claytonjn"],
"requirements": [],
"requirements": ["colour-science"],
"iot_class": "calculated"
}
14 changes: 12 additions & 2 deletions custom_components/circadian_lighting/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@

import asyncio
import logging
import sys
from itertools import repeat

import voluptuous as vol
try:
import colour
USING_COLOUR = True
except:
USING_COLOUR = False

import homeassistant.helpers.config_validation as cv
from homeassistant.components.light import (
Expand Down Expand Up @@ -299,7 +305,10 @@ def _calc_rgb(self):
return color_temperature_to_rgb(self._color_temperature())

def _calc_xy(self):
return color_RGB_to_xy(*self._calc_rgb())
if USING_COLOUR:
return list(colour.temperature.CCT_to_xy_CIE_D(self._color_temperature()))
else:
return color_RGB_to_xy(*self._calc_rgb())

def _calc_hs(self):
return color_xy_to_hs(*self._calc_xy())
Expand Down Expand Up @@ -352,7 +361,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
Copy link
Owner

Choose a reason for hiding this comment

The 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 service_data was not set because of an issue with light or transition?

Copy link
Author

Choose a reason for hiding this comment

The 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)

Expand Down