ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
light_traits.h
Go to the documentation of this file.
1#pragma once
2
4#include "color_mode.h"
5#include <set>
6
7namespace esphome {
8
9#ifdef USE_API
10namespace api {
11class APIConnection;
12} // namespace api
13#endif
14
15namespace light {
16
19 public:
20 LightTraits() = default;
21
22 const std::set<ColorMode> &get_supported_color_modes() const { return this->supported_color_modes_; }
23 void set_supported_color_modes(std::set<ColorMode> supported_color_modes) {
24 this->supported_color_modes_ = std::move(supported_color_modes);
25 }
26
27 bool supports_color_mode(ColorMode color_mode) const { return this->supported_color_modes_.count(color_mode); }
28 bool supports_color_capability(ColorCapability color_capability) const {
29 for (auto mode : this->supported_color_modes_) {
30 if (mode & color_capability)
31 return true;
32 }
33 return false;
34 }
35
36 ESPDEPRECATED("get_supports_brightness() is deprecated, use color modes instead.", "v1.21")
37 bool get_supports_brightness() const { return this->supports_color_capability(ColorCapability::BRIGHTNESS); }
38 ESPDEPRECATED("get_supports_rgb() is deprecated, use color modes instead.", "v1.21")
39 bool get_supports_rgb() const { return this->supports_color_capability(ColorCapability::RGB); }
40 ESPDEPRECATED("get_supports_rgb_white_value() is deprecated, use color modes instead.", "v1.21")
41 bool get_supports_rgb_white_value() const {
44 }
45 ESPDEPRECATED("get_supports_color_temperature() is deprecated, use color modes instead.", "v1.21")
46 bool get_supports_color_temperature() const {
48 }
49 ESPDEPRECATED("get_supports_color_interlock() is deprecated, use color modes instead.", "v1.21")
50 bool get_supports_color_interlock() const {
51 return this->supports_color_mode(ColorMode::RGB) &&
54 }
55
56 float get_min_mireds() const { return this->min_mireds_; }
57 void set_min_mireds(float min_mireds) { this->min_mireds_ = min_mireds; }
58 float get_max_mireds() const { return this->max_mireds_; }
59 void set_max_mireds(float max_mireds) { this->max_mireds_ = max_mireds; }
60
61 protected:
62#ifdef USE_API
63 // The API connection is a friend class to access internal methods
64 friend class api::APIConnection;
65 // This method returns a reference to the internal color modes set.
66 // It is used by the API to avoid copying data when encoding messages.
67 // Warning: Do not use this method outside of the API connection code.
68 // It returns a reference to internal data that can be invalidated.
69 const std::set<ColorMode> &get_supported_color_modes_for_api_() const { return this->supported_color_modes_; }
70#endif
71
72 std::set<ColorMode> supported_color_modes_{};
73 float min_mireds_{0};
74 float max_mireds_{0};
75};
76
77} // namespace light
78} // namespace esphome
BedjetMode mode
BedJet operating mode.
This class is used to represent the capabilities of a light.
ESPDEPRECATED("get_supports_brightness() is deprecated, use color modes instead.", "v1.21") bool get_supports_brightness() const
ESPDEPRECATED("get_supports_rgb() is deprecated, use color modes instead.", "v1.21") bool get_supports_rgb() const
ESPDEPRECATED("get_supports_color_temperature() is deprecated, use color modes instead.", "v1.21") bool get_supports_color_temperature() const
ESPDEPRECATED("get_supports_rgb_white_value() is deprecated, use color modes instead.", "v1.21") bool get_supports_rgb_white_value() const
bool supports_color_mode(ColorMode color_mode) const
const std::set< ColorMode > & get_supported_color_modes() const
ESPDEPRECATED("get_supports_color_interlock() is deprecated, use color modes instead.", "v1.21") bool get_supports_color_interlock() const
void set_min_mireds(float min_mireds)
bool supports_color_capability(ColorCapability color_capability) const
const std::set< ColorMode > & get_supported_color_modes_for_api_() const
void set_supported_color_modes(std::set< ColorMode > supported_color_modes)
std::set< ColorMode > supported_color_modes_
void set_max_mireds(float max_mireds)
ColorMode
Color modes are a combination of color capabilities that can be used at the same time.
Definition color_mode.h:49
@ RGB_WHITE
RGB color output and a separate white output.
@ RGB_COLOR_TEMPERATURE
RGB color output and a separate white output with controllable color temperature.
@ RGB
RGB color output.
@ COLOR_TEMPERATURE
Controllable color temperature output.
@ WHITE
White output only (use only if the light also has another color mode such as RGB).
@ COLD_WARM_WHITE
Cold and warm white output with individually controllable brightness.
ColorCapability
Color capabilities are the various outputs that a light has and that can be independently controlled ...
Definition color_mode.h:9
@ BRIGHTNESS
Master brightness of the light can be controlled.
@ RGB
Color can be controlled using RGB format (includes a brightness control for the color).
@ COLOR_TEMPERATURE
Color temperature can be controlled.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7