14static const char *
const TAG =
"mqtt.light";
47 root[
"schema"] =
"json";
52 JsonArray color_modes = root[
"supported_color_modes"].to<JsonArray>();
53 if (traits.supports_color_mode(ColorMode::ON_OFF))
54 color_modes.add(
"onoff");
55 if (traits.supports_color_mode(ColorMode::BRIGHTNESS))
56 color_modes.add(
"brightness");
57 if (traits.supports_color_mode(ColorMode::WHITE))
58 color_modes.add(
"white");
59 if (traits.supports_color_mode(ColorMode::COLOR_TEMPERATURE) ||
60 traits.supports_color_mode(ColorMode::COLD_WARM_WHITE))
61 color_modes.add(
"color_temp");
62 if (traits.supports_color_mode(ColorMode::RGB))
63 color_modes.add(
"rgb");
64 if (traits.supports_color_mode(ColorMode::RGB_WHITE) ||
66 traits.supports_color_mode(ColorMode::RGB_COLOR_TEMPERATURE))
67 color_modes.add(
"rgbw");
68 if (traits.supports_color_mode(ColorMode::RGB_COLD_WARM_WHITE))
69 color_modes.add(
"rgbww");
72 if (traits.supports_color_capability(ColorCapability::BRIGHTNESS))
73 root[
"brightness"] =
true;
75 if (traits.supports_color_mode(ColorMode::COLOR_TEMPERATURE) ||
76 traits.supports_color_mode(ColorMode::COLD_WARM_WHITE)) {
82 root[
"effect"] =
true;
85 effect_list.add(effect->get_name());
86 effect_list.add(
"None");
92 LOG_MQTT_COMPONENT(
true,
true)
void defer(const std::string &name, std::function< void()> &&f)
Defer a callback to the next loop() call.
const StringRef & get_name() const
constexpr const char * c_str() const
This class represents a requested change in a light state.
static void parse_json(LightState &state, LightCall &call, JsonObject root)
Parse the JSON state of a light to a LightCall.
static void dump_json(LightState &state, JsonObject root)
Dump the state of a light as JSON.
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
void add_remote_values_listener(LightRemoteValuesListener *listener)
Add a listener for remote values changes.
const FixedVector< LightEffect * > & get_effects() const
Get all effects for this light state.
bool supports_effects()
Return whether the light has any effects that meet the trait requirements.
void subscribe_json(const std::string &topic, const mqtt_json_callback_t &callback, uint8_t qos=0)
Subscribe to a MQTT topic and automatically parse JSON payload.
bool publish_json(const std::string &topic, const json::json_build_t &f)
Construct and send a JSON MQTT message.
std::string get_state_topic_() const
Get the MQTT topic that new states will be shared to.
std::string get_command_topic_() const
Get the MQTT topic for listening to commands.
void dump_config() override
light::LightState * state_
MQTTJSONLightComponent(light::LightState *state)
void on_light_remote_values_update() override
const EntityBase * get_entity() const override
void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
bool send_initial_state() override
light::LightState * get_state() const
std::string component_type() const override
constexpr const char *const MQTT_COLOR_MODE
constexpr const char *const MQTT_EFFECT_LIST
constexpr const char *const MQTT_MIN_MIREDS
constexpr const char *const MQTT_MAX_MIREDS
Providing packet encoding functions for exchanging data with a remote host.
Simple Helper struct used for Home Assistant MQTT send_discovery().