esphome 2025.7.0b2__py3-none-any.whl → 2025.7.0b4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. esphome/components/async_tcp/__init__.py +1 -1
  2. esphome/components/esp_ldo/__init__.py +10 -8
  3. esphome/components/esp_ldo/esp_ldo.h +3 -0
  4. esphome/components/fan/fan.cpp +4 -0
  5. esphome/components/gpio/binary_sensor/__init__.py +24 -3
  6. esphome/components/http_request/update/http_request_update.cpp +7 -7
  7. esphome/components/i2s_audio/speaker/__init__.py +1 -1
  8. esphome/components/json/__init__.py +1 -1
  9. esphome/components/json/json_util.cpp +56 -63
  10. esphome/components/ld2420/binary_sensor/ld2420_binary_sensor.cpp +2 -2
  11. esphome/components/ld2420/button/reconfig_buttons.cpp +1 -1
  12. esphome/components/ld2420/ld2420.cpp +66 -57
  13. esphome/components/ld2420/ld2420.h +9 -11
  14. esphome/components/ld2420/number/gate_config_number.cpp +1 -1
  15. esphome/components/ld2420/select/operating_mode_select.cpp +1 -1
  16. esphome/components/ld2420/sensor/ld2420_sensor.cpp +2 -2
  17. esphome/components/ld2420/text_sensor/text_sensor.cpp +2 -2
  18. esphome/components/light/light_json_schema.cpp +17 -16
  19. esphome/components/lvgl/widgets/meter.py +20 -13
  20. esphome/components/mqtt/mqtt_alarm_control_panel.cpp +2 -1
  21. esphome/components/mqtt/mqtt_binary_sensor.cpp +1 -0
  22. esphome/components/mqtt/mqtt_button.cpp +4 -1
  23. esphome/components/mqtt/mqtt_client.cpp +2 -0
  24. esphome/components/mqtt/mqtt_climate.cpp +6 -4
  25. esphome/components/mqtt/mqtt_component.cpp +3 -1
  26. esphome/components/mqtt/mqtt_cover.cpp +1 -0
  27. esphome/components/mqtt/mqtt_date.cpp +4 -3
  28. esphome/components/mqtt/mqtt_datetime.cpp +7 -6
  29. esphome/components/mqtt/mqtt_event.cpp +6 -3
  30. esphome/components/mqtt/mqtt_fan.cpp +1 -0
  31. esphome/components/mqtt/mqtt_light.cpp +8 -4
  32. esphome/components/mqtt/mqtt_lock.cpp +3 -1
  33. esphome/components/mqtt/mqtt_number.cpp +1 -0
  34. esphome/components/mqtt/mqtt_select.cpp +2 -1
  35. esphome/components/mqtt/mqtt_sensor.cpp +3 -1
  36. esphome/components/mqtt/mqtt_switch.cpp +3 -1
  37. esphome/components/mqtt/mqtt_text.cpp +1 -0
  38. esphome/components/mqtt/mqtt_text_sensor.cpp +3 -1
  39. esphome/components/mqtt/mqtt_time.cpp +4 -3
  40. esphome/components/mqtt/mqtt_update.cpp +1 -0
  41. esphome/components/mqtt/mqtt_valve.cpp +3 -1
  42. esphome/components/ms8607/ms8607.cpp +1 -1
  43. esphome/components/online_image/__init__.py +4 -1
  44. esphome/components/online_image/online_image.cpp +11 -5
  45. esphome/components/online_image/online_image.h +6 -1
  46. esphome/components/opentherm/output/output.cpp +1 -1
  47. esphome/components/servo/servo.cpp +2 -2
  48. esphome/components/substitutions/__init__.py +5 -2
  49. esphome/components/web_server/web_server.cpp +13 -9
  50. esphome/components/web_server_base/__init__.py +1 -1
  51. esphome/components/web_server_idf/web_server_idf.cpp +2 -0
  52. esphome/const.py +1 -1
  53. esphome/core/component.cpp +9 -8
  54. esphome/core/helpers.h +1 -1
  55. esphome/platformio_api.py +2 -0
  56. esphome/writer.py +23 -0
  57. {esphome-2025.7.0b2.dist-info → esphome-2025.7.0b4.dist-info}/METADATA +1 -1
  58. {esphome-2025.7.0b2.dist-info → esphome-2025.7.0b4.dist-info}/RECORD +62 -62
  59. {esphome-2025.7.0b2.dist-info → esphome-2025.7.0b4.dist-info}/WHEEL +0 -0
  60. {esphome-2025.7.0b2.dist-info → esphome-2025.7.0b4.dist-info}/entry_points.txt +0 -0
  61. {esphome-2025.7.0b2.dist-info → esphome-2025.7.0b4.dist-info}/licenses/LICENSE +0 -0
  62. {esphome-2025.7.0b2.dist-info → esphome-2025.7.0b4.dist-info}/top_level.txt +0 -0
@@ -5,10 +5,10 @@
5
5
  namespace esphome {
6
6
  namespace ld2420 {
7
7
 
8
- static const char *const TAG = "LD2420.text_sensor";
8
+ static const char *const TAG = "ld2420.text_sensor";
9
9
 
10
10
  void LD2420TextSensor::dump_config() {
11
- ESP_LOGCONFIG(TAG, "LD2420 TextSensor:");
11
+ ESP_LOGCONFIG(TAG, "Text Sensor:");
12
12
  LOG_TEXT_SENSOR(" ", "Firmware", this->fw_version_text_sensor_);
13
13
  }
14
14
 
@@ -9,6 +9,7 @@ namespace light {
9
9
  // See https://www.home-assistant.io/integrations/light.mqtt/#json-schema for documentation on the schema
10
10
 
11
11
  void LightJSONSchema::dump_json(LightState &state, JsonObject root) {
12
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
12
13
  if (state.supports_effects())
13
14
  root["effect"] = state.get_effect_name();
14
15
 
@@ -52,7 +53,7 @@ void LightJSONSchema::dump_json(LightState &state, JsonObject root) {
52
53
  if (values.get_color_mode() & ColorCapability::BRIGHTNESS)
53
54
  root["brightness"] = uint8_t(values.get_brightness() * 255);
54
55
 
55
- JsonObject color = root.createNestedObject("color");
56
+ JsonObject color = root["color"].to<JsonObject>();
56
57
  if (values.get_color_mode() & ColorCapability::RGB) {
57
58
  color["r"] = uint8_t(values.get_color_brightness() * values.get_red() * 255);
58
59
  color["g"] = uint8_t(values.get_color_brightness() * values.get_green() * 255);
@@ -73,7 +74,7 @@ void LightJSONSchema::dump_json(LightState &state, JsonObject root) {
73
74
  }
74
75
 
75
76
  void LightJSONSchema::parse_color_json(LightState &state, LightCall &call, JsonObject root) {
76
- if (root.containsKey("state")) {
77
+ if (root["state"].is<const char *>()) {
77
78
  auto val = parse_on_off(root["state"]);
78
79
  switch (val) {
79
80
  case PARSE_ON:
@@ -90,40 +91,40 @@ void LightJSONSchema::parse_color_json(LightState &state, LightCall &call, JsonO
90
91
  }
91
92
  }
92
93
 
93
- if (root.containsKey("brightness")) {
94
+ if (root["brightness"].is<uint8_t>()) {
94
95
  call.set_brightness(float(root["brightness"]) / 255.0f);
95
96
  }
96
97
 
97
- if (root.containsKey("color")) {
98
+ if (root["color"].is<JsonObject>()) {
98
99
  JsonObject color = root["color"];
99
100
  // HA also encodes brightness information in the r, g, b values, so extract that and set it as color brightness.
100
101
  float max_rgb = 0.0f;
101
- if (color.containsKey("r")) {
102
+ if (color["r"].is<uint8_t>()) {
102
103
  float r = float(color["r"]) / 255.0f;
103
104
  max_rgb = fmaxf(max_rgb, r);
104
105
  call.set_red(r);
105
106
  }
106
- if (color.containsKey("g")) {
107
+ if (color["g"].is<uint8_t>()) {
107
108
  float g = float(color["g"]) / 255.0f;
108
109
  max_rgb = fmaxf(max_rgb, g);
109
110
  call.set_green(g);
110
111
  }
111
- if (color.containsKey("b")) {
112
+ if (color["b"].is<uint8_t>()) {
112
113
  float b = float(color["b"]) / 255.0f;
113
114
  max_rgb = fmaxf(max_rgb, b);
114
115
  call.set_blue(b);
115
116
  }
116
- if (color.containsKey("r") || color.containsKey("g") || color.containsKey("b")) {
117
+ if (color["r"].is<uint8_t>() || color["g"].is<uint8_t>() || color["b"].is<uint8_t>()) {
117
118
  call.set_color_brightness(max_rgb);
118
119
  }
119
120
 
120
- if (color.containsKey("c")) {
121
+ if (color["c"].is<uint8_t>()) {
121
122
  call.set_cold_white(float(color["c"]) / 255.0f);
122
123
  }
123
- if (color.containsKey("w")) {
124
+ if (color["w"].is<uint8_t>()) {
124
125
  // the HA scheme is ambiguous here, the same key is used for white channel in RGBW and warm
125
126
  // white channel in RGBWW.
126
- if (color.containsKey("c")) {
127
+ if (color["c"].is<uint8_t>()) {
127
128
  call.set_warm_white(float(color["w"]) / 255.0f);
128
129
  } else {
129
130
  call.set_white(float(color["w"]) / 255.0f);
@@ -131,11 +132,11 @@ void LightJSONSchema::parse_color_json(LightState &state, LightCall &call, JsonO
131
132
  }
132
133
  }
133
134
 
134
- if (root.containsKey("white_value")) { // legacy API
135
+ if (root["white_value"].is<uint8_t>()) { // legacy API
135
136
  call.set_white(float(root["white_value"]) / 255.0f);
136
137
  }
137
138
 
138
- if (root.containsKey("color_temp")) {
139
+ if (root["color_temp"].is<uint16_t>()) {
139
140
  call.set_color_temperature(float(root["color_temp"]));
140
141
  }
141
142
  }
@@ -143,17 +144,17 @@ void LightJSONSchema::parse_color_json(LightState &state, LightCall &call, JsonO
143
144
  void LightJSONSchema::parse_json(LightState &state, LightCall &call, JsonObject root) {
144
145
  LightJSONSchema::parse_color_json(state, call, root);
145
146
 
146
- if (root.containsKey("flash")) {
147
+ if (root["flash"].is<uint32_t>()) {
147
148
  auto length = uint32_t(float(root["flash"]) * 1000);
148
149
  call.set_flash_length(length);
149
150
  }
150
151
 
151
- if (root.containsKey("transition")) {
152
+ if (root["transition"].is<uint16_t>()) {
152
153
  auto length = uint32_t(float(root["transition"]) * 1000);
153
154
  call.set_transition_length(length);
154
155
  }
155
156
 
156
- if (root.containsKey("effect")) {
157
+ if (root["effect"].is<const char *>()) {
157
158
  const char *effect = root["effect"];
158
159
  call.set_effect(effect);
159
160
  }
@@ -29,9 +29,9 @@ from ..defines import (
29
29
  )
30
30
  from ..helpers import add_lv_use, lvgl_components_required
31
31
  from ..lv_validation import (
32
- angle,
33
32
  get_end_value,
34
33
  get_start_value,
34
+ lv_angle,
35
35
  lv_bool,
36
36
  lv_color,
37
37
  lv_float,
@@ -162,7 +162,7 @@ SCALE_SCHEMA = cv.Schema(
162
162
  cv.Optional(CONF_RANGE_FROM, default=0.0): cv.float_,
163
163
  cv.Optional(CONF_RANGE_TO, default=100.0): cv.float_,
164
164
  cv.Optional(CONF_ANGLE_RANGE, default=270): cv.int_range(0, 360),
165
- cv.Optional(CONF_ROTATION): angle,
165
+ cv.Optional(CONF_ROTATION): lv_angle,
166
166
  cv.Optional(CONF_INDICATORS): cv.ensure_list(INDICATOR_SCHEMA),
167
167
  }
168
168
  )
@@ -187,7 +187,7 @@ class MeterType(WidgetType):
187
187
  for scale_conf in config.get(CONF_SCALES, ()):
188
188
  rotation = 90 + (360 - scale_conf[CONF_ANGLE_RANGE]) / 2
189
189
  if CONF_ROTATION in scale_conf:
190
- rotation = scale_conf[CONF_ROTATION] // 10
190
+ rotation = await lv_angle.process(scale_conf[CONF_ROTATION])
191
191
  with LocalVariable(
192
192
  "meter_var", "lv_meter_scale_t", lv_expr.meter_add_scale(var)
193
193
  ) as meter_var:
@@ -205,21 +205,20 @@ class MeterType(WidgetType):
205
205
  var,
206
206
  meter_var,
207
207
  ticks[CONF_COUNT],
208
- ticks[CONF_WIDTH],
209
- ticks[CONF_LENGTH],
208
+ await size.process(ticks[CONF_WIDTH]),
209
+ await size.process(ticks[CONF_LENGTH]),
210
210
  color,
211
211
  )
212
212
  if CONF_MAJOR in ticks:
213
213
  major = ticks[CONF_MAJOR]
214
- color = await lv_color.process(major[CONF_COLOR])
215
214
  lv.meter_set_scale_major_ticks(
216
215
  var,
217
216
  meter_var,
218
217
  major[CONF_STRIDE],
219
- major[CONF_WIDTH],
220
- major[CONF_LENGTH],
221
- color,
222
- major[CONF_LABEL_GAP],
218
+ await size.process(major[CONF_WIDTH]),
219
+ await size.process(major[CONF_LENGTH]),
220
+ await lv_color.process(major[CONF_COLOR]),
221
+ await size.process(major[CONF_LABEL_GAP]),
223
222
  )
224
223
  for indicator in scale_conf.get(CONF_INDICATORS, ()):
225
224
  (t, v) = next(iter(indicator.items()))
@@ -233,7 +232,11 @@ class MeterType(WidgetType):
233
232
  lv_assign(
234
233
  ivar,
235
234
  lv_expr.meter_add_needle_line(
236
- var, meter_var, v[CONF_WIDTH], color, v[CONF_R_MOD]
235
+ var,
236
+ meter_var,
237
+ await size.process(v[CONF_WIDTH]),
238
+ color,
239
+ await size.process(v[CONF_R_MOD]),
237
240
  ),
238
241
  )
239
242
  if t == CONF_ARC:
@@ -241,7 +244,11 @@ class MeterType(WidgetType):
241
244
  lv_assign(
242
245
  ivar,
243
246
  lv_expr.meter_add_arc(
244
- var, meter_var, v[CONF_WIDTH], color, v[CONF_R_MOD]
247
+ var,
248
+ meter_var,
249
+ await size.process(v[CONF_WIDTH]),
250
+ color,
251
+ await size.process(v[CONF_R_MOD]),
245
252
  ),
246
253
  )
247
254
  if t == CONF_TICK_STYLE:
@@ -257,7 +264,7 @@ class MeterType(WidgetType):
257
264
  color_start,
258
265
  color_end,
259
266
  v[CONF_LOCAL],
260
- v[CONF_WIDTH],
267
+ size.process(v[CONF_WIDTH]),
261
268
  ),
262
269
  )
263
270
  if t == CONF_IMAGE:
@@ -55,7 +55,8 @@ void MQTTAlarmControlPanelComponent::dump_config() {
55
55
  }
56
56
 
57
57
  void MQTTAlarmControlPanelComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
58
- JsonArray supported_features = root.createNestedArray(MQTT_SUPPORTED_FEATURES);
58
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
59
+ JsonArray supported_features = root[MQTT_SUPPORTED_FEATURES].to<JsonArray>();
59
60
  const uint32_t acp_supported_features = this->alarm_control_panel_->get_supported_features();
60
61
  if (acp_supported_features & ACP_FEAT_ARM_AWAY) {
61
62
  supported_features.add("arm_away");
@@ -30,6 +30,7 @@ MQTTBinarySensorComponent::MQTTBinarySensorComponent(binary_sensor::BinarySensor
30
30
  }
31
31
 
32
32
  void MQTTBinarySensorComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
33
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
33
34
  if (!this->binary_sensor_->get_device_class().empty())
34
35
  root[MQTT_DEVICE_CLASS] = this->binary_sensor_->get_device_class();
35
36
  if (this->binary_sensor_->is_status_binary_sensor())
@@ -31,9 +31,12 @@ void MQTTButtonComponent::dump_config() {
31
31
  }
32
32
 
33
33
  void MQTTButtonComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
34
+ // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
34
35
  config.state_topic = false;
35
- if (!this->button_->get_device_class().empty())
36
+ if (!this->button_->get_device_class().empty()) {
36
37
  root[MQTT_DEVICE_CLASS] = this->button_->get_device_class();
38
+ }
39
+ // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
37
40
  }
38
41
 
39
42
  std::string MQTTButtonComponent::component_type() const { return "button"; }
@@ -92,6 +92,7 @@ void MQTTClientComponent::send_device_info_() {
92
92
  std::string topic = "esphome/discover/";
93
93
  topic.append(App.get_name());
94
94
 
95
+ // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
95
96
  this->publish_json(
96
97
  topic,
97
98
  [](JsonObject root) {
@@ -147,6 +148,7 @@ void MQTTClientComponent::send_device_info_() {
147
148
  #endif
148
149
  },
149
150
  2, this->discovery_info_.retain);
151
+ // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
150
152
  }
151
153
 
152
154
  void MQTTClientComponent::dump_config() {
@@ -14,6 +14,7 @@ static const char *const TAG = "mqtt.climate";
14
14
  using namespace esphome::climate;
15
15
 
16
16
  void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
17
+ // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
17
18
  auto traits = this->device_->get_traits();
18
19
  // current_temperature_topic
19
20
  if (traits.get_supports_current_temperature()) {
@@ -28,7 +29,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo
28
29
  // mode_state_topic
29
30
  root[MQTT_MODE_STATE_TOPIC] = this->get_mode_state_topic();
30
31
  // modes
31
- JsonArray modes = root.createNestedArray(MQTT_MODES);
32
+ JsonArray modes = root[MQTT_MODES].to<JsonArray>();
32
33
  // sort array for nice UI in HA
33
34
  if (traits.supports_mode(CLIMATE_MODE_AUTO))
34
35
  modes.add("auto");
@@ -89,7 +90,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo
89
90
  // preset_mode_state_topic
90
91
  root[MQTT_PRESET_MODE_STATE_TOPIC] = this->get_preset_state_topic();
91
92
  // presets
92
- JsonArray presets = root.createNestedArray("preset_modes");
93
+ JsonArray presets = root["preset_modes"].to<JsonArray>();
93
94
  if (traits.supports_preset(CLIMATE_PRESET_HOME))
94
95
  presets.add("home");
95
96
  if (traits.supports_preset(CLIMATE_PRESET_AWAY))
@@ -119,7 +120,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo
119
120
  // fan_mode_state_topic
120
121
  root[MQTT_FAN_MODE_STATE_TOPIC] = this->get_fan_mode_state_topic();
121
122
  // fan_modes
122
- JsonArray fan_modes = root.createNestedArray("fan_modes");
123
+ JsonArray fan_modes = root["fan_modes"].to<JsonArray>();
123
124
  if (traits.supports_fan_mode(CLIMATE_FAN_ON))
124
125
  fan_modes.add("on");
125
126
  if (traits.supports_fan_mode(CLIMATE_FAN_OFF))
@@ -150,7 +151,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo
150
151
  // swing_mode_state_topic
151
152
  root[MQTT_SWING_MODE_STATE_TOPIC] = this->get_swing_mode_state_topic();
152
153
  // swing_modes
153
- JsonArray swing_modes = root.createNestedArray("swing_modes");
154
+ JsonArray swing_modes = root["swing_modes"].to<JsonArray>();
154
155
  if (traits.supports_swing_mode(CLIMATE_SWING_OFF))
155
156
  swing_modes.add("off");
156
157
  if (traits.supports_swing_mode(CLIMATE_SWING_BOTH))
@@ -163,6 +164,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo
163
164
 
164
165
  config.state_topic = false;
165
166
  config.command_topic = false;
167
+ // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
166
168
  }
167
169
  void MQTTClimateComponent::setup() {
168
170
  auto traits = this->device_->get_traits();
@@ -70,6 +70,7 @@ bool MQTTComponent::send_discovery_() {
70
70
 
71
71
  ESP_LOGV(TAG, "'%s': Sending discovery", this->friendly_name().c_str());
72
72
 
73
+ // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
73
74
  return global_mqtt_client->publish_json(
74
75
  this->get_discovery_topic_(discovery_info),
75
76
  [this](JsonObject root) {
@@ -155,7 +156,7 @@ bool MQTTComponent::send_discovery_() {
155
156
  }
156
157
  std::string node_area = App.get_area();
157
158
 
158
- JsonObject device_info = root.createNestedObject(MQTT_DEVICE);
159
+ JsonObject device_info = root[MQTT_DEVICE].to<JsonObject>();
159
160
  const auto mac = get_mac_address();
160
161
  device_info[MQTT_DEVICE_IDENTIFIERS] = mac;
161
162
  device_info[MQTT_DEVICE_NAME] = node_friendly_name;
@@ -192,6 +193,7 @@ bool MQTTComponent::send_discovery_() {
192
193
  device_info[MQTT_DEVICE_CONNECTIONS][0][1] = mac;
193
194
  },
194
195
  this->qos_, discovery_info.retain);
196
+ // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
195
197
  }
196
198
 
197
199
  uint8_t MQTTComponent::get_qos() const { return this->qos_; }
@@ -67,6 +67,7 @@ void MQTTCoverComponent::dump_config() {
67
67
  }
68
68
  }
69
69
  void MQTTCoverComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
70
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
70
71
  if (!this->cover_->get_device_class().empty())
71
72
  root[MQTT_DEVICE_CLASS] = this->cover_->get_device_class();
72
73
 
@@ -20,13 +20,13 @@ MQTTDateComponent::MQTTDateComponent(DateEntity *date) : date_(date) {}
20
20
  void MQTTDateComponent::setup() {
21
21
  this->subscribe_json(this->get_command_topic_(), [this](const std::string &topic, JsonObject root) {
22
22
  auto call = this->date_->make_call();
23
- if (root.containsKey("year")) {
23
+ if (root["year"].is<uint16_t>()) {
24
24
  call.set_year(root["year"]);
25
25
  }
26
- if (root.containsKey("month")) {
26
+ if (root["month"].is<uint8_t>()) {
27
27
  call.set_month(root["month"]);
28
28
  }
29
- if (root.containsKey("day")) {
29
+ if (root["day"].is<uint8_t>()) {
30
30
  call.set_day(root["day"]);
31
31
  }
32
32
  call.perform();
@@ -55,6 +55,7 @@ bool MQTTDateComponent::send_initial_state() {
55
55
  }
56
56
  bool MQTTDateComponent::publish_state(uint16_t year, uint8_t month, uint8_t day) {
57
57
  return this->publish_json(this->get_state_topic_(), [year, month, day](JsonObject root) {
58
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
58
59
  root["year"] = year;
59
60
  root["month"] = month;
60
61
  root["day"] = day;
@@ -20,22 +20,22 @@ MQTTDateTimeComponent::MQTTDateTimeComponent(DateTimeEntity *datetime) : datetim
20
20
  void MQTTDateTimeComponent::setup() {
21
21
  this->subscribe_json(this->get_command_topic_(), [this](const std::string &topic, JsonObject root) {
22
22
  auto call = this->datetime_->make_call();
23
- if (root.containsKey("year")) {
23
+ if (root["year"].is<uint16_t>()) {
24
24
  call.set_year(root["year"]);
25
25
  }
26
- if (root.containsKey("month")) {
26
+ if (root["month"].is<uint8_t>()) {
27
27
  call.set_month(root["month"]);
28
28
  }
29
- if (root.containsKey("day")) {
29
+ if (root["day"].is<uint8_t>()) {
30
30
  call.set_day(root["day"]);
31
31
  }
32
- if (root.containsKey("hour")) {
32
+ if (root["hour"].is<uint8_t>()) {
33
33
  call.set_hour(root["hour"]);
34
34
  }
35
- if (root.containsKey("minute")) {
35
+ if (root["minute"].is<uint8_t>()) {
36
36
  call.set_minute(root["minute"]);
37
37
  }
38
- if (root.containsKey("second")) {
38
+ if (root["second"].is<uint8_t>()) {
39
39
  call.set_second(root["second"]);
40
40
  }
41
41
  call.perform();
@@ -68,6 +68,7 @@ bool MQTTDateTimeComponent::send_initial_state() {
68
68
  bool MQTTDateTimeComponent::publish_state(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute,
69
69
  uint8_t second) {
70
70
  return this->publish_json(this->get_state_topic_(), [year, month, day, hour, minute, second](JsonObject root) {
71
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
71
72
  root["year"] = year;
72
73
  root["month"] = month;
73
74
  root["day"] = day;
@@ -16,7 +16,8 @@ using namespace esphome::event;
16
16
  MQTTEventComponent::MQTTEventComponent(event::Event *event) : event_(event) {}
17
17
 
18
18
  void MQTTEventComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
19
- JsonArray event_types = root.createNestedArray(MQTT_EVENT_TYPES);
19
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
20
+ JsonArray event_types = root[MQTT_EVENT_TYPES].to<JsonArray>();
20
21
  for (const auto &event_type : this->event_->get_event_types())
21
22
  event_types.add(event_type);
22
23
 
@@ -40,8 +41,10 @@ void MQTTEventComponent::dump_config() {
40
41
  }
41
42
 
42
43
  bool MQTTEventComponent::publish_event_(const std::string &event_type) {
43
- return this->publish_json(this->get_state_topic_(),
44
- [event_type](JsonObject root) { root[MQTT_EVENT_TYPE] = event_type; });
44
+ return this->publish_json(this->get_state_topic_(), [event_type](JsonObject root) {
45
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
46
+ root[MQTT_EVENT_TYPE] = event_type;
47
+ });
45
48
  }
46
49
 
47
50
  std::string MQTTEventComponent::component_type() const { return "event"; }
@@ -143,6 +143,7 @@ void MQTTFanComponent::dump_config() {
143
143
  bool MQTTFanComponent::send_initial_state() { return this->publish_state(); }
144
144
 
145
145
  void MQTTFanComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
146
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
146
147
  if (this->state_->get_traits().supports_direction()) {
147
148
  root[MQTT_DIRECTION_COMMAND_TOPIC] = this->get_direction_command_topic();
148
149
  root[MQTT_DIRECTION_STATE_TOPIC] = this->get_direction_state_topic();
@@ -32,17 +32,21 @@ void MQTTJSONLightComponent::setup() {
32
32
  MQTTJSONLightComponent::MQTTJSONLightComponent(LightState *state) : state_(state) {}
33
33
 
34
34
  bool MQTTJSONLightComponent::publish_state_() {
35
- return this->publish_json(this->get_state_topic_(),
36
- [this](JsonObject root) { LightJSONSchema::dump_json(*this->state_, root); });
35
+ return this->publish_json(this->get_state_topic_(), [this](JsonObject root) {
36
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
37
+ LightJSONSchema::dump_json(*this->state_, root);
38
+ });
37
39
  }
38
40
  LightState *MQTTJSONLightComponent::get_state() const { return this->state_; }
39
41
 
40
42
  void MQTTJSONLightComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
43
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
41
44
  root["schema"] = "json";
42
45
  auto traits = this->state_->get_traits();
43
46
 
44
47
  root[MQTT_COLOR_MODE] = true;
45
- JsonArray color_modes = root.createNestedArray("supported_color_modes");
48
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
49
+ JsonArray color_modes = root["supported_color_modes"].to<JsonArray>();
46
50
  if (traits.supports_color_mode(ColorMode::ON_OFF))
47
51
  color_modes.add("onoff");
48
52
  if (traits.supports_color_mode(ColorMode::BRIGHTNESS))
@@ -67,7 +71,7 @@ void MQTTJSONLightComponent::send_discovery(JsonObject root, mqtt::SendDiscovery
67
71
 
68
72
  if (this->state_->supports_effects()) {
69
73
  root["effect"] = true;
70
- JsonArray effect_list = root.createNestedArray(MQTT_EFFECT_LIST);
74
+ JsonArray effect_list = root[MQTT_EFFECT_LIST].to<JsonArray>();
71
75
  for (auto *effect : this->state_->get_effects())
72
76
  effect_list.add(effect->get_name());
73
77
  effect_list.add("None");
@@ -38,8 +38,10 @@ void MQTTLockComponent::dump_config() {
38
38
  std::string MQTTLockComponent::component_type() const { return "lock"; }
39
39
  const EntityBase *MQTTLockComponent::get_entity() const { return this->lock_; }
40
40
  void MQTTLockComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
41
- if (this->lock_->traits.get_assumed_state())
41
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
42
+ if (this->lock_->traits.get_assumed_state()) {
42
43
  root[MQTT_OPTIMISTIC] = true;
44
+ }
43
45
  if (this->lock_->traits.get_supports_open())
44
46
  root[MQTT_PAYLOAD_OPEN] = "OPEN";
45
47
  }
@@ -40,6 +40,7 @@ const EntityBase *MQTTNumberComponent::get_entity() const { return this->number_
40
40
  void MQTTNumberComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
41
41
  const auto &traits = number_->traits;
42
42
  // https://www.home-assistant.io/integrations/number.mqtt/
43
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
43
44
  root[MQTT_MIN] = traits.get_min_value();
44
45
  root[MQTT_MAX] = traits.get_max_value();
45
46
  root[MQTT_STEP] = traits.get_step();
@@ -35,7 +35,8 @@ const EntityBase *MQTTSelectComponent::get_entity() const { return this->select_
35
35
  void MQTTSelectComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
36
36
  const auto &traits = select_->traits;
37
37
  // https://www.home-assistant.io/integrations/select.mqtt/
38
- JsonArray options = root.createNestedArray(MQTT_OPTIONS);
38
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
39
+ JsonArray options = root[MQTT_OPTIONS].to<JsonArray>();
39
40
  for (const auto &option : traits.get_options())
40
41
  options.add(option);
41
42
 
@@ -44,8 +44,10 @@ void MQTTSensorComponent::set_expire_after(uint32_t expire_after) { this->expire
44
44
  void MQTTSensorComponent::disable_expire_after() { this->expire_after_ = 0; }
45
45
 
46
46
  void MQTTSensorComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
47
- if (!this->sensor_->get_device_class().empty())
47
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
48
+ if (!this->sensor_->get_device_class().empty()) {
48
49
  root[MQTT_DEVICE_CLASS] = this->sensor_->get_device_class();
50
+ }
49
51
 
50
52
  if (!this->sensor_->get_unit_of_measurement().empty())
51
53
  root[MQTT_UNIT_OF_MEASUREMENT] = this->sensor_->get_unit_of_measurement();
@@ -45,8 +45,10 @@ void MQTTSwitchComponent::dump_config() {
45
45
  std::string MQTTSwitchComponent::component_type() const { return "switch"; }
46
46
  const EntityBase *MQTTSwitchComponent::get_entity() const { return this->switch_; }
47
47
  void MQTTSwitchComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
48
- if (this->switch_->assumed_state())
48
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
49
+ if (this->switch_->assumed_state()) {
49
50
  root[MQTT_OPTIMISTIC] = true;
51
+ }
50
52
  }
51
53
  bool MQTTSwitchComponent::send_initial_state() { return this->publish_state(this->switch_->state); }
52
54
 
@@ -34,6 +34,7 @@ std::string MQTTTextComponent::component_type() const { return "text"; }
34
34
  const EntityBase *MQTTTextComponent::get_entity() const { return this->text_; }
35
35
 
36
36
  void MQTTTextComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
37
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
37
38
  switch (this->text_->traits.get_mode()) {
38
39
  case TEXT_MODE_TEXT:
39
40
  root[MQTT_MODE] = "text";
@@ -15,8 +15,10 @@ using namespace esphome::text_sensor;
15
15
 
16
16
  MQTTTextSensor::MQTTTextSensor(TextSensor *sensor) : sensor_(sensor) {}
17
17
  void MQTTTextSensor::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
18
- if (!this->sensor_->get_device_class().empty())
18
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
19
+ if (!this->sensor_->get_device_class().empty()) {
19
20
  root[MQTT_DEVICE_CLASS] = this->sensor_->get_device_class();
21
+ }
20
22
  config.command_topic = false;
21
23
  }
22
24
  void MQTTTextSensor::setup() {
@@ -20,13 +20,13 @@ MQTTTimeComponent::MQTTTimeComponent(TimeEntity *time) : time_(time) {}
20
20
  void MQTTTimeComponent::setup() {
21
21
  this->subscribe_json(this->get_command_topic_(), [this](const std::string &topic, JsonObject root) {
22
22
  auto call = this->time_->make_call();
23
- if (root.containsKey("hour")) {
23
+ if (root["hour"].is<uint8_t>()) {
24
24
  call.set_hour(root["hour"]);
25
25
  }
26
- if (root.containsKey("minute")) {
26
+ if (root["minute"].is<uint8_t>()) {
27
27
  call.set_minute(root["minute"]);
28
28
  }
29
- if (root.containsKey("second")) {
29
+ if (root["second"].is<uint8_t>()) {
30
30
  call.set_second(root["second"]);
31
31
  }
32
32
  call.perform();
@@ -55,6 +55,7 @@ bool MQTTTimeComponent::send_initial_state() {
55
55
  }
56
56
  bool MQTTTimeComponent::publish_state(uint8_t hour, uint8_t minute, uint8_t second) {
57
57
  return this->publish_json(this->get_state_topic_(), [hour, minute, second](JsonObject root) {
58
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
58
59
  root["hour"] = hour;
59
60
  root["minute"] = minute;
60
61
  root["second"] = second;
@@ -41,6 +41,7 @@ bool MQTTUpdateComponent::publish_state() {
41
41
  }
42
42
 
43
43
  void MQTTUpdateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
44
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
44
45
  root["schema"] = "json";
45
46
  root[MQTT_PAYLOAD_INSTALL] = "INSTALL";
46
47
  }
@@ -49,8 +49,10 @@ void MQTTValveComponent::dump_config() {
49
49
  }
50
50
  }
51
51
  void MQTTValveComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
52
- if (!this->valve_->get_device_class().empty())
52
+ // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
53
+ if (!this->valve_->get_device_class().empty()) {
53
54
  root[MQTT_DEVICE_CLASS] = this->valve_->get_device_class();
55
+ }
54
56
 
55
57
  auto traits = this->valve_->get_traits();
56
58
  if (traits.get_is_assumed_state()) {
@@ -356,7 +356,7 @@ void MS8607Component::read_humidity_(float temperature_float) {
356
356
 
357
357
  // map 16 bit humidity value into range [-6%, 118%]
358
358
  float const humidity_partial = double(humidity) / (1 << 16);
359
- float const humidity_percentage = lerp(humidity_partial, -6.0, 118.0);
359
+ float const humidity_percentage = std::lerp(-6.0, 118.0, humidity_partial);
360
360
  float const compensated_humidity_percentage =
361
361
  humidity_percentage + (20 - temperature_float) * MS8607_H_TEMP_COEFFICIENT;
362
362
  ESP_LOGD(TAG, "Compensated for temperature, humidity=%.2f%%", compensated_humidity_percentage);