1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-23 20:23:50 +01:00
This commit is contained in:
J. Nick Koston
2025-10-18 13:38:45 -10:00
parent 1c8b60891c
commit 8545b5231b

View File

@@ -288,15 +288,16 @@ class ColorModeMask {
/// Check if any mode in the bitmask has a specific capability /// Check if any mode in the bitmask has a specific capability
/// Used for checking if a light supports a capability (e.g., BRIGHTNESS, RGB) /// Used for checking if a light supports a capability (e.g., BRIGHTNESS, RGB)
bool has_capability(ColorCapability capability) const { bool has_capability(ColorCapability capability) const {
// Convert capability bit to array index (log2 of the bit value) // Lookup the pre-computed bitmask for this capability and check intersection with our mask
uint8_t cap_bit = static_cast<uint8_t>(capability); // ColorCapability values: 1, 2, 4, 8, 16, 32 -> array indices: 0, 1, 2, 3, 4, 5
// Count trailing zeros to get the bit position (0-5) // We need to convert the power-of-2 value to an index
uint8_t cap_val = static_cast<uint8_t>(capability);
int index = 0; int index = 0;
while (index < COLOR_CAPABILITY_COUNT && !(cap_bit & (1 << index))) { while (cap_val > 1) {
cap_val >>= 1;
++index; ++index;
} }
// Look up the pre-computed bitmask and check if any of our set bits match return (this->mask_ & CAPABILITY_BITMASKS[index]) != 0;
return (index < COLOR_CAPABILITY_COUNT) && ((this->mask_ & CAPABILITY_BITMASKS[index]) != 0);
} }
/// Build a bitmask of modes that match the given capability requirements /// Build a bitmask of modes that match the given capability requirements