Skip to content

Commit

Permalink
More accurately convert colortemp to xy and hs
Browse files Browse the repository at this point in the history
  • Loading branch information
dn0sar committed Apr 20, 2021
1 parent 6a919ae commit 02820b2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion custom_components/circadian_lighting/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
"documentation": "https://github.com/claytonjn/hass-circadian_lighting",
"dependencies": [],
"codeowners": ["@claytonjn"],
"requirements": ["timezonefinder==4.2.0"]
"requirements": [
"timezonefinder==4.2.0",
"colour-science"
]
}
7 changes: 6 additions & 1 deletion custom_components/circadian_lighting/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from custom_components.circadian_lighting import DOMAIN, CIRCADIAN_LIGHTING_UPDATE_TOPIC, DATA_CIRCADIAN_LIGHTING

import voluptuous as vol
import colour

import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import dispatcher_connect
Expand Down Expand Up @@ -235,7 +236,11 @@ def calc_rgb(self):
return color_temperature_to_rgb(self._cl.data['colortemp'])

def calc_xy(self):
return color_RGB_to_xy(*self.calc_rgb())
if self.is_sleep():
_LOGGER.debug(self._name + " in Sleep mode")
return list(colour.temperature.CCT_to_xy_CIE_D(self._sleep_colortemp))
else:
return list(colour.temperature.CCT_to_xy_CIE_D(self._cl.data['colortemp']))

def calc_hs(self):
return color_xy_to_hs(*self.calc_xy())
Expand Down

0 comments on commit 02820b2

Please sign in to comment.