Improve MQTT json light brightness scaling (#104510)

* Improve MQTT json light brightness scaling

* Revert unrelated changes

* Format
pull/104733/head
Jan Bouwhuis 2023-11-29 16:42:10 +01:00 committed by GitHub
parent b36ddaa15c
commit 4bf88b1690
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 7 deletions

View File

@ -367,13 +367,10 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity):
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(

View File

@ -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(
@ -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(