mirror of
https://github.com/esphome/esphome.git
synced 2025-08-03 17:07:54 +00:00
update createdNestedArray calls
This commit is contained in:
parent
8648acab5d
commit
8040c7cd92
@ -55,7 +55,7 @@ void MQTTAlarmControlPanelComponent::dump_config() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MQTTAlarmControlPanelComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
void MQTTAlarmControlPanelComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||||
JsonArray supported_features = root.createNestedArray(MQTT_SUPPORTED_FEATURES);
|
JsonArray supported_features = root[MQTT_SUPPORTED_FEATURES].to<JsonArray>();
|
||||||
const uint32_t acp_supported_features = this->alarm_control_panel_->get_supported_features();
|
const uint32_t acp_supported_features = this->alarm_control_panel_->get_supported_features();
|
||||||
if (acp_supported_features & ACP_FEAT_ARM_AWAY) {
|
if (acp_supported_features & ACP_FEAT_ARM_AWAY) {
|
||||||
supported_features.add("arm_away");
|
supported_features.add("arm_away");
|
||||||
|
@ -28,7 +28,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo
|
|||||||
// mode_state_topic
|
// mode_state_topic
|
||||||
root[MQTT_MODE_STATE_TOPIC] = this->get_mode_state_topic();
|
root[MQTT_MODE_STATE_TOPIC] = this->get_mode_state_topic();
|
||||||
// modes
|
// modes
|
||||||
JsonArray modes = root.createNestedArray(MQTT_MODES);
|
JsonArray modes = root[MQTT_MODES].to<JsonArray>();
|
||||||
// sort array for nice UI in HA
|
// sort array for nice UI in HA
|
||||||
if (traits.supports_mode(CLIMATE_MODE_AUTO))
|
if (traits.supports_mode(CLIMATE_MODE_AUTO))
|
||||||
modes.add("auto");
|
modes.add("auto");
|
||||||
@ -89,7 +89,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo
|
|||||||
// preset_mode_state_topic
|
// preset_mode_state_topic
|
||||||
root[MQTT_PRESET_MODE_STATE_TOPIC] = this->get_preset_state_topic();
|
root[MQTT_PRESET_MODE_STATE_TOPIC] = this->get_preset_state_topic();
|
||||||
// presets
|
// presets
|
||||||
JsonArray presets = root.createNestedArray("preset_modes");
|
JsonArray presets = root["preset_modes"].to<JsonArray>();
|
||||||
if (traits.supports_preset(CLIMATE_PRESET_HOME))
|
if (traits.supports_preset(CLIMATE_PRESET_HOME))
|
||||||
presets.add("home");
|
presets.add("home");
|
||||||
if (traits.supports_preset(CLIMATE_PRESET_AWAY))
|
if (traits.supports_preset(CLIMATE_PRESET_AWAY))
|
||||||
@ -119,7 +119,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo
|
|||||||
// fan_mode_state_topic
|
// fan_mode_state_topic
|
||||||
root[MQTT_FAN_MODE_STATE_TOPIC] = this->get_fan_mode_state_topic();
|
root[MQTT_FAN_MODE_STATE_TOPIC] = this->get_fan_mode_state_topic();
|
||||||
// fan_modes
|
// fan_modes
|
||||||
JsonArray fan_modes = root.createNestedArray("fan_modes");
|
JsonArray fan_modes = root["fan_modes"].to<JsonArray>();
|
||||||
if (traits.supports_fan_mode(CLIMATE_FAN_ON))
|
if (traits.supports_fan_mode(CLIMATE_FAN_ON))
|
||||||
fan_modes.add("on");
|
fan_modes.add("on");
|
||||||
if (traits.supports_fan_mode(CLIMATE_FAN_OFF))
|
if (traits.supports_fan_mode(CLIMATE_FAN_OFF))
|
||||||
@ -150,7 +150,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo
|
|||||||
// swing_mode_state_topic
|
// swing_mode_state_topic
|
||||||
root[MQTT_SWING_MODE_STATE_TOPIC] = this->get_swing_mode_state_topic();
|
root[MQTT_SWING_MODE_STATE_TOPIC] = this->get_swing_mode_state_topic();
|
||||||
// swing_modes
|
// swing_modes
|
||||||
JsonArray swing_modes = root.createNestedArray("swing_modes");
|
JsonArray swing_modes = root["swing_modes"].to<JsonArray>();
|
||||||
if (traits.supports_swing_mode(CLIMATE_SWING_OFF))
|
if (traits.supports_swing_mode(CLIMATE_SWING_OFF))
|
||||||
swing_modes.add("off");
|
swing_modes.add("off");
|
||||||
if (traits.supports_swing_mode(CLIMATE_SWING_BOTH))
|
if (traits.supports_swing_mode(CLIMATE_SWING_BOTH))
|
||||||
|
@ -16,7 +16,7 @@ using namespace esphome::event;
|
|||||||
MQTTEventComponent::MQTTEventComponent(event::Event *event) : event_(event) {}
|
MQTTEventComponent::MQTTEventComponent(event::Event *event) : event_(event) {}
|
||||||
|
|
||||||
void MQTTEventComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
void MQTTEventComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||||
JsonArray event_types = root.createNestedArray(MQTT_EVENT_TYPES);
|
JsonArray event_types = root[MQTT_EVENT_TYPES].to<JsonArray>();
|
||||||
for (const auto &event_type : this->event_->get_event_types())
|
for (const auto &event_type : this->event_->get_event_types())
|
||||||
event_types.add(event_type);
|
event_types.add(event_type);
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ void MQTTJSONLightComponent::send_discovery(JsonObject root, mqtt::SendDiscovery
|
|||||||
auto traits = this->state_->get_traits();
|
auto traits = this->state_->get_traits();
|
||||||
|
|
||||||
root[MQTT_COLOR_MODE] = true;
|
root[MQTT_COLOR_MODE] = true;
|
||||||
JsonArray color_modes = root.createNestedArray("supported_color_modes");
|
JsonArray color_modes = root["supported_color_modes"].to<JsonArray>();
|
||||||
if (traits.supports_color_mode(ColorMode::ON_OFF))
|
if (traits.supports_color_mode(ColorMode::ON_OFF))
|
||||||
color_modes.add("onoff");
|
color_modes.add("onoff");
|
||||||
if (traits.supports_color_mode(ColorMode::BRIGHTNESS))
|
if (traits.supports_color_mode(ColorMode::BRIGHTNESS))
|
||||||
@ -67,7 +67,7 @@ void MQTTJSONLightComponent::send_discovery(JsonObject root, mqtt::SendDiscovery
|
|||||||
|
|
||||||
if (this->state_->supports_effects()) {
|
if (this->state_->supports_effects()) {
|
||||||
root["effect"] = true;
|
root["effect"] = true;
|
||||||
JsonArray effect_list = root.createNestedArray(MQTT_EFFECT_LIST);
|
JsonArray effect_list = root[MQTT_EFFECT_LIST].to<JsonArray>();
|
||||||
for (auto *effect : this->state_->get_effects())
|
for (auto *effect : this->state_->get_effects())
|
||||||
effect_list.add(effect->get_name());
|
effect_list.add(effect->get_name());
|
||||||
effect_list.add("None");
|
effect_list.add("None");
|
||||||
|
@ -35,7 +35,7 @@ const EntityBase *MQTTSelectComponent::get_entity() const { return this->select_
|
|||||||
void MQTTSelectComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
void MQTTSelectComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
|
||||||
const auto &traits = select_->traits;
|
const auto &traits = select_->traits;
|
||||||
// https://www.home-assistant.io/integrations/select.mqtt/
|
// https://www.home-assistant.io/integrations/select.mqtt/
|
||||||
JsonArray options = root.createNestedArray(MQTT_OPTIONS);
|
JsonArray options = root[MQTT_OPTIONS].to<JsonArray>();
|
||||||
for (const auto &option : traits.get_options())
|
for (const auto &option : traits.get_options())
|
||||||
options.add(option);
|
options.add(option);
|
||||||
|
|
||||||
|
@ -792,7 +792,7 @@ std::string WebServer::light_json(light::LightState *obj, JsonDetail start_confi
|
|||||||
|
|
||||||
light::LightJSONSchema::dump_json(*obj, root);
|
light::LightJSONSchema::dump_json(*obj, root);
|
||||||
if (start_config == DETAIL_ALL) {
|
if (start_config == DETAIL_ALL) {
|
||||||
JsonArray opt = root.createNestedArray("effects");
|
JsonArray opt = root["effects"].to<JsonArray>();
|
||||||
opt.add("None");
|
opt.add("None");
|
||||||
for (auto const &option : obj->get_effects()) {
|
for (auto const &option : obj->get_effects()) {
|
||||||
opt.add(option->get_name());
|
opt.add(option->get_name());
|
||||||
@ -1238,7 +1238,7 @@ std::string WebServer::select_json(select::Select *obj, const std::string &value
|
|||||||
return json::build_json([this, obj, value, start_config](JsonObject root) {
|
return json::build_json([this, obj, value, start_config](JsonObject root) {
|
||||||
set_json_icon_state_value(root, obj, "select-" + obj->get_object_id(), value, value, start_config);
|
set_json_icon_state_value(root, obj, "select-" + obj->get_object_id(), value, value, start_config);
|
||||||
if (start_config == DETAIL_ALL) {
|
if (start_config == DETAIL_ALL) {
|
||||||
JsonArray opt = root.createNestedArray("option");
|
JsonArray opt = root["option"].to<JsonArray>();
|
||||||
for (auto &option : obj->traits.get_options()) {
|
for (auto &option : obj->traits.get_options()) {
|
||||||
opt.add(option);
|
opt.add(option);
|
||||||
}
|
}
|
||||||
@ -1330,32 +1330,32 @@ std::string WebServer::climate_json(climate::Climate *obj, JsonDetail start_conf
|
|||||||
char buf[16];
|
char buf[16];
|
||||||
|
|
||||||
if (start_config == DETAIL_ALL) {
|
if (start_config == DETAIL_ALL) {
|
||||||
JsonArray opt = root.createNestedArray("modes");
|
JsonArray opt = root["modes"].to<JsonArray>();
|
||||||
for (climate::ClimateMode m : traits.get_supported_modes())
|
for (climate::ClimateMode m : traits.get_supported_modes())
|
||||||
opt.add(PSTR_LOCAL(climate::climate_mode_to_string(m)));
|
opt.add(PSTR_LOCAL(climate::climate_mode_to_string(m)));
|
||||||
if (!traits.get_supported_custom_fan_modes().empty()) {
|
if (!traits.get_supported_custom_fan_modes().empty()) {
|
||||||
JsonArray opt = root.createNestedArray("fan_modes");
|
JsonArray opt = root["fan_modes"].to<JsonArray>();
|
||||||
for (climate::ClimateFanMode m : traits.get_supported_fan_modes())
|
for (climate::ClimateFanMode m : traits.get_supported_fan_modes())
|
||||||
opt.add(PSTR_LOCAL(climate::climate_fan_mode_to_string(m)));
|
opt.add(PSTR_LOCAL(climate::climate_fan_mode_to_string(m)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!traits.get_supported_custom_fan_modes().empty()) {
|
if (!traits.get_supported_custom_fan_modes().empty()) {
|
||||||
JsonArray opt = root.createNestedArray("custom_fan_modes");
|
JsonArray opt = root["custom_fan_modes"].to<JsonArray>();
|
||||||
for (auto const &custom_fan_mode : traits.get_supported_custom_fan_modes())
|
for (auto const &custom_fan_mode : traits.get_supported_custom_fan_modes())
|
||||||
opt.add(custom_fan_mode);
|
opt.add(custom_fan_mode);
|
||||||
}
|
}
|
||||||
if (traits.get_supports_swing_modes()) {
|
if (traits.get_supports_swing_modes()) {
|
||||||
JsonArray opt = root.createNestedArray("swing_modes");
|
JsonArray opt = root["swing_modes"].to<JsonArray>();
|
||||||
for (auto swing_mode : traits.get_supported_swing_modes())
|
for (auto swing_mode : traits.get_supported_swing_modes())
|
||||||
opt.add(PSTR_LOCAL(climate::climate_swing_mode_to_string(swing_mode)));
|
opt.add(PSTR_LOCAL(climate::climate_swing_mode_to_string(swing_mode)));
|
||||||
}
|
}
|
||||||
if (traits.get_supports_presets() && obj->preset.has_value()) {
|
if (traits.get_supports_presets() && obj->preset.has_value()) {
|
||||||
JsonArray opt = root.createNestedArray("presets");
|
JsonArray opt = root["presets"].to<JsonArray>();
|
||||||
for (climate::ClimatePreset m : traits.get_supported_presets())
|
for (climate::ClimatePreset m : traits.get_supported_presets())
|
||||||
opt.add(PSTR_LOCAL(climate::climate_preset_to_string(m)));
|
opt.add(PSTR_LOCAL(climate::climate_preset_to_string(m)));
|
||||||
}
|
}
|
||||||
if (!traits.get_supported_custom_presets().empty() && obj->custom_preset.has_value()) {
|
if (!traits.get_supported_custom_presets().empty() && obj->custom_preset.has_value()) {
|
||||||
JsonArray opt = root.createNestedArray("custom_presets");
|
JsonArray opt = root["custom_presets"].to<JsonArray>();
|
||||||
for (auto const &custom_preset : traits.get_supported_custom_presets())
|
for (auto const &custom_preset : traits.get_supported_custom_presets())
|
||||||
opt.add(custom_preset);
|
opt.add(custom_preset);
|
||||||
}
|
}
|
||||||
@ -1635,7 +1635,7 @@ std::string WebServer::event_json(event::Event *obj, const std::string &event_ty
|
|||||||
root["event_type"] = event_type;
|
root["event_type"] = event_type;
|
||||||
}
|
}
|
||||||
if (start_config == DETAIL_ALL) {
|
if (start_config == DETAIL_ALL) {
|
||||||
JsonArray event_types = root.createNestedArray("event_types");
|
JsonArray event_types = root["event_types"].to<JsonArray>();
|
||||||
for (auto const &event_type : obj->get_event_types()) {
|
for (auto const &event_type : obj->get_event_types()) {
|
||||||
event_types.add(event_type);
|
event_types.add(event_type);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user