esphome 2025.2.2__py3-none-any.whl → 2025.3.0b1__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 (135) hide show
  1. esphome/__main__.py +9 -1
  2. esphome/components/api/api_connection.cpp +426 -70
  3. esphome/components/api/api_connection.h +117 -25
  4. esphome/components/api/api_pb2.cpp +9 -0
  5. esphome/components/api/api_pb2.h +1 -0
  6. esphome/components/api/api_server.cpp +2 -2
  7. esphome/components/api/list_entities.cpp +76 -22
  8. esphome/components/api/list_entities.h +1 -0
  9. esphome/components/api/subscribe_state.h +2 -0
  10. esphome/components/bluetooth_proxy/bluetooth_proxy.h +8 -0
  11. esphome/components/bmp085/bmp085.cpp +1 -1
  12. esphome/components/chsc6x/__init__.py +2 -0
  13. esphome/components/chsc6x/chsc6x_touchscreen.cpp +47 -0
  14. esphome/components/chsc6x/chsc6x_touchscreen.h +34 -0
  15. esphome/components/chsc6x/touchscreen.py +33 -0
  16. esphome/components/climate/__init__.py +0 -1
  17. esphome/components/cst816/binary_sensor/__init__.py +2 -25
  18. esphome/components/cst816/touchscreen/cst816_touchscreen.cpp +3 -14
  19. esphome/components/cst816/touchscreen/cst816_touchscreen.h +0 -4
  20. esphome/components/esp32_ble_beacon/__init__.py +3 -1
  21. esphome/components/esp8266/gpio.py +1 -2
  22. esphome/components/font/__init__.py +185 -185
  23. esphome/components/font/font.cpp +4 -4
  24. esphome/components/font/font.h +1 -0
  25. esphome/components/haier/climate.py +11 -10
  26. esphome/components/hbridge/switch/hbridge_switch.cpp +2 -2
  27. esphome/components/heatpumpir/climate.py +2 -1
  28. esphome/components/heatpumpir/heatpumpir.cpp +1 -0
  29. esphome/components/heatpumpir/heatpumpir.h +1 -0
  30. esphome/components/i2c/__init__.py +6 -6
  31. esphome/components/i2c/i2c_bus_esp_idf.cpp +6 -2
  32. esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +1 -1
  33. esphome/components/ili9xxx/display.py +1 -0
  34. esphome/components/ili9xxx/ili9xxx_display.h +5 -0
  35. esphome/components/ili9xxx/ili9xxx_init.h +59 -0
  36. esphome/components/ld2450/__init__.py +51 -0
  37. esphome/components/ld2450/binary_sensor.py +47 -0
  38. esphome/components/ld2450/button/__init__.py +45 -0
  39. esphome/components/ld2450/button/reset_button.cpp +9 -0
  40. esphome/components/ld2450/button/reset_button.h +18 -0
  41. esphome/components/ld2450/button/restart_button.cpp +9 -0
  42. esphome/components/ld2450/button/restart_button.h +18 -0
  43. esphome/components/ld2450/ld2450.cpp +876 -0
  44. esphome/components/ld2450/ld2450.h +234 -0
  45. esphome/components/ld2450/number/__init__.py +121 -0
  46. esphome/components/ld2450/number/presence_timeout_number.cpp +12 -0
  47. esphome/components/ld2450/number/presence_timeout_number.h +18 -0
  48. esphome/components/ld2450/number/zone_coordinate_number.cpp +14 -0
  49. esphome/components/ld2450/number/zone_coordinate_number.h +19 -0
  50. esphome/components/ld2450/select/__init__.py +56 -0
  51. esphome/components/ld2450/select/baud_rate_select.cpp +12 -0
  52. esphome/components/ld2450/select/baud_rate_select.h +18 -0
  53. esphome/components/ld2450/select/zone_type_select.cpp +12 -0
  54. esphome/components/ld2450/select/zone_type_select.h +18 -0
  55. esphome/components/ld2450/sensor.py +156 -0
  56. esphome/components/ld2450/switch/__init__.py +45 -0
  57. esphome/components/ld2450/switch/bluetooth_switch.cpp +12 -0
  58. esphome/components/ld2450/switch/bluetooth_switch.h +18 -0
  59. esphome/components/ld2450/switch/multi_target_switch.cpp +12 -0
  60. esphome/components/ld2450/switch/multi_target_switch.h +18 -0
  61. esphome/components/ld2450/text_sensor.py +62 -0
  62. esphome/components/lvgl/defines.py +0 -2
  63. esphome/components/lvgl/font.cpp +1 -1
  64. esphome/components/lvgl/lvgl_esphome.cpp +27 -19
  65. esphome/components/lvgl/widgets/img.py +1 -3
  66. esphome/components/mcp2515/mcp2515.cpp +1 -0
  67. esphome/components/mlx90393/sensor.py +53 -33
  68. esphome/components/mlx90393/sensor_mlx90393.cpp +4 -0
  69. esphome/components/mlx90393/sensor_mlx90393.h +8 -3
  70. esphome/components/mqtt/__init__.py +2 -2
  71. esphome/components/msa3xx/__init__.py +189 -0
  72. esphome/components/msa3xx/binary_sensor.py +40 -0
  73. esphome/components/msa3xx/msa3xx.cpp +417 -0
  74. esphome/components/msa3xx/msa3xx.h +311 -0
  75. esphome/components/msa3xx/sensor.py +42 -0
  76. esphome/components/msa3xx/text_sensor.py +38 -0
  77. esphome/components/nfc/binary_sensor/__init__.py +4 -4
  78. esphome/components/opentherm/binary_sensor/__init__.py +4 -4
  79. esphome/components/opentherm/generate.py +6 -6
  80. esphome/components/opentherm/sensor/__init__.py +5 -6
  81. esphome/components/packages/__init__.py +35 -11
  82. esphome/components/pn532/binary_sensor.py +4 -4
  83. esphome/components/rc522/binary_sensor.py +4 -4
  84. esphome/components/socket/bsd_sockets_impl.cpp +1 -0
  85. esphome/components/socket/lwip_sockets_impl.cpp +1 -0
  86. esphome/components/socket/socket.h +3 -1
  87. esphome/components/ssd1306_base/__init__.py +7 -7
  88. esphome/components/thermostat/climate.py +1 -1
  89. esphome/components/tmp1075/tmp1075.cpp +7 -11
  90. esphome/components/tmp1075/tmp1075.h +1 -2
  91. esphome/components/tormatic/__init__.py +1 -0
  92. esphome/components/tormatic/cover.py +47 -0
  93. esphome/components/tormatic/tormatic_cover.cpp +355 -0
  94. esphome/components/tormatic/tormatic_cover.h +60 -0
  95. esphome/components/tormatic/tormatic_protocol.h +211 -0
  96. esphome/components/touchscreen/binary_sensor/__init__.py +3 -0
  97. esphome/components/touchscreen/binary_sensor/touchscreen_binary_sensor.cpp +7 -1
  98. esphome/components/touchscreen/binary_sensor/touchscreen_binary_sensor.h +3 -1
  99. esphome/components/touchscreen/touchscreen.cpp +3 -4
  100. esphome/components/udp/udp_component.h +4 -1
  101. esphome/components/web_server/list_entities.cpp +70 -66
  102. esphome/components/web_server/list_entities.h +43 -22
  103. esphome/components/web_server/web_server.cpp +345 -68
  104. esphome/components/web_server/web_server.h +138 -6
  105. esphome/components/web_server_base/__init__.py +1 -1
  106. esphome/components/web_server_idf/__init__.py +2 -0
  107. esphome/components/web_server_idf/web_server_idf.cpp +177 -30
  108. esphome/components/web_server_idf/web_server_idf.h +53 -4
  109. esphome/config_validation.py +23 -125
  110. esphome/const.py +5 -1
  111. esphome/core/config.py +12 -4
  112. esphome/core/defines.h +1 -1
  113. esphome/core/helpers.h +5 -3
  114. esphome/core/time.cpp +1 -0
  115. esphome/cpp_generator.py +3 -3
  116. esphome/dashboard/core.py +30 -21
  117. esphome/dashboard/dns.py +7 -1
  118. esphome/dashboard/entries.py +83 -16
  119. esphome/dashboard/settings.py +0 -4
  120. esphome/dashboard/status/mdns.py +43 -14
  121. esphome/dashboard/status/mqtt.py +22 -9
  122. esphome/dashboard/status/ping.py +54 -10
  123. esphome/dashboard/web_server.py +56 -24
  124. esphome/storage_json.py +4 -0
  125. esphome/wizard.py +13 -17
  126. esphome/writer.py +1 -3
  127. esphome/yaml_util.py +36 -33
  128. esphome/zeroconf.py +9 -21
  129. {esphome-2025.2.2.dist-info → esphome-2025.3.0b1.dist-info}/METADATA +5 -5
  130. {esphome-2025.2.2.dist-info → esphome-2025.3.0b1.dist-info}/RECORD +134 -94
  131. esphome/components/cst816/binary_sensor/cst816_button.h +0 -27
  132. {esphome-2025.2.2.dist-info → esphome-2025.3.0b1.dist-info}/LICENSE +0 -0
  133. {esphome-2025.2.2.dist-info → esphome-2025.3.0b1.dist-info}/WHEEL +0 -0
  134. {esphome-2025.2.2.dist-info → esphome-2025.3.0b1.dist-info}/entry_points.txt +0 -0
  135. {esphome-2025.2.2.dist-info → esphome-2025.3.0b1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,234 @@
1
+ #pragma once
2
+
3
+ #include <iomanip>
4
+ #include <map>
5
+ #include "esphome/components/uart/uart.h"
6
+ #include "esphome/core/component.h"
7
+ #include "esphome/core/defines.h"
8
+ #include "esphome/core/helpers.h"
9
+ #include "esphome/core/preferences.h"
10
+ #ifdef USE_SENSOR
11
+ #include "esphome/components/sensor/sensor.h"
12
+ #endif
13
+ #ifdef USE_NUMBER
14
+ #include "esphome/components/number/number.h"
15
+ #endif
16
+ #ifdef USE_SWITCH
17
+ #include "esphome/components/switch/switch.h"
18
+ #endif
19
+ #ifdef USE_BUTTON
20
+ #include "esphome/components/button/button.h"
21
+ #endif
22
+ #ifdef USE_SELECT
23
+ #include "esphome/components/select/select.h"
24
+ #endif
25
+ #ifdef USE_TEXT_SENSOR
26
+ #include "esphome/components/text_sensor/text_sensor.h"
27
+ #endif
28
+ #ifdef USE_BINARY_SENSOR
29
+ #include "esphome/components/binary_sensor/binary_sensor.h"
30
+ #endif
31
+
32
+ #ifndef M_PI
33
+ #define M_PI 3.14
34
+ #endif
35
+
36
+ namespace esphome {
37
+ namespace ld2450 {
38
+
39
+ // Constants
40
+ static const uint8_t DEFAULT_PRESENCE_TIMEOUT = 5; // Timeout to reset presense status 5 sec.
41
+ static const uint8_t MAX_LINE_LENGTH = 60; // Max characters for serial buffer
42
+ static const uint8_t MAX_TARGETS = 3; // Max 3 Targets in LD2450
43
+ static const uint8_t MAX_ZONES = 3; // Max 3 Zones in LD2450
44
+
45
+ // Target coordinate struct
46
+ struct Target {
47
+ int16_t x;
48
+ int16_t y;
49
+ bool is_moving;
50
+ };
51
+
52
+ // Zone coordinate struct
53
+ struct Zone {
54
+ int16_t x1 = 0;
55
+ int16_t y1 = 0;
56
+ int16_t x2 = 0;
57
+ int16_t y2 = 0;
58
+ };
59
+
60
+ #ifdef USE_NUMBER
61
+ struct ZoneOfNumbers {
62
+ number::Number *x1 = nullptr;
63
+ number::Number *y1 = nullptr;
64
+ number::Number *x2 = nullptr;
65
+ number::Number *y2 = nullptr;
66
+ };
67
+ #endif
68
+
69
+ enum BaudRateStructure : uint8_t {
70
+ BAUD_RATE_9600 = 1,
71
+ BAUD_RATE_19200 = 2,
72
+ BAUD_RATE_38400 = 3,
73
+ BAUD_RATE_57600 = 4,
74
+ BAUD_RATE_115200 = 5,
75
+ BAUD_RATE_230400 = 6,
76
+ BAUD_RATE_256000 = 7,
77
+ BAUD_RATE_460800 = 8
78
+ };
79
+
80
+ // Convert baud rate enum to int
81
+ static const std::map<std::string, uint8_t> BAUD_RATE_ENUM_TO_INT{
82
+ {"9600", BAUD_RATE_9600}, {"19200", BAUD_RATE_19200}, {"38400", BAUD_RATE_38400},
83
+ {"57600", BAUD_RATE_57600}, {"115200", BAUD_RATE_115200}, {"230400", BAUD_RATE_230400},
84
+ {"256000", BAUD_RATE_256000}, {"460800", BAUD_RATE_460800}};
85
+
86
+ // Zone type struct
87
+ enum ZoneTypeStructure : uint8_t { ZONE_DISABLED = 0, ZONE_DETECTION = 1, ZONE_FILTER = 2 };
88
+
89
+ // Convert zone type int to enum
90
+ static const std::map<ZoneTypeStructure, std::string> ZONE_TYPE_INT_TO_ENUM{
91
+ {ZONE_DISABLED, "Disabled"}, {ZONE_DETECTION, "Detection"}, {ZONE_FILTER, "Filter"}};
92
+
93
+ // Convert zone type enum to int
94
+ static const std::map<std::string, uint8_t> ZONE_TYPE_ENUM_TO_INT{
95
+ {"Disabled", ZONE_DISABLED}, {"Detection", ZONE_DETECTION}, {"Filter", ZONE_FILTER}};
96
+
97
+ // LD2450 serial command header & footer
98
+ static const uint8_t CMD_FRAME_HEADER[4] = {0xFD, 0xFC, 0xFB, 0xFA};
99
+ static const uint8_t CMD_FRAME_END[4] = {0x04, 0x03, 0x02, 0x01};
100
+
101
+ enum PeriodicDataStructure : uint8_t {
102
+ TARGET_X = 4,
103
+ TARGET_Y = 6,
104
+ TARGET_SPEED = 8,
105
+ TARGET_RESOLUTION = 10,
106
+ };
107
+
108
+ enum PeriodicDataValue : uint8_t { HEAD = 0XAA, END = 0x55, CHECK = 0x00 };
109
+
110
+ enum AckDataStructure : uint8_t { COMMAND = 6, COMMAND_STATUS = 7 };
111
+
112
+ class LD2450Component : public Component, public uart::UARTDevice {
113
+ #ifdef USE_SENSOR
114
+ SUB_SENSOR(target_count)
115
+ SUB_SENSOR(still_target_count)
116
+ SUB_SENSOR(moving_target_count)
117
+ #endif
118
+ #ifdef USE_BINARY_SENSOR
119
+ SUB_BINARY_SENSOR(target)
120
+ SUB_BINARY_SENSOR(moving_target)
121
+ SUB_BINARY_SENSOR(still_target)
122
+ #endif
123
+ #ifdef USE_TEXT_SENSOR
124
+ SUB_TEXT_SENSOR(version)
125
+ SUB_TEXT_SENSOR(mac)
126
+ #endif
127
+ #ifdef USE_SELECT
128
+ SUB_SELECT(baud_rate)
129
+ SUB_SELECT(zone_type)
130
+ #endif
131
+ #ifdef USE_SWITCH
132
+ SUB_SWITCH(bluetooth)
133
+ SUB_SWITCH(multi_target)
134
+ #endif
135
+ #ifdef USE_BUTTON
136
+ SUB_BUTTON(reset)
137
+ SUB_BUTTON(restart)
138
+ #endif
139
+ #ifdef USE_NUMBER
140
+ SUB_NUMBER(presence_timeout)
141
+ #endif
142
+
143
+ public:
144
+ LD2450Component();
145
+ void setup() override;
146
+ void dump_config() override;
147
+ void loop() override;
148
+ void set_presence_timeout();
149
+ void set_throttle(uint16_t value) { this->throttle_ = value; };
150
+ void read_all_info();
151
+ void query_zone_info();
152
+ void restart_and_read_all_info();
153
+ void set_bluetooth(bool enable);
154
+ void set_multi_target(bool enable);
155
+ void set_baud_rate(const std::string &state);
156
+ void set_zone_type(const std::string &state);
157
+ void publish_zone_type();
158
+ void factory_reset();
159
+ #ifdef USE_TEXT_SENSOR
160
+ void set_direction_text_sensor(uint8_t target, text_sensor::TextSensor *s);
161
+ #endif
162
+ #ifdef USE_NUMBER
163
+ void set_zone_coordinate(uint8_t zone);
164
+ void set_zone_numbers(uint8_t zone, number::Number *x1, number::Number *y1, number::Number *x2, number::Number *y2);
165
+ #endif
166
+ #ifdef USE_SENSOR
167
+ void set_move_x_sensor(uint8_t target, sensor::Sensor *s);
168
+ void set_move_y_sensor(uint8_t target, sensor::Sensor *s);
169
+ void set_move_speed_sensor(uint8_t target, sensor::Sensor *s);
170
+ void set_move_angle_sensor(uint8_t target, sensor::Sensor *s);
171
+ void set_move_distance_sensor(uint8_t target, sensor::Sensor *s);
172
+ void set_move_resolution_sensor(uint8_t target, sensor::Sensor *s);
173
+ void set_zone_target_count_sensor(uint8_t zone, sensor::Sensor *s);
174
+ void set_zone_still_target_count_sensor(uint8_t zone, sensor::Sensor *s);
175
+ void set_zone_moving_target_count_sensor(uint8_t zone, sensor::Sensor *s);
176
+ #endif
177
+ void reset_radar_zone();
178
+ void set_radar_zone(int32_t zone_type, int32_t zone1_x1, int32_t zone1_y1, int32_t zone1_x2, int32_t zone1_y2,
179
+ int32_t zone2_x1, int32_t zone2_y1, int32_t zone2_x2, int32_t zone2_y2, int32_t zone3_x1,
180
+ int32_t zone3_y1, int32_t zone3_x2, int32_t zone3_y2);
181
+
182
+ protected:
183
+ void send_command_(uint8_t command_str, const uint8_t *command_value, uint8_t command_value_len);
184
+ void set_config_mode_(bool enable);
185
+ void handle_periodic_data_(uint8_t *buffer, uint8_t len);
186
+ bool handle_ack_data_(uint8_t *buffer, uint8_t len);
187
+ void process_zone_(uint8_t *buffer);
188
+ void readline_(int readch, uint8_t *buffer, uint8_t len);
189
+ void get_version_();
190
+ void get_mac_();
191
+ void query_target_tracking_mode_();
192
+ void query_zone_();
193
+ void restart_();
194
+ void send_set_zone_command_();
195
+ void save_to_flash_(float value);
196
+ float restore_from_flash_();
197
+ bool get_timeout_status_(uint32_t check_millis);
198
+ uint8_t count_targets_in_zone_(const Zone &zone, bool is_moving);
199
+
200
+ Target target_info_[MAX_TARGETS];
201
+ Zone zone_config_[MAX_ZONES];
202
+ uint8_t buffer_pos_ = 0; // where to resume processing/populating buffer
203
+ uint8_t buffer_data_[MAX_LINE_LENGTH];
204
+ uint32_t last_periodic_millis_ = 0;
205
+ uint32_t presence_millis_ = 0;
206
+ uint32_t still_presence_millis_ = 0;
207
+ uint32_t moving_presence_millis_ = 0;
208
+ uint16_t throttle_ = 0;
209
+ uint16_t timeout_ = 5;
210
+ uint8_t zone_type_ = 0;
211
+ std::string version_{};
212
+ std::string mac_{};
213
+ #ifdef USE_NUMBER
214
+ ESPPreferenceObject pref_; // only used when numbers are in use
215
+ ZoneOfNumbers zone_numbers_[MAX_ZONES];
216
+ #endif
217
+ #ifdef USE_SENSOR
218
+ std::vector<sensor::Sensor *> move_x_sensors_ = std::vector<sensor::Sensor *>(MAX_TARGETS);
219
+ std::vector<sensor::Sensor *> move_y_sensors_ = std::vector<sensor::Sensor *>(MAX_TARGETS);
220
+ std::vector<sensor::Sensor *> move_speed_sensors_ = std::vector<sensor::Sensor *>(MAX_TARGETS);
221
+ std::vector<sensor::Sensor *> move_angle_sensors_ = std::vector<sensor::Sensor *>(MAX_TARGETS);
222
+ std::vector<sensor::Sensor *> move_distance_sensors_ = std::vector<sensor::Sensor *>(MAX_TARGETS);
223
+ std::vector<sensor::Sensor *> move_resolution_sensors_ = std::vector<sensor::Sensor *>(MAX_TARGETS);
224
+ std::vector<sensor::Sensor *> zone_target_count_sensors_ = std::vector<sensor::Sensor *>(MAX_ZONES);
225
+ std::vector<sensor::Sensor *> zone_still_target_count_sensors_ = std::vector<sensor::Sensor *>(MAX_ZONES);
226
+ std::vector<sensor::Sensor *> zone_moving_target_count_sensors_ = std::vector<sensor::Sensor *>(MAX_ZONES);
227
+ #endif
228
+ #ifdef USE_TEXT_SENSOR
229
+ std::vector<text_sensor::TextSensor *> direction_text_sensors_ = std::vector<text_sensor::TextSensor *>(3);
230
+ #endif
231
+ };
232
+
233
+ } // namespace ld2450
234
+ } // namespace esphome
@@ -0,0 +1,121 @@
1
+ import esphome.codegen as cg
2
+ from esphome.components import number
3
+ import esphome.config_validation as cv
4
+ from esphome.const import (
5
+ CONF_ID,
6
+ DEVICE_CLASS_DISTANCE,
7
+ ENTITY_CATEGORY_CONFIG,
8
+ ICON_TIMELAPSE,
9
+ UNIT_MILLIMETER,
10
+ UNIT_SECOND,
11
+ )
12
+
13
+ from .. import CONF_LD2450_ID, LD2450Component, ld2450_ns
14
+
15
+ CONF_PRESENCE_TIMEOUT = "presence_timeout"
16
+ CONF_X1 = "x1"
17
+ CONF_X2 = "x2"
18
+ CONF_Y1 = "y1"
19
+ CONF_Y2 = "y2"
20
+ ICON_ARROW_BOTTOM_RIGHT = "mdi:arrow-bottom-right"
21
+ ICON_ARROW_BOTTOM_RIGHT_BOLD_BOX_OUTLINE = "mdi:arrow-bottom-right-bold-box-outline"
22
+ ICON_ARROW_TOP_LEFT = "mdi:arrow-top-left"
23
+ ICON_ARROW_TOP_LEFT_BOLD_BOX_OUTLINE = "mdi:arrow-top-left-bold-box-outline"
24
+ MAX_ZONES = 3
25
+
26
+ PresenceTimeoutNumber = ld2450_ns.class_("PresenceTimeoutNumber", number.Number)
27
+ ZoneCoordinateNumber = ld2450_ns.class_("ZoneCoordinateNumber", number.Number)
28
+
29
+ CONFIG_SCHEMA = cv.Schema(
30
+ {
31
+ cv.GenerateID(CONF_LD2450_ID): cv.use_id(LD2450Component),
32
+ cv.Required(CONF_PRESENCE_TIMEOUT): number.number_schema(
33
+ PresenceTimeoutNumber,
34
+ unit_of_measurement=UNIT_SECOND,
35
+ entity_category=ENTITY_CATEGORY_CONFIG,
36
+ icon=ICON_TIMELAPSE,
37
+ ),
38
+ }
39
+ )
40
+
41
+ CONFIG_SCHEMA = CONFIG_SCHEMA.extend(
42
+ {
43
+ cv.Optional(f"zone_{n + 1}"): cv.Schema(
44
+ {
45
+ cv.Required(CONF_X1): number.number_schema(
46
+ ZoneCoordinateNumber,
47
+ device_class=DEVICE_CLASS_DISTANCE,
48
+ unit_of_measurement=UNIT_MILLIMETER,
49
+ entity_category=ENTITY_CATEGORY_CONFIG,
50
+ icon=ICON_ARROW_TOP_LEFT_BOLD_BOX_OUTLINE,
51
+ ),
52
+ cv.Required(CONF_Y1): number.number_schema(
53
+ ZoneCoordinateNumber,
54
+ device_class=DEVICE_CLASS_DISTANCE,
55
+ unit_of_measurement=UNIT_MILLIMETER,
56
+ entity_category=ENTITY_CATEGORY_CONFIG,
57
+ icon=ICON_ARROW_TOP_LEFT,
58
+ ),
59
+ cv.Required(CONF_X2): number.number_schema(
60
+ ZoneCoordinateNumber,
61
+ device_class=DEVICE_CLASS_DISTANCE,
62
+ unit_of_measurement=UNIT_MILLIMETER,
63
+ entity_category=ENTITY_CATEGORY_CONFIG,
64
+ icon=ICON_ARROW_BOTTOM_RIGHT_BOLD_BOX_OUTLINE,
65
+ ),
66
+ cv.Required(CONF_Y2): number.number_schema(
67
+ ZoneCoordinateNumber,
68
+ device_class=DEVICE_CLASS_DISTANCE,
69
+ unit_of_measurement=UNIT_MILLIMETER,
70
+ entity_category=ENTITY_CATEGORY_CONFIG,
71
+ icon=ICON_ARROW_BOTTOM_RIGHT,
72
+ ),
73
+ }
74
+ )
75
+ for n in range(MAX_ZONES)
76
+ }
77
+ )
78
+
79
+
80
+ async def to_code(config):
81
+ ld2450_component = await cg.get_variable(config[CONF_LD2450_ID])
82
+ if presence_timeout_config := config.get(CONF_PRESENCE_TIMEOUT):
83
+ n = await number.new_number(
84
+ presence_timeout_config,
85
+ min_value=0,
86
+ max_value=3600,
87
+ step=1,
88
+ )
89
+ await cg.register_parented(n, config[CONF_LD2450_ID])
90
+ cg.add(ld2450_component.set_presence_timeout_number(n))
91
+ for zone_num in range(MAX_ZONES):
92
+ if zone_conf := config.get(f"zone_{zone_num + 1}"):
93
+ zone_x1_config = zone_conf.get(CONF_X1)
94
+ x1 = cg.new_Pvariable(zone_x1_config[CONF_ID], zone_num)
95
+ await number.register_number(
96
+ x1, zone_x1_config, min_value=-4860, max_value=4860, step=1
97
+ )
98
+ await cg.register_parented(x1, config[CONF_LD2450_ID])
99
+
100
+ zone_y1_config = zone_conf.get(CONF_Y1)
101
+ y1 = cg.new_Pvariable(zone_y1_config[CONF_ID], zone_num)
102
+ await number.register_number(
103
+ y1, zone_y1_config, min_value=0, max_value=7560, step=1
104
+ )
105
+ await cg.register_parented(y1, config[CONF_LD2450_ID])
106
+
107
+ zone_x2_config = zone_conf.get(CONF_X2)
108
+ x2 = cg.new_Pvariable(zone_x2_config[CONF_ID], zone_num)
109
+ await number.register_number(
110
+ x2, zone_x2_config, min_value=-4860, max_value=4860, step=1
111
+ )
112
+ await cg.register_parented(x2, config[CONF_LD2450_ID])
113
+
114
+ zone_y2_config = zone_conf.get(CONF_Y2)
115
+ y2 = cg.new_Pvariable(zone_y2_config[CONF_ID], zone_num)
116
+ await number.register_number(
117
+ y2, zone_y2_config, min_value=0, max_value=7560, step=1
118
+ )
119
+ await cg.register_parented(y2, config[CONF_LD2450_ID])
120
+
121
+ cg.add(ld2450_component.set_zone_numbers(zone_num, x1, y1, x2, y2))
@@ -0,0 +1,12 @@
1
+ #include "presence_timeout_number.h"
2
+
3
+ namespace esphome {
4
+ namespace ld2450 {
5
+
6
+ void PresenceTimeoutNumber::control(float value) {
7
+ this->publish_state(value);
8
+ this->parent_->set_presence_timeout();
9
+ }
10
+
11
+ } // namespace ld2450
12
+ } // namespace esphome
@@ -0,0 +1,18 @@
1
+ #pragma once
2
+
3
+ #include "esphome/components/number/number.h"
4
+ #include "../ld2450.h"
5
+
6
+ namespace esphome {
7
+ namespace ld2450 {
8
+
9
+ class PresenceTimeoutNumber : public number::Number, public Parented<LD2450Component> {
10
+ public:
11
+ PresenceTimeoutNumber() = default;
12
+
13
+ protected:
14
+ void control(float value) override;
15
+ };
16
+
17
+ } // namespace ld2450
18
+ } // namespace esphome
@@ -0,0 +1,14 @@
1
+ #include "zone_coordinate_number.h"
2
+
3
+ namespace esphome {
4
+ namespace ld2450 {
5
+
6
+ ZoneCoordinateNumber::ZoneCoordinateNumber(uint8_t zone) : zone_(zone) {}
7
+
8
+ void ZoneCoordinateNumber::control(float value) {
9
+ this->publish_state(value);
10
+ this->parent_->set_zone_coordinate(this->zone_);
11
+ }
12
+
13
+ } // namespace ld2450
14
+ } // namespace esphome
@@ -0,0 +1,19 @@
1
+ #pragma once
2
+
3
+ #include "esphome/components/number/number.h"
4
+ #include "../ld2450.h"
5
+
6
+ namespace esphome {
7
+ namespace ld2450 {
8
+
9
+ class ZoneCoordinateNumber : public number::Number, public Parented<LD2450Component> {
10
+ public:
11
+ ZoneCoordinateNumber(uint8_t zone);
12
+
13
+ protected:
14
+ uint8_t zone_;
15
+ void control(float value) override;
16
+ };
17
+
18
+ } // namespace ld2450
19
+ } // namespace esphome
@@ -0,0 +1,56 @@
1
+ import esphome.codegen as cg
2
+ from esphome.components import select
3
+ import esphome.config_validation as cv
4
+ from esphome.const import CONF_BAUD_RATE, ENTITY_CATEGORY_CONFIG, ICON_THERMOMETER
5
+
6
+ from .. import CONF_LD2450_ID, LD2450Component, ld2450_ns
7
+
8
+ CONF_ZONE_TYPE = "zone_type"
9
+
10
+ BaudRateSelect = ld2450_ns.class_("BaudRateSelect", select.Select)
11
+ ZoneTypeSelect = ld2450_ns.class_("ZoneTypeSelect", select.Select)
12
+
13
+ CONFIG_SCHEMA = {
14
+ cv.GenerateID(CONF_LD2450_ID): cv.use_id(LD2450Component),
15
+ cv.Optional(CONF_BAUD_RATE): select.select_schema(
16
+ BaudRateSelect,
17
+ entity_category=ENTITY_CATEGORY_CONFIG,
18
+ icon=ICON_THERMOMETER,
19
+ ),
20
+ cv.Optional(CONF_ZONE_TYPE): select.select_schema(
21
+ ZoneTypeSelect,
22
+ entity_category=ENTITY_CATEGORY_CONFIG,
23
+ icon=ICON_THERMOMETER,
24
+ ),
25
+ }
26
+
27
+
28
+ async def to_code(config):
29
+ ld2450_component = await cg.get_variable(config[CONF_LD2450_ID])
30
+ if baud_rate_config := config.get(CONF_BAUD_RATE):
31
+ s = await select.new_select(
32
+ baud_rate_config,
33
+ options=[
34
+ "9600",
35
+ "19200",
36
+ "38400",
37
+ "57600",
38
+ "115200",
39
+ "230400",
40
+ "256000",
41
+ "460800",
42
+ ],
43
+ )
44
+ await cg.register_parented(s, config[CONF_LD2450_ID])
45
+ cg.add(ld2450_component.set_baud_rate_select(s))
46
+ if zone_type_config := config.get(CONF_ZONE_TYPE):
47
+ s = await select.new_select(
48
+ zone_type_config,
49
+ options=[
50
+ "Disabled",
51
+ "Detection",
52
+ "Filter",
53
+ ],
54
+ )
55
+ await cg.register_parented(s, config[CONF_LD2450_ID])
56
+ cg.add(ld2450_component.set_zone_type_select(s))
@@ -0,0 +1,12 @@
1
+ #include "baud_rate_select.h"
2
+
3
+ namespace esphome {
4
+ namespace ld2450 {
5
+
6
+ void BaudRateSelect::control(const std::string &value) {
7
+ this->publish_state(value);
8
+ this->parent_->set_baud_rate(state);
9
+ }
10
+
11
+ } // namespace ld2450
12
+ } // namespace esphome
@@ -0,0 +1,18 @@
1
+ #pragma once
2
+
3
+ #include "esphome/components/select/select.h"
4
+ #include "../ld2450.h"
5
+
6
+ namespace esphome {
7
+ namespace ld2450 {
8
+
9
+ class BaudRateSelect : public select::Select, public Parented<LD2450Component> {
10
+ public:
11
+ BaudRateSelect() = default;
12
+
13
+ protected:
14
+ void control(const std::string &value) override;
15
+ };
16
+
17
+ } // namespace ld2450
18
+ } // namespace esphome
@@ -0,0 +1,12 @@
1
+ #include "zone_type_select.h"
2
+
3
+ namespace esphome {
4
+ namespace ld2450 {
5
+
6
+ void ZoneTypeSelect::control(const std::string &value) {
7
+ this->publish_state(value);
8
+ this->parent_->set_zone_type(state);
9
+ }
10
+
11
+ } // namespace ld2450
12
+ } // namespace esphome
@@ -0,0 +1,18 @@
1
+ #pragma once
2
+
3
+ #include "esphome/components/select/select.h"
4
+ #include "../ld2450.h"
5
+
6
+ namespace esphome {
7
+ namespace ld2450 {
8
+
9
+ class ZoneTypeSelect : public select::Select, public Parented<LD2450Component> {
10
+ public:
11
+ ZoneTypeSelect() = default;
12
+
13
+ protected:
14
+ void control(const std::string &value) override;
15
+ };
16
+
17
+ } // namespace ld2450
18
+ } // namespace esphome