ESPHome  2022.9.3
light_traits.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "esphome/core/helpers.h"
4 #include "color_mode.h"
5 #include <set>
6 
7 namespace esphome {
8 namespace light {
9 
11 class LightTraits {
12  public:
13  LightTraits() = default;
14 
15  const std::set<ColorMode> &get_supported_color_modes() const { return this->supported_color_modes_; }
16  void set_supported_color_modes(std::set<ColorMode> supported_color_modes) {
17  this->supported_color_modes_ = std::move(supported_color_modes);
18  }
19 
20  bool supports_color_mode(ColorMode color_mode) const { return this->supported_color_modes_.count(color_mode); }
21  bool supports_color_capability(ColorCapability color_capability) const {
22  for (auto mode : this->supported_color_modes_) {
23  if (mode & color_capability)
24  return true;
25  }
26  return false;
27  }
28 
29  ESPDEPRECATED("get_supports_brightness() is deprecated, use color modes instead.", "v1.21")
30  bool get_supports_brightness() const { return this->supports_color_capability(ColorCapability::BRIGHTNESS); }
31  ESPDEPRECATED("get_supports_rgb() is deprecated, use color modes instead.", "v1.21")
32  bool get_supports_rgb() const { return this->supports_color_capability(ColorCapability::RGB); }
33  ESPDEPRECATED("get_supports_rgb_white_value() is deprecated, use color modes instead.", "v1.21")
34  bool get_supports_rgb_white_value() const {
37  }
38  ESPDEPRECATED("get_supports_color_temperature() is deprecated, use color modes instead.", "v1.21")
39  bool get_supports_color_temperature() const {
41  }
42  ESPDEPRECATED("get_supports_color_interlock() is deprecated, use color modes instead.", "v1.21")
43  bool get_supports_color_interlock() const {
44  return this->supports_color_mode(ColorMode::RGB) &&
47  }
48 
49  float get_min_mireds() const { return this->min_mireds_; }
50  void set_min_mireds(float min_mireds) { this->min_mireds_ = min_mireds; }
51  float get_max_mireds() const { return this->max_mireds_; }
52  void set_max_mireds(float max_mireds) { this->max_mireds_ = max_mireds; }
53 
54  protected:
55  std::set<ColorMode> supported_color_modes_{};
56  float min_mireds_{0};
57  float max_mireds_{0};
58 };
59 
60 } // namespace light
61 } // namespace esphome
ColorMode
Color modes are a combination of color capabilities that can be used at the same time.
Definition: color_mode.h:49
std::set< ColorMode > supported_color_modes_
Definition: light_traits.h:55
ESPDEPRECATED("get_supports_color_interlock() is deprecated, use color modes instead.", "v1.21") bool get_supports_color_interlock() const
Definition: light_traits.h:42
float get_min_mireds() const
Definition: light_traits.h:49
RGB color output and a separate white output.
Color temperature can be controlled.
ESPDEPRECATED("get_supports_color_temperature() is deprecated, use color modes instead.", "v1.21") bool get_supports_color_temperature() const
Definition: light_traits.h:38
void set_max_mireds(float max_mireds)
Definition: light_traits.h:52
ESPDEPRECATED("get_supports_brightness() is deprecated, use color modes instead.", "v1.21") bool get_supports_brightness() const
Definition: light_traits.h:29
void set_min_mireds(float min_mireds)
Definition: light_traits.h:50
Brightness of cold and warm white output can be controlled.
const std::set< ColorMode > & get_supported_color_modes() const
Definition: light_traits.h:15
BedjetMode mode
BedJet operating mode.
Definition: bedjet_codec.h:151
bool supports_color_capability(ColorCapability color_capability) const
Definition: light_traits.h:21
RGB color output and a separate white output with controllable color temperature. ...
Master brightness of the light can be controlled.
White output only (use only if the light also has another color mode such as RGB).
This class is used to represent the capabilities of a light.
Definition: light_traits.h:11
bool supports_color_mode(ColorMode color_mode) const
Definition: light_traits.h:20
ColorCapability
Color capabilities are the various outputs that a light has and that can be independently controlled ...
Definition: color_mode.h:9
ESPDEPRECATED("get_supports_rgb() is deprecated, use color modes instead.", "v1.21") bool get_supports_rgb() const
Definition: light_traits.h:31
Definition: a4988.cpp:4
Color can be controlled using RGB format (includes a brightness control for the color).
float get_max_mireds() const
Definition: light_traits.h:51
void set_supported_color_modes(std::set< ColorMode > supported_color_modes)
Definition: light_traits.h:16
ESPDEPRECATED("get_supports_rgb_white_value() is deprecated, use color modes instead.", "v1.21") bool get_supports_rgb_white_value() const
Definition: light_traits.h:33