Fix Matter light get brightness (#149186)

This commit is contained in:
jvmahon 2025-07-25 13:09:58 -04:00 committed by GitHub
parent 356ac74fa5
commit 65109ea000
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -5,6 +5,7 @@ from __future__ import annotations
from typing import Any
from chip.clusters import Objects as clusters
from chip.clusters.Objects import NullValue
from matter_server.client.models import device_types
from homeassistant.components.light import (
@ -241,7 +242,7 @@ class MatterLight(MatterEntity, LightEntity):
return int(color_temp)
def _get_brightness(self) -> int:
def _get_brightness(self) -> int | None:
"""Get brightness from matter."""
level_control = self._endpoint.get_cluster(clusters.LevelControl)
@ -255,6 +256,10 @@ class MatterLight(MatterEntity, LightEntity):
self.entity_id,
)
if level_control.currentLevel is NullValue:
# currentLevel is a nullable value.
return None
return round(
renormalize(
level_control.currentLevel,

View File

@ -131,6 +131,15 @@ async def test_dimmable_light(
) -> None:
"""Test a dimmable light."""
# Test for currentLevel is None
set_node_attribute(matter_node, 1, 8, 0, None)
await trigger_subscription_callback(hass, matter_client)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == "on"
assert state.attributes["brightness"] is None
# Test that the light brightness is 50 (out of 254)
set_node_attribute(matter_node, 1, 8, 0, 50)
await trigger_subscription_callback(hass, matter_client)