mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Fix Matter light get brightness (#149186)
This commit is contained in:
parent
356ac74fa5
commit
65109ea000
@ -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,
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user