mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Don't truncate brightness and white_value of MQTT light (#19502)
* MQTT light: Don't truncate brightness * Clamp after rounding
This commit is contained in:
parent
5eab4f1dcc
commit
f9aa364b6d
@ -305,7 +305,7 @@ class MqttLight(MqttAvailability, MqttDiscoveryUpdate, MqttEntityDeviceInfo,
|
|||||||
device_value = float(payload)
|
device_value = float(payload)
|
||||||
percent_bright = \
|
percent_bright = \
|
||||||
device_value / self._config.get(CONF_BRIGHTNESS_SCALE)
|
device_value / self._config.get(CONF_BRIGHTNESS_SCALE)
|
||||||
self._brightness = int(percent_bright * 255)
|
self._brightness = percent_bright * 255
|
||||||
self.async_schedule_update_ha_state()
|
self.async_schedule_update_ha_state()
|
||||||
|
|
||||||
if self._topic[CONF_BRIGHTNESS_STATE_TOPIC] is not None:
|
if self._topic[CONF_BRIGHTNESS_STATE_TOPIC] is not None:
|
||||||
@ -335,7 +335,7 @@ class MqttLight(MqttAvailability, MqttDiscoveryUpdate, MqttEntityDeviceInfo,
|
|||||||
if self._topic[CONF_BRIGHTNESS_STATE_TOPIC] is None:
|
if self._topic[CONF_BRIGHTNESS_STATE_TOPIC] is None:
|
||||||
percent_bright = \
|
percent_bright = \
|
||||||
float(color_util.color_RGB_to_hsv(*rgb)[2]) / 100.0
|
float(color_util.color_RGB_to_hsv(*rgb)[2]) / 100.0
|
||||||
self._brightness = int(percent_bright * 255)
|
self._brightness = percent_bright * 255
|
||||||
self.async_schedule_update_ha_state()
|
self.async_schedule_update_ha_state()
|
||||||
|
|
||||||
if self._topic[CONF_RGB_STATE_TOPIC] is not None:
|
if self._topic[CONF_RGB_STATE_TOPIC] is not None:
|
||||||
@ -441,7 +441,7 @@ class MqttLight(MqttAvailability, MqttDiscoveryUpdate, MqttEntityDeviceInfo,
|
|||||||
device_value = float(payload)
|
device_value = float(payload)
|
||||||
percent_white = \
|
percent_white = \
|
||||||
device_value / self._config.get(CONF_WHITE_VALUE_SCALE)
|
device_value / self._config.get(CONF_WHITE_VALUE_SCALE)
|
||||||
self._white_value = int(percent_white * 255)
|
self._white_value = percent_white * 255
|
||||||
self.async_schedule_update_ha_state()
|
self.async_schedule_update_ha_state()
|
||||||
|
|
||||||
if self._topic[CONF_WHITE_VALUE_STATE_TOPIC] is not None:
|
if self._topic[CONF_WHITE_VALUE_STATE_TOPIC] is not None:
|
||||||
@ -496,7 +496,10 @@ class MqttLight(MqttAvailability, MqttDiscoveryUpdate, MqttEntityDeviceInfo,
|
|||||||
@property
|
@property
|
||||||
def brightness(self):
|
def brightness(self):
|
||||||
"""Return the brightness of this light between 0..255."""
|
"""Return the brightness of this light between 0..255."""
|
||||||
return self._brightness
|
brightness = self._brightness
|
||||||
|
if brightness:
|
||||||
|
brightness = min(round(brightness), 255)
|
||||||
|
return brightness
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hs_color(self):
|
def hs_color(self):
|
||||||
@ -511,7 +514,10 @@ class MqttLight(MqttAvailability, MqttDiscoveryUpdate, MqttEntityDeviceInfo,
|
|||||||
@property
|
@property
|
||||||
def white_value(self):
|
def white_value(self):
|
||||||
"""Return the white property."""
|
"""Return the white property."""
|
||||||
return self._white_value
|
white_value = self._white_value
|
||||||
|
if white_value:
|
||||||
|
white_value = min(round(white_value), 255)
|
||||||
|
return white_value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
@ -639,8 +645,9 @@ class MqttLight(MqttAvailability, MqttDiscoveryUpdate, MqttEntityDeviceInfo,
|
|||||||
if ATTR_BRIGHTNESS in kwargs and \
|
if ATTR_BRIGHTNESS in kwargs and \
|
||||||
self._topic[CONF_BRIGHTNESS_COMMAND_TOPIC] is not None:
|
self._topic[CONF_BRIGHTNESS_COMMAND_TOPIC] is not None:
|
||||||
percent_bright = float(kwargs[ATTR_BRIGHTNESS]) / 255
|
percent_bright = float(kwargs[ATTR_BRIGHTNESS]) / 255
|
||||||
|
brightness_scale = self._config.get(CONF_BRIGHTNESS_SCALE)
|
||||||
device_brightness = \
|
device_brightness = \
|
||||||
int(percent_bright * self._config.get(CONF_BRIGHTNESS_SCALE))
|
min(round(percent_bright * brightness_scale), brightness_scale)
|
||||||
mqtt.async_publish(
|
mqtt.async_publish(
|
||||||
self.hass, self._topic[CONF_BRIGHTNESS_COMMAND_TOPIC],
|
self.hass, self._topic[CONF_BRIGHTNESS_COMMAND_TOPIC],
|
||||||
device_brightness, self._config.get(CONF_QOS),
|
device_brightness, self._config.get(CONF_QOS),
|
||||||
@ -700,8 +707,9 @@ class MqttLight(MqttAvailability, MqttDiscoveryUpdate, MqttEntityDeviceInfo,
|
|||||||
if ATTR_WHITE_VALUE in kwargs and \
|
if ATTR_WHITE_VALUE in kwargs and \
|
||||||
self._topic[CONF_WHITE_VALUE_COMMAND_TOPIC] is not None:
|
self._topic[CONF_WHITE_VALUE_COMMAND_TOPIC] is not None:
|
||||||
percent_white = float(kwargs[ATTR_WHITE_VALUE]) / 255
|
percent_white = float(kwargs[ATTR_WHITE_VALUE]) / 255
|
||||||
|
white_scale = self._config.get(CONF_WHITE_VALUE_SCALE)
|
||||||
device_white_value = \
|
device_white_value = \
|
||||||
int(percent_white * self._config.get(CONF_WHITE_VALUE_SCALE))
|
min(round(percent_white * white_scale), white_scale)
|
||||||
mqtt.async_publish(
|
mqtt.async_publish(
|
||||||
self.hass, self._topic[CONF_WHITE_VALUE_COMMAND_TOPIC],
|
self.hass, self._topic[CONF_WHITE_VALUE_COMMAND_TOPIC],
|
||||||
device_white_value, self._config.get(CONF_QOS),
|
device_white_value, self._config.get(CONF_QOS),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user