Ensure HomeKit passes min/max mireds as ints (#54372)
parent
e99576c094
commit
d0b11568cc
|
@ -1,5 +1,6 @@
|
||||||
"""Class to hold all light accessories."""
|
"""Class to hold all light accessories."""
|
||||||
import logging
|
import logging
|
||||||
|
import math
|
||||||
|
|
||||||
from pyhap.const import CATEGORY_LIGHTBULB
|
from pyhap.const import CATEGORY_LIGHTBULB
|
||||||
|
|
||||||
|
@ -89,8 +90,8 @@ class Light(HomeAccessory):
|
||||||
self.char_brightness = serv_light.configure_char(CHAR_BRIGHTNESS, value=100)
|
self.char_brightness = serv_light.configure_char(CHAR_BRIGHTNESS, value=100)
|
||||||
|
|
||||||
if self.color_temp_supported:
|
if self.color_temp_supported:
|
||||||
min_mireds = attributes.get(ATTR_MIN_MIREDS, 153)
|
min_mireds = math.floor(attributes.get(ATTR_MIN_MIREDS, 153))
|
||||||
max_mireds = attributes.get(ATTR_MAX_MIREDS, 500)
|
max_mireds = math.ceil(attributes.get(ATTR_MAX_MIREDS, 500))
|
||||||
self.char_color_temp = serv_light.configure_char(
|
self.char_color_temp = serv_light.configure_char(
|
||||||
CHAR_COLOR_TEMPERATURE,
|
CHAR_COLOR_TEMPERATURE,
|
||||||
value=min_mireds,
|
value=min_mireds,
|
||||||
|
|
|
@ -15,6 +15,8 @@ from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS_PCT,
|
ATTR_BRIGHTNESS_PCT,
|
||||||
ATTR_COLOR_TEMP,
|
ATTR_COLOR_TEMP,
|
||||||
ATTR_HS_COLOR,
|
ATTR_HS_COLOR,
|
||||||
|
ATTR_MAX_MIREDS,
|
||||||
|
ATTR_MIN_MIREDS,
|
||||||
ATTR_SUPPORTED_COLOR_MODES,
|
ATTR_SUPPORTED_COLOR_MODES,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
@ -639,6 +641,26 @@ async def test_light_set_brightness_and_color(hass, hk_driver, events):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_light_min_max_mireds(hass, hk_driver, events):
|
||||||
|
"""Test mireds are forced to ints."""
|
||||||
|
entity_id = "light.demo"
|
||||||
|
|
||||||
|
hass.states.async_set(
|
||||||
|
entity_id,
|
||||||
|
STATE_ON,
|
||||||
|
{
|
||||||
|
ATTR_SUPPORTED_COLOR_MODES: ["color_temp"],
|
||||||
|
ATTR_BRIGHTNESS: 255,
|
||||||
|
ATTR_MAX_MIREDS: 500.5,
|
||||||
|
ATTR_MIN_MIREDS: 100.5,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
acc = Light(hass, hk_driver, "Light", entity_id, 1, None)
|
||||||
|
acc.char_color_temp.properties["maxValue"] == 500
|
||||||
|
acc.char_color_temp.properties["minValue"] == 100
|
||||||
|
|
||||||
|
|
||||||
async def test_light_set_brightness_and_color_temp(hass, hk_driver, events):
|
async def test_light_set_brightness_and_color_temp(hass, hk_driver, events):
|
||||||
"""Test light with all chars in one go."""
|
"""Test light with all chars in one go."""
|
||||||
entity_id = "light.demo"
|
entity_id = "light.demo"
|
||||||
|
|
Loading…
Reference in New Issue