14 static const char *
const TAG =
"mqtt.light";
22 this->subscribe_json(this->get_command_topic_(), [
this](
const std::string &topic, JsonObject root) {
23 LightCall call = this->state_->make_call();
29 this->state_->add_new_remote_values_callback([
this, f]() { this->defer(
"send", f); });
41 root[
"schema"] =
"json";
45 JsonArray color_modes = root.createNestedArray(
"supported_color_modes");
46 if (traits.supports_color_mode(ColorMode::ON_OFF))
47 color_modes.add(
"onoff");
48 if (traits.supports_color_mode(ColorMode::BRIGHTNESS))
49 color_modes.add(
"brightness");
51 color_modes.add(
"white");
52 if (traits.supports_color_mode(ColorMode::COLOR_TEMPERATURE) ||
53 traits.supports_color_mode(ColorMode::COLD_WARM_WHITE))
54 color_modes.add(
"color_temp");
56 color_modes.add(
"rgb");
57 if (traits.supports_color_mode(ColorMode::RGB_WHITE) ||
59 traits.supports_color_mode(ColorMode::RGB_COLOR_TEMPERATURE))
60 color_modes.add(
"rgbw");
61 if (traits.supports_color_mode(ColorMode::RGB_COLD_WARM_WHITE))
62 color_modes.add(
"rgbww");
65 if (traits.supports_color_capability(ColorCapability::BRIGHTNESS))
66 root[
"brightness"] =
true;
69 root[
"effect"] =
true;
72 effect_list.add(effect->get_name());
73 effect_list.add(
"None");
79 LOG_MQTT_COMPONENT(
true,
true)
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
light::LightState * get_state() const
void dump_config() override
bool supports_effects()
Return whether the light has any effects that meet the trait requirements.
constexpr const char *const MQTT_COLOR_MODE
bool publish_json(const std::string &topic, const json::json_build_t &f)
Construct and send a JSON MQTT message.
MQTTJSONLightComponent(light::LightState *state)
static void parse_json(LightState &state, LightCall &call, JsonObject root)
Parse the JSON state of a light to a LightCall.
Simple Helper struct used for Home Assistant MQTT send_discovery().
const std::vector< LightEffect * > & get_effects() const
Get all effects for this light state.
This class represents a requested change in a light state.
light::LightState * state_
static void dump_json(LightState &state, JsonObject root)
Dump the state of a light as JSON.
White output only (use only if the light also has another color mode such as RGB).
bool send_initial_state() override
constexpr const char * c_str() const
const EntityBase * get_entity() const override
std::string component_type() const override
Implementation of SPI Controller mode.
constexpr const char *const MQTT_EFFECT_LIST
void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
std::string get_state_topic_() const
Get the MQTT topic that new states will be shared to.
const StringRef & get_name() const