ESPHome  2022.1.2
demo_light.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 namespace esphome {
7 namespace demo {
8 
9 enum class DemoLightType {
10  // binary
11  TYPE_1,
12  // brightness
13  TYPE_2,
14  // RGB
15  TYPE_3,
16  // RGBW
17  TYPE_4,
18  // RGBWW
19  TYPE_5,
20  // CWWW
21  TYPE_6,
22  // RGBW + color_interlock
23  TYPE_7,
24 };
25 
26 class DemoLight : public light::LightOutput, public Component {
27  public:
28  void set_type(DemoLightType type) { type_ = type; }
30  light::LightTraits traits{};
31  switch (type_) {
33  traits.set_supported_color_modes({light::ColorMode::ON_OFF});
34  break;
36  traits.set_supported_color_modes({light::ColorMode::BRIGHTNESS});
37  break;
39  traits.set_supported_color_modes({light::ColorMode::RGB});
40  break;
42  traits.set_supported_color_modes({light::ColorMode::RGB_WHITE});
43  break;
45  traits.set_supported_color_modes({light::ColorMode::RGB_COLOR_TEMPERATURE});
46  traits.set_min_mireds(153);
47  traits.set_max_mireds(500);
48  break;
50  traits.set_supported_color_modes({light::ColorMode::COLD_WARM_WHITE});
51  traits.set_min_mireds(153);
52  traits.set_max_mireds(500);
53  break;
55  traits.set_supported_color_modes({light::ColorMode::RGB, light::ColorMode::WHITE});
56  break;
57  }
58  return traits;
59  }
60  void write_state(light::LightState *state) override {
61  // do nothing
62  }
63 
65 };
66 
67 } // namespace demo
68 } // namespace esphome
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition: light_state.h:30
Interface to write LightStates to hardware.
Definition: light_output.h:12
void write_state(light::LightState *state) override
Definition: demo_light.h:60
RGB color output and a separate white output.
Brightness of cold and warm white output can be controlled.
DemoLightType type_
Definition: demo_light.h:64
light::LightTraits get_traits() override
Definition: demo_light.h:29
Light can be turned on/off.
uint8_t type
void set_type(DemoLightType type)
Definition: demo_light.h:28
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
Library based on https://github.com/miguelbalboa/rfid and adapted to ESPHome by . ...
Definition: a4988.cpp:4
Color can be controlled using RGB format (includes a brightness control for the color).