Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MQTT json light brightness scaling #104510

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions homeassistant/components/mqtt/light/schema_json.py
Expand Up @@ -367,13 +367,10 @@ def state_received(msg: ReceiveMessage) -> None:
if brightness_supported(self.supported_color_modes):
try:
if brightness := values["brightness"]:
scale = self._config[CONF_BRIGHTNESS_SCALE]
self._attr_brightness = min(
int(
brightness # type: ignore[operator]
/ float(self._config[CONF_BRIGHTNESS_SCALE])
* 255
),
255,
round(brightness * 255 / scale), # type: ignore[operator]
)
else:
_LOGGER.debug(
Expand Down
4 changes: 2 additions & 2 deletions tests/components/mqtt/test_light_json.py
Expand Up @@ -1792,7 +1792,7 @@ async def test_brightness_scale(

state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.attributes.get("brightness") == 128
assert state.attributes.get("brightness") == 129

# Test limmiting max brightness
async_fire_mqtt_message(
Expand Down Expand Up @@ -1862,7 +1862,7 @@ async def test_white_scale(

state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.attributes.get("brightness") == 128
assert state.attributes.get("brightness") == 129


@pytest.mark.parametrize(
Expand Down