Improve MQTT json light brightness scaling (#104510)
* Improve MQTT json light brightness scaling * Revert unrelated changes * Formatpull/104733/head
parent
b36ddaa15c
commit
4bf88b1690
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue