Added support for setting/getting the white color temperature and a utility function to convert from Kelvin to MIRED
This commit is contained in:
parent
9b99902463
commit
ed75cd2951
4 changed files with 92 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
||||||
* [yahuelib](#yahuelib)
|
* [yahuelib](#yahuelib)
|
||||||
* [yahuelib.utils](#yahuelib.utils)
|
* [yahuelib.utils](#yahuelib.utils)
|
||||||
* [rgb\_to\_hsv](#yahuelib.utils.rgb_to_hsv)
|
* [rgb\_to\_hsv](#yahuelib.utils.rgb_to_hsv)
|
||||||
|
* [kelvin\_to\_mired](#yahuelib.utils.kelvin_to_mired)
|
||||||
* [yahuelib.controller](#yahuelib.controller)
|
* [yahuelib.controller](#yahuelib.controller)
|
||||||
* [LightController](#yahuelib.controller.LightController)
|
* [LightController](#yahuelib.controller.LightController)
|
||||||
* [reachable](#yahuelib.controller.LightController.reachable)
|
* [reachable](#yahuelib.controller.LightController.reachable)
|
||||||
|
@ -14,6 +15,8 @@
|
||||||
* [hue](#yahuelib.controller.LightController.hue)
|
* [hue](#yahuelib.controller.LightController.hue)
|
||||||
* [saturation](#yahuelib.controller.LightController.saturation)
|
* [saturation](#yahuelib.controller.LightController.saturation)
|
||||||
* [saturation](#yahuelib.controller.LightController.saturation)
|
* [saturation](#yahuelib.controller.LightController.saturation)
|
||||||
|
* [color\_temperature](#yahuelib.controller.LightController.color_temperature)
|
||||||
|
* [color\_temperature](#yahuelib.controller.LightController.color_temperature)
|
||||||
* [alert](#yahuelib.controller.LightController.alert)
|
* [alert](#yahuelib.controller.LightController.alert)
|
||||||
* [alert\_long](#yahuelib.controller.LightController.alert_long)
|
* [alert\_long](#yahuelib.controller.LightController.alert_long)
|
||||||
* [GroupController](#yahuelib.controller.GroupController)
|
* [GroupController](#yahuelib.controller.GroupController)
|
||||||
|
@ -26,6 +29,8 @@
|
||||||
* [hue](#yahuelib.controller.GroupController.hue)
|
* [hue](#yahuelib.controller.GroupController.hue)
|
||||||
* [saturation](#yahuelib.controller.GroupController.saturation)
|
* [saturation](#yahuelib.controller.GroupController.saturation)
|
||||||
* [saturation](#yahuelib.controller.GroupController.saturation)
|
* [saturation](#yahuelib.controller.GroupController.saturation)
|
||||||
|
* [color\_temperature](#yahuelib.controller.GroupController.color_temperature)
|
||||||
|
* [color\_temperature](#yahuelib.controller.GroupController.color_temperature)
|
||||||
* [alert](#yahuelib.controller.GroupController.alert)
|
* [alert](#yahuelib.controller.GroupController.alert)
|
||||||
* [alert\_long](#yahuelib.controller.GroupController.alert_long)
|
* [alert\_long](#yahuelib.controller.GroupController.alert_long)
|
||||||
* [yahuelib.exceptions](#yahuelib.exceptions)
|
* [yahuelib.exceptions](#yahuelib.exceptions)
|
||||||
|
@ -50,6 +55,16 @@ def rgb_to_hsv(r: int, g: int, b: int) -> tuple
|
||||||
|
|
||||||
Convert RGB colors `(255, 220, 100)` to HSV `(0.129, 0.608, 1.0)`
|
Convert RGB colors `(255, 220, 100)` to HSV `(0.129, 0.608, 1.0)`
|
||||||
|
|
||||||
|
<a id="yahuelib.utils.kelvin_to_mired"></a>
|
||||||
|
|
||||||
|
#### kelvin\_to\_mired
|
||||||
|
|
||||||
|
```python
|
||||||
|
def kelvin_to_mired(kelvin: int)
|
||||||
|
```
|
||||||
|
|
||||||
|
Convert the color temperature from Kelvin to Mired
|
||||||
|
|
||||||
<a id="yahuelib.controller"></a>
|
<a id="yahuelib.controller"></a>
|
||||||
|
|
||||||
# yahuelib.controller
|
# yahuelib.controller
|
||||||
|
@ -171,6 +186,28 @@ def saturation(saturation: float)
|
||||||
|
|
||||||
Set the saturation using `LightController.saturation = ...`
|
Set the saturation using `LightController.saturation = ...`
|
||||||
|
|
||||||
|
<a id="yahuelib.controller.LightController.color_temperature"></a>
|
||||||
|
|
||||||
|
#### color\_temperature
|
||||||
|
|
||||||
|
```python
|
||||||
|
@property
|
||||||
|
def color_temperature()
|
||||||
|
```
|
||||||
|
|
||||||
|
Get the white color temperature in Mired using `LightController.color_temperature`
|
||||||
|
|
||||||
|
<a id="yahuelib.controller.LightController.color_temperature"></a>
|
||||||
|
|
||||||
|
#### color\_temperature
|
||||||
|
|
||||||
|
```python
|
||||||
|
@color_temperature.setter
|
||||||
|
def color_temperature(mired: int)
|
||||||
|
```
|
||||||
|
|
||||||
|
Set the white color temperature in Mired (`154` - `500`) using `LightController.color_temperature = ...`
|
||||||
|
|
||||||
<a id="yahuelib.controller.LightController.alert"></a>
|
<a id="yahuelib.controller.LightController.alert"></a>
|
||||||
|
|
||||||
#### alert
|
#### alert
|
||||||
|
@ -308,6 +345,28 @@ def saturation(saturation: float)
|
||||||
|
|
||||||
Set the saturation of all lights in this group using `GroupController.saturation = ...`
|
Set the saturation of all lights in this group using `GroupController.saturation = ...`
|
||||||
|
|
||||||
|
<a id="yahuelib.controller.GroupController.color_temperature"></a>
|
||||||
|
|
||||||
|
#### color\_temperature
|
||||||
|
|
||||||
|
```python
|
||||||
|
@property
|
||||||
|
def color_temperature()
|
||||||
|
```
|
||||||
|
|
||||||
|
Get the last set white color temperature in Mired using `GroupController.color_temperature`
|
||||||
|
|
||||||
|
<a id="yahuelib.controller.GroupController.color_temperature"></a>
|
||||||
|
|
||||||
|
#### color\_temperature
|
||||||
|
|
||||||
|
```python
|
||||||
|
@color_temperature.setter
|
||||||
|
def color_temperature(mired: int)
|
||||||
|
```
|
||||||
|
|
||||||
|
Set the white color temperature in Mired (`154` - `500`) for all lights in this group using `GroupController.color_temperature = ...`
|
||||||
|
|
||||||
<a id="yahuelib.controller.GroupController.alert"></a>
|
<a id="yahuelib.controller.GroupController.alert"></a>
|
||||||
|
|
||||||
#### alert
|
#### alert
|
||||||
|
|
|
@ -15,6 +15,7 @@ See https://developers.meethue.com/develop/get-started-2/
|
||||||
- brightness
|
- brightness
|
||||||
- hue
|
- hue
|
||||||
- saturation
|
- saturation
|
||||||
|
- white color temperature
|
||||||
- alert
|
- alert
|
||||||
- alert_long
|
- alert_long
|
||||||
- 🏠 Groups (Zones and Rooms)
|
- 🏠 Groups (Zones and Rooms)
|
||||||
|
@ -23,6 +24,7 @@ See https://developers.meethue.com/develop/get-started-2/
|
||||||
- brightness
|
- brightness
|
||||||
- hue
|
- hue
|
||||||
- saturation
|
- saturation
|
||||||
|
- white color temperature
|
||||||
- alert
|
- alert
|
||||||
- alert_long
|
- alert_long
|
||||||
|
|
||||||
|
|
|
@ -133,6 +133,19 @@ class LightController(_BaseController):
|
||||||
sat_ = min(max(int(saturation * 254), 0), 254)
|
sat_ = min(max(int(saturation * 254), 0), 254)
|
||||||
self._api_request("PUT", "/state", {"sat": sat_})
|
self._api_request("PUT", "/state", {"sat": sat_})
|
||||||
|
|
||||||
|
@property
|
||||||
|
def color_temperature(self):
|
||||||
|
'''Get the white color temperature in Mired using `LightController.color_temperature`'''
|
||||||
|
data = self._api_request()
|
||||||
|
return data["state"]["ct"]
|
||||||
|
|
||||||
|
@color_temperature.setter
|
||||||
|
def color_temperature(self, mired:int):
|
||||||
|
'''Set the white color temperature in Mired (`154` - `500`) using `LightController.color_temperature = ...`'''
|
||||||
|
assert type(mired) == int
|
||||||
|
ct_ = min(max(mired, 154), 500)
|
||||||
|
self._api_request("PUT", "/state", {"ct": ct_})
|
||||||
|
|
||||||
def alert(self):
|
def alert(self):
|
||||||
'''Flash the light once.'''
|
'''Flash the light once.'''
|
||||||
self._api_request("PUT", "/state", {"alert": "select"})
|
self._api_request("PUT", "/state", {"alert": "select"})
|
||||||
|
@ -213,6 +226,19 @@ class GroupController(_BaseController):
|
||||||
sat_ = min(max(int(saturation * 254), 0), 254)
|
sat_ = min(max(int(saturation * 254), 0), 254)
|
||||||
self._api_request("PUT", "/action", {"sat": sat_})
|
self._api_request("PUT", "/action", {"sat": sat_})
|
||||||
|
|
||||||
|
@property
|
||||||
|
def color_temperature(self):
|
||||||
|
'''Get the last set white color temperature in Mired using `GroupController.color_temperature`'''
|
||||||
|
data = self._api_request()
|
||||||
|
return data["action"]["ct"]
|
||||||
|
|
||||||
|
@color_temperature.setter
|
||||||
|
def color_temperature(self, mired:int):
|
||||||
|
'''Set the white color temperature in Mired (`154` - `500`) for all lights in this group using `GroupController.color_temperature = ...`'''
|
||||||
|
assert type(mired) == int
|
||||||
|
ct_ = min(max(mired, 154), 500)
|
||||||
|
self._api_request("PUT", "/action", {"ct": ct_})
|
||||||
|
|
||||||
def alert(self):
|
def alert(self):
|
||||||
'''Flash all lights in the group once.'''
|
'''Flash all lights in the group once.'''
|
||||||
self._api_request("PUT", "/action", {"alert": "select"})
|
self._api_request("PUT", "/action", {"alert": "select"})
|
||||||
|
|
|
@ -13,3 +13,8 @@ def rgb_to_hsv(r:int, g:int, b:int) -> tuple:
|
||||||
g_ = g / 255.0
|
g_ = g / 255.0
|
||||||
b_ = b / 255.0
|
b_ = b / 255.0
|
||||||
return _rgb_to_hsv(r_, g_, b_)
|
return _rgb_to_hsv(r_, g_, b_)
|
||||||
|
|
||||||
|
def kelvin_to_mired(kelvin:int):
|
||||||
|
'''Convert the color temperature from Kelvin to Mired'''
|
||||||
|
assert type(kelvin) == int
|
||||||
|
return round(1000000.0/kelvin)
|
||||||
|
|
Reference in a new issue