Skip to content

Commit

Permalink
Convert Hue scenes brightness to 0..255 (home-assistant#105871)
Browse files Browse the repository at this point in the history
Co-authored-by: Franck Nijhof <[email protected]>
  • Loading branch information
barryvdh and frenck authored Jul 6, 2024
1 parent ec536bd commit d113ea8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions homeassistant/components/hue/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ def extra_state_attributes(self) -> dict[str, Any] | None:
if action.action.dimming:
brightness = action.action.dimming.brightness
break
if brightness is not None:
# Hue uses a range of [0, 100] to control brightness.
brightness = round((brightness / 100) * 255)
return {
"group_name": self.group.metadata.name,
"group_type": self.group.type.value,
Expand Down
8 changes: 4 additions & 4 deletions tests/components/hue/test_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def test_scene(
assert test_entity.attributes["group_type"] == "zone"
assert test_entity.attributes["name"] == "Dynamic Test Scene"
assert test_entity.attributes["speed"] == 0.6269841194152832
assert test_entity.attributes["brightness"] == 46.85
assert test_entity.attributes["brightness"] == 119
assert test_entity.attributes["is_dynamic"] is True

# test (regular) scene for a hue room
Expand All @@ -47,7 +47,7 @@ async def test_scene(
assert test_entity.attributes["group_type"] == "room"
assert test_entity.attributes["name"] == "Regular Test Scene"
assert test_entity.attributes["speed"] == 0.5
assert test_entity.attributes["brightness"] == 100.0
assert test_entity.attributes["brightness"] == 255
assert test_entity.attributes["is_dynamic"] is False

# test smart scene
Expand Down Expand Up @@ -170,7 +170,7 @@ async def test_scene_updates(
assert test_entity is not None
assert test_entity.state == STATE_UNKNOWN
assert test_entity.name == "Test Room Mocked Scene"
assert test_entity.attributes["brightness"] == 65.0
assert test_entity.attributes["brightness"] == 166

# test update
updated_resource = {**FAKE_SCENE}
Expand All @@ -179,7 +179,7 @@ async def test_scene_updates(
await hass.async_block_till_done()
test_entity = hass.states.get(test_entity_id)
assert test_entity is not None
assert test_entity.attributes["brightness"] == 35.0
assert test_entity.attributes["brightness"] == 89

# # test entity name changes on group name change
mock_bridge_v2.api.emit_event(
Expand Down

0 comments on commit d113ea8

Please sign in to comment.