Skip to content

Commit c3eb6de

Browse files
jvmahonfrenck
authored andcommitted
Fix Matter light get brightness (home-assistant#149186)
1 parent f428ffd commit c3eb6de

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

homeassistant/components/matter/light.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Any
66

77
from chip.clusters import Objects as clusters
8+
from chip.clusters.Objects import NullValue
89
from matter_server.client.models import device_types
910

1011
from homeassistant.components.light import (
@@ -241,7 +242,7 @@ def _get_color_temperature(self) -> int:
241242

242243
return int(color_temp)
243244

244-
def _get_brightness(self) -> int:
245+
def _get_brightness(self) -> int | None:
245246
"""Get brightness from matter."""
246247

247248
level_control = self._endpoint.get_cluster(clusters.LevelControl)
@@ -255,6 +256,10 @@ def _get_brightness(self) -> int:
255256
self.entity_id,
256257
)
257258

259+
if level_control.currentLevel is NullValue:
260+
# currentLevel is a nullable value.
261+
return None
262+
258263
return round(
259264
renormalize(
260265
level_control.currentLevel,

tests/components/matter/test_light.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ async def test_dimmable_light(
131131
) -> None:
132132
"""Test a dimmable light."""
133133

134+
# Test for currentLevel is None
135+
set_node_attribute(matter_node, 1, 8, 0, None)
136+
await trigger_subscription_callback(hass, matter_client)
137+
138+
state = hass.states.get(entity_id)
139+
assert state is not None
140+
assert state.state == "on"
141+
assert state.attributes["brightness"] is None
142+
134143
# Test that the light brightness is 50 (out of 254)
135144
set_node_attribute(matter_node, 1, 8, 0, 50)
136145
await trigger_subscription_callback(hass, matter_client)

0 commit comments

Comments
 (0)