1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Reduce loss of precision when setting light percent brightness (#34208)

* Reduce loss of precision when setting light percent brightness

This part of an effort to fix all the round trip light
brightness percentages that cause errors with homekit
, alexa, and other devices that use percentage.

* fix demo light test
This commit is contained in:
J. Nick Koston
2020-04-14 13:26:18 -05:00
committed by GitHub
parent 18478ebd05
commit e0a7ea52fd
3 changed files with 56 additions and 4 deletions

View File

@@ -495,4 +495,56 @@ async def test_light_brightness_step(hass):
)
_, data = entity.last_call("turn_on")
assert data["brightness"] == 125, data
assert data["brightness"] == 126, data
async def test_light_brightness_pct_conversion(hass):
"""Test that light brightness percent conversion."""
platform = getattr(hass.components, "test.light")
platform.init()
entity = platform.ENTITIES[0]
entity.supported_features = light.SUPPORT_BRIGHTNESS
entity.brightness = 100
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
state = hass.states.get(entity.entity_id)
assert state is not None
assert state.attributes["brightness"] == 100
await hass.services.async_call(
"light", "turn_on", {"entity_id": entity.entity_id, "brightness_pct": 1}, True,
)
_, data = entity.last_call("turn_on")
assert data["brightness"] == 3, data
await hass.services.async_call(
"light", "turn_on", {"entity_id": entity.entity_id, "brightness_pct": 2}, True,
)
_, data = entity.last_call("turn_on")
assert data["brightness"] == 5, data
await hass.services.async_call(
"light", "turn_on", {"entity_id": entity.entity_id, "brightness_pct": 50}, True,
)
_, data = entity.last_call("turn_on")
assert data["brightness"] == 128, data
await hass.services.async_call(
"light", "turn_on", {"entity_id": entity.entity_id, "brightness_pct": 99}, True,
)
_, data = entity.last_call("turn_on")
assert data["brightness"] == 252, data
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": entity.entity_id, "brightness_pct": 100},
True,
)
_, data = entity.last_call("turn_on")
assert data["brightness"] == 255, data