1
mirror of https://github.com/home-assistant/core synced 2024-08-02 23:40:32 +02:00

Ensure HomeKit passes min/max mireds as ints (#54372)

This commit is contained in:
J. Nick Koston 2021-08-10 20:28:01 -05:00 committed by GitHub
parent e99576c094
commit d0b11568cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -1,5 +1,6 @@
"""Class to hold all light accessories."""
import logging
import math
from pyhap.const import CATEGORY_LIGHTBULB
@ -89,8 +90,8 @@ class Light(HomeAccessory):
self.char_brightness = serv_light.configure_char(CHAR_BRIGHTNESS, value=100)
if self.color_temp_supported:
min_mireds = attributes.get(ATTR_MIN_MIREDS, 153)
max_mireds = attributes.get(ATTR_MAX_MIREDS, 500)
min_mireds = math.floor(attributes.get(ATTR_MIN_MIREDS, 153))
max_mireds = math.ceil(attributes.get(ATTR_MAX_MIREDS, 500))
self.char_color_temp = serv_light.configure_char(
CHAR_COLOR_TEMPERATURE,
value=min_mireds,

View File

@ -15,6 +15,8 @@ from homeassistant.components.light import (
ATTR_BRIGHTNESS_PCT,
ATTR_COLOR_TEMP,
ATTR_HS_COLOR,
ATTR_MAX_MIREDS,
ATTR_MIN_MIREDS,
ATTR_SUPPORTED_COLOR_MODES,
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):
"""Test light with all chars in one go."""
entity_id = "light.demo"