diff --git a/homeassistant/components/reolink/light.py b/homeassistant/components/reolink/light.py index a5826e9bb8c..56e31c771e4 100644 --- a/homeassistant/components/reolink/light.py +++ b/homeassistant/components/reolink/light.py @@ -19,6 +19,7 @@ from homeassistant.components.light import ( from homeassistant.const import EntityCategory from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback +from homeassistant.util import color as color_util from .entity import ( ReolinkChannelCoordinatorEntity, @@ -157,16 +158,16 @@ class ReolinkLightEntity(ReolinkChannelCoordinatorEntity, LightEntity): @property def brightness(self) -> int | None: - """Return the brightness of this light between 0.255.""" + """Return the brightness of this light between 1.255.""" assert self.entity_description.get_brightness_fn is not None bright_pct = self.entity_description.get_brightness_fn( self._host.api, self._channel ) - if bright_pct is None: + if not bright_pct: return None - return round(255 * bright_pct / 100.0) + return color_util.value_to_brightness((1, 100), bright_pct) @property def color_temp_kelvin(self) -> int | None: @@ -189,7 +190,7 @@ class ReolinkLightEntity(ReolinkChannelCoordinatorEntity, LightEntity): if ( brightness := kwargs.get(ATTR_BRIGHTNESS) ) is not None and self.entity_description.set_brightness_fn is not None: - brightness_pct = int(brightness / 255.0 * 100) + brightness_pct = round(color_util.brightness_to_value((1, 100), brightness)) await self.entity_description.set_brightness_fn( self._host.api, self._channel, brightness_pct ) diff --git a/tests/components/reolink/conftest.py b/tests/components/reolink/conftest.py index a766846175a..ea9975ad683 100644 --- a/tests/components/reolink/conftest.py +++ b/tests/components/reolink/conftest.py @@ -185,6 +185,7 @@ def _init_host_mock(host_mock: MagicMock) -> None: host_mock.baichuan.smart_ai_type_list.return_value = ["people"] host_mock.baichuan.smart_ai_index.return_value = 1 host_mock.baichuan.smart_ai_name.return_value = "zone1" + host_mock.whiteled_brightness.return_value = None def ai_detect_type(channel: int, object_type: str) -> str | None: if object_type == "people": diff --git a/tests/components/reolink/test_light.py b/tests/components/reolink/test_light.py index a9c2d8cc1bf..0896c1df87d 100644 --- a/tests/components/reolink/test_light.py +++ b/tests/components/reolink/test_light.py @@ -74,6 +74,7 @@ async def test_light_turn_off( ) -> None: """Test light turn off service.""" reolink_host.whiteled_color_temperature.return_value = 3000 + reolink_host.whiteled_brightness.return_value = 75 with patch("homeassistant.components.reolink.PLATFORMS", [Platform.LIGHT]): assert await hass.config_entries.async_setup(config_entry.entry_id) @@ -81,6 +82,8 @@ async def test_light_turn_off( assert config_entry.state is ConfigEntryState.LOADED entity_id = f"{Platform.LIGHT}.{TEST_CAM_NAME}_floodlight" + state = hass.states.get(entity_id) + assert state and state.attributes.get(ATTR_BRIGHTNESS) == 191 await hass.services.async_call( LIGHT_DOMAIN, @@ -107,6 +110,7 @@ async def test_light_turn_on( ) -> None: """Test light turn on service.""" reolink_host.whiteled_color_temperature.return_value = 3000 + reolink_host.whiteled_brightness.return_value = None with patch("homeassistant.components.reolink.PLATFORMS", [Platform.LIGHT]): assert await hass.config_entries.async_setup(config_entry.entry_id)