mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +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 typing import Any
|
||||||
|
|
||||||
from chip.clusters import Objects as clusters
|
from chip.clusters import Objects as clusters
|
||||||
|
from chip.clusters.Objects import NullValue
|
||||||
from matter_server.client.models import device_types
|
from matter_server.client.models import device_types
|
||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
@ -241,7 +242,7 @@ class MatterLight(MatterEntity, LightEntity):
|
|||||||
|
|
||||||
return int(color_temp)
|
return int(color_temp)
|
||||||
|
|
||||||
def _get_brightness(self) -> int:
|
def _get_brightness(self) -> int | None:
|
||||||
"""Get brightness from matter."""
|
"""Get brightness from matter."""
|
||||||
|
|
||||||
level_control = self._endpoint.get_cluster(clusters.LevelControl)
|
level_control = self._endpoint.get_cluster(clusters.LevelControl)
|
||||||
@ -255,6 +256,10 @@ class MatterLight(MatterEntity, LightEntity):
|
|||||||
self.entity_id,
|
self.entity_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if level_control.currentLevel is NullValue:
|
||||||
|
# currentLevel is a nullable value.
|
||||||
|
return None
|
||||||
|
|
||||||
return round(
|
return round(
|
||||||
renormalize(
|
renormalize(
|
||||||
level_control.currentLevel,
|
level_control.currentLevel,
|
||||||
|
@ -131,6 +131,15 @@ async def test_dimmable_light(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test a dimmable light."""
|
"""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)
|
# Test that the light brightness is 50 (out of 254)
|
||||||
set_node_attribute(matter_node, 1, 8, 0, 50)
|
set_node_attribute(matter_node, 1, 8, 0, 50)
|
||||||
await trigger_subscription_callback(hass, matter_client)
|
await trigger_subscription_callback(hass, matter_client)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user