1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-23 12:13:49 +01:00
This commit is contained in:
J. Nick Koston
2025-10-18 13:10:41 -10:00
parent 89903929f3
commit 89c719d71d
2 changed files with 14 additions and 5 deletions

View File

@@ -194,6 +194,19 @@ class ColorModeMask {
return (mask & (1 << mode_to_bit(mode))) != 0;
}
/// Check if any mode in the bitmask has a specific capability
/// Used for checking if a light supports a capability (e.g., BRIGHTNESS, RGB)
bool has_capability(ColorCapability capability) const {
uint8_t cap_mask = static_cast<uint8_t>(capability);
// Check each set bit to see if any mode has this capability
for (int bit = 1; bit < COLOR_MODE_COUNT; ++bit) {
if ((this->mask_ & (1 << bit)) && (static_cast<uint8_t>(bit_to_mode(bit)) & cap_mask)) {
return true;
}
}
return false;
}
/// Build a bitmask of modes that match the given capability requirements
/// @param require_caps Capabilities that must be present in the mode
/// @param exclude_caps Capabilities that must not be present in the mode (for none case)

View File

@@ -28,11 +28,7 @@ class LightTraits {
bool supports_color_mode(ColorMode color_mode) const { return this->supported_color_modes_.contains(color_mode); }
bool supports_color_capability(ColorCapability color_capability) const {
for (auto mode : this->supported_color_modes_) {
if (mode & color_capability)
return true;
}
return false;
return this->supported_color_modes_.has_capability(color_capability);
}
ESPDEPRECATED("get_supports_brightness() is deprecated, use color modes instead.", "v1.21")