Ensure brightness is limited to 100
As suggested by coderabbitai.
This commit is contained in:
@@ -20,7 +20,7 @@ namespace esphome {
|
||||
|
||||
// Function implementations
|
||||
uint32_t pack_light_attributes(const LightAttributes& attr) {
|
||||
return (uint32_t(attr.brightness) << 24) |
|
||||
return (uint32_t(std::min(attr.brightness, uint8_t(100))) << 24) |
|
||||
(uint32_t(attr.red) << 16) |
|
||||
(uint32_t(attr.green) << 8) |
|
||||
(uint32_t(attr.blue));
|
||||
@@ -28,7 +28,7 @@ namespace esphome {
|
||||
|
||||
LightAttributes unpack_light_attributes(uint32_t packed) {
|
||||
return {
|
||||
.brightness = uint8_t((packed >> 24) & 0xFF),
|
||||
.brightness = std::min(uint8_t((packed >> 24) & 0xFF), uint8_t(100)),
|
||||
.red = uint8_t((packed >> 16) & 0xFF),
|
||||
.green = uint8_t((packed >> 8) & 0xFF),
|
||||
.blue = uint8_t(packed & 0xFF)
|
||||
|
||||
Reference in New Issue
Block a user