mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Handle float values for homekit lightning (#33683)
* Handle float values for homekit lightning * Empty commit to rerun CI
This commit is contained in:
parent
d3a4270312
commit
000ad256fb
@ -149,7 +149,7 @@ class Light(HomeAccessory):
|
|||||||
# Handle Brightness
|
# Handle Brightness
|
||||||
if CHAR_BRIGHTNESS in self.chars:
|
if CHAR_BRIGHTNESS in self.chars:
|
||||||
brightness = new_state.attributes.get(ATTR_BRIGHTNESS)
|
brightness = new_state.attributes.get(ATTR_BRIGHTNESS)
|
||||||
if isinstance(brightness, int):
|
if isinstance(brightness, (int, float)):
|
||||||
brightness = round(brightness / 255 * 100, 0)
|
brightness = round(brightness / 255 * 100, 0)
|
||||||
# The homeassistant component might report its brightness as 0 but is
|
# The homeassistant component might report its brightness as 0 but is
|
||||||
# not off. But 0 is a special value in homekit. When you turn on a
|
# not off. But 0 is a special value in homekit. When you turn on a
|
||||||
@ -169,22 +169,18 @@ class Light(HomeAccessory):
|
|||||||
# Handle color temperature
|
# Handle color temperature
|
||||||
if CHAR_COLOR_TEMPERATURE in self.chars:
|
if CHAR_COLOR_TEMPERATURE in self.chars:
|
||||||
color_temperature = new_state.attributes.get(ATTR_COLOR_TEMP)
|
color_temperature = new_state.attributes.get(ATTR_COLOR_TEMP)
|
||||||
if (
|
if isinstance(color_temperature, (int, float)):
|
||||||
isinstance(color_temperature, int)
|
color_temperature = round(color_temperature, 0)
|
||||||
and self.char_color_temperature.value != color_temperature
|
if self.char_color_temperature.value != color_temperature:
|
||||||
):
|
self.char_color_temperature.set_value(color_temperature)
|
||||||
self.char_color_temperature.set_value(color_temperature)
|
|
||||||
|
|
||||||
# Handle Color
|
# Handle Color
|
||||||
if CHAR_SATURATION in self.chars and CHAR_HUE in self.chars:
|
if CHAR_SATURATION in self.chars and CHAR_HUE in self.chars:
|
||||||
hue, saturation = new_state.attributes.get(ATTR_HS_COLOR, (None, None))
|
hue, saturation = new_state.attributes.get(ATTR_HS_COLOR, (None, None))
|
||||||
if (
|
if isinstance(hue, (int, float)) and isinstance(saturation, (int, float)):
|
||||||
isinstance(hue, (int, float))
|
hue = round(hue, 0)
|
||||||
and isinstance(saturation, (int, float))
|
saturation = round(saturation, 0)
|
||||||
and (
|
if hue != self.char_hue.value:
|
||||||
hue != self.char_hue.value
|
self.char_hue.set_value(hue)
|
||||||
or saturation != self.char_saturation.value
|
if saturation != self.char_saturation.value:
|
||||||
)
|
self.char_saturation.set_value(saturation)
|
||||||
):
|
|
||||||
self.char_hue.set_value(hue)
|
|
||||||
self.char_saturation.set_value(saturation)
|
|
||||||
|
@ -235,6 +235,17 @@ async def test_light_brightness(hass, hk_driver, cls, events, driver):
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert acc.char_brightness.value == 1
|
assert acc.char_brightness.value == 1
|
||||||
|
|
||||||
|
# Ensure floats are handled
|
||||||
|
hass.states.async_set(entity_id, STATE_ON, {ATTR_BRIGHTNESS: 55.66})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert acc.char_brightness.value == 22
|
||||||
|
hass.states.async_set(entity_id, STATE_ON, {ATTR_BRIGHTNESS: 108.4})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert acc.char_brightness.value == 43
|
||||||
|
hass.states.async_set(entity_id, STATE_ON, {ATTR_BRIGHTNESS: 0.0})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert acc.char_brightness.value == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_light_color_temperature(hass, hk_driver, cls, events, driver):
|
async def test_light_color_temperature(hass, hk_driver, cls, events, driver):
|
||||||
"""Test light with color temperature."""
|
"""Test light with color temperature."""
|
||||||
@ -417,6 +428,11 @@ async def test_light_set_brightness_and_color(hass, hk_driver, cls, events, driv
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert acc.char_brightness.value == 40
|
assert acc.char_brightness.value == 40
|
||||||
|
|
||||||
|
hass.states.async_set(entity_id, STATE_ON, {ATTR_HS_COLOR: (4.5, 9.2)})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert acc.char_hue.value == 4
|
||||||
|
assert acc.char_saturation.value == 9
|
||||||
|
|
||||||
# Set from HomeKit
|
# Set from HomeKit
|
||||||
call_turn_on = async_mock_service(hass, DOMAIN, "turn_on")
|
call_turn_on = async_mock_service(hass, DOMAIN, "turn_on")
|
||||||
|
|
||||||
@ -489,6 +505,10 @@ async def test_light_set_brightness_and_color_temp(
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert acc.char_brightness.value == 40
|
assert acc.char_brightness.value == 40
|
||||||
|
|
||||||
|
hass.states.async_set(entity_id, STATE_ON, {ATTR_COLOR_TEMP: (224.14)})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert acc.char_color_temperature.value == 224
|
||||||
|
|
||||||
# Set from HomeKit
|
# Set from HomeKit
|
||||||
call_turn_on = async_mock_service(hass, DOMAIN, "turn_on")
|
call_turn_on = async_mock_service(hass, DOMAIN, "turn_on")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user