esphome 2024.8.2__py3-none-any.whl → 2024.9.0__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.
- esphome/__main__.py +6 -2
- esphome/components/api/api_connection.cpp +53 -0
- esphome/components/api/api_connection.h +4 -0
- esphome/components/api/api_pb2.cpp +280 -0
- esphome/components/api/api_pb2.h +91 -0
- esphome/components/api/api_pb2_service.cpp +85 -0
- esphome/components/api/api_pb2_service.h +28 -0
- esphome/components/async_tcp/__init__.py +3 -3
- esphome/components/atm90e26/sensor.py +10 -10
- esphome/components/atm90e32/sensor.py +1 -1
- esphome/components/bl0906/__init__.py +1 -0
- esphome/components/bl0906/bl0906.cpp +238 -0
- esphome/components/bl0906/bl0906.h +96 -0
- esphome/components/bl0906/const.py +4 -0
- esphome/components/bl0906/constants.h +122 -0
- esphome/components/bl0906/sensor.py +184 -0
- esphome/components/bl0942/__init__.py +1 -1
- esphome/components/bl0942/bl0942.cpp +127 -34
- esphome/components/bl0942/bl0942.h +87 -3
- esphome/components/bl0942/sensor.py +46 -8
- esphome/components/ble_client/__init__.py +1 -3
- esphome/components/ble_presence/binary_sensor.py +2 -2
- esphome/components/bluetooth_proxy/bluetooth_proxy.cpp +5 -0
- esphome/components/bmp280/sensor.py +2 -93
- esphome/components/bmp280_base/__init__.py +88 -0
- esphome/components/{bmp280/bmp280.cpp → bmp280_base/bmp280_base.cpp} +11 -4
- esphome/components/{bmp280/bmp280.h → bmp280_base/bmp280_base.h} +9 -5
- esphome/components/bmp280_i2c/__init__.py +0 -0
- esphome/components/bmp280_i2c/bmp280_i2c.cpp +27 -0
- esphome/components/bmp280_i2c/bmp280_i2c.h +22 -0
- esphome/components/bmp280_i2c/sensor.py +22 -0
- esphome/components/bmp280_spi/__init__.py +0 -0
- esphome/components/bmp280_spi/bmp280_spi.cpp +65 -0
- esphome/components/bmp280_spi/bmp280_spi.h +20 -0
- esphome/components/bmp280_spi/sensor.py +22 -0
- esphome/components/captive_portal/captive_portal.cpp +2 -0
- esphome/components/captive_portal/captive_portal.h +3 -1
- esphome/components/ch422g/__init__.py +67 -0
- esphome/components/ch422g/ch422g.cpp +122 -0
- esphome/components/ch422g/ch422g.h +70 -0
- esphome/components/debug/debug_esp32.cpp +3 -1
- esphome/components/display/__init__.py +5 -4
- esphome/components/dsmr/dsmr.cpp +6 -0
- esphome/components/dsmr/dsmr.h +6 -0
- esphome/components/dsmr/text_sensor.py +7 -2
- esphome/components/e131/e131.cpp +2 -0
- esphome/components/e131/e131.h +3 -1
- esphome/components/e131/e131_addressable_light_effect.cpp +2 -0
- esphome/components/e131/e131_addressable_light_effect.h +2 -1
- esphome/components/e131/e131_packet.cpp +2 -0
- esphome/components/esp32_ble/ble_uuid.cpp +7 -0
- esphome/components/esp32_ble/ble_uuid.h +1 -0
- esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp +11 -9
- esphome/components/esp32_ble_tracker/esp32_ble_tracker.h +3 -3
- esphome/components/esp32_camera/__init__.py +4 -0
- esphome/components/esp32_camera/esp32_camera.cpp +9 -1
- esphome/components/esp32_camera/esp32_camera.h +3 -0
- esphome/components/esp32_can/canbus.py +18 -7
- esphome/components/esp32_can/esp32_can.cpp +8 -0
- esphome/components/esp32_can/esp32_can.h +4 -0
- esphome/components/esp32_rmt_led_strip/led_strip.cpp +14 -2
- esphome/components/esp32_rmt_led_strip/led_strip.h +3 -2
- esphome/components/esp32_rmt_led_strip/light.py +21 -4
- esphome/components/esphome/ota/ota_esphome.cpp +2 -1
- esphome/components/esphome/ota/ota_esphome.h +2 -0
- esphome/components/font/__init__.py +11 -22
- esphome/components/font/font.cpp +3 -2
- esphome/components/font/font.h +12 -3
- esphome/components/gree/climate.py +2 -1
- esphome/components/gree/gree.cpp +54 -3
- esphome/components/gree/gree.h +10 -2
- esphome/components/gt911/touchscreen/__init__.py +6 -4
- esphome/components/gt911/touchscreen/gt911_touchscreen.cpp +17 -0
- esphome/components/gt911/touchscreen/gt911_touchscreen.h +2 -0
- esphome/components/hmac_md5/__init__.py +2 -0
- esphome/components/hmac_md5/hmac_md5.cpp +56 -0
- esphome/components/hmac_md5/hmac_md5.h +48 -0
- esphome/components/homeassistant/__init__.py +13 -0
- esphome/components/homeassistant/switch/__init__.py +15 -2
- esphome/components/homeassistant/switch/homeassistant_switch.cpp +2 -2
- esphome/components/i2s_audio/__init__.py +88 -9
- esphome/components/i2s_audio/i2s_audio.h +20 -2
- esphome/components/i2s_audio/media_player/__init__.py +8 -4
- esphome/components/i2s_audio/media_player/i2s_audio_media_player.h +1 -1
- esphome/components/i2s_audio/microphone/__init__.py +19 -51
- esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp +18 -15
- esphome/components/i2s_audio/microphone/i2s_audio_microphone.h +0 -12
- esphome/components/i2s_audio/speaker/__init__.py +39 -27
- esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +49 -37
- esphome/components/i2s_audio/speaker/i2s_audio_speaker.h +3 -4
- esphome/components/ili9xxx/display.py +16 -17
- esphome/components/ili9xxx/ili9xxx_display.cpp +1 -1
- esphome/components/ili9xxx/ili9xxx_display.h +18 -18
- esphome/components/ili9xxx/ili9xxx_init.h +0 -3
- esphome/components/improv_serial/improv_serial_component.cpp +2 -1
- esphome/components/improv_serial/improv_serial_component.h +2 -1
- esphome/components/ledc/ledc_output.cpp +11 -7
- esphome/components/libretiny/__init__.py +8 -13
- esphome/components/ltr501/__init__.py +1 -0
- esphome/components/ltr501/ltr501.cpp +542 -0
- esphome/components/ltr501/ltr501.h +184 -0
- esphome/components/ltr501/ltr_definitions_501.h +260 -0
- esphome/components/ltr501/sensor.py +274 -0
- esphome/components/ltr_als_ps/sensor.py +2 -2
- esphome/components/lvgl/__init__.py +19 -16
- esphome/components/lvgl/automation.py +90 -9
- esphome/components/lvgl/defines.py +29 -2
- esphome/components/lvgl/gradient.py +61 -0
- esphome/components/lvgl/lv_validation.py +45 -27
- esphome/components/lvgl/lvcode.py +8 -3
- esphome/components/lvgl/lvgl_esphome.cpp +54 -0
- esphome/components/lvgl/lvgl_esphome.h +9 -3
- esphome/components/lvgl/number/__init__.py +1 -0
- esphome/components/lvgl/number/lvgl_number.h +3 -1
- esphome/components/lvgl/schemas.py +16 -11
- esphome/components/lvgl/select/__init__.py +1 -0
- esphome/components/lvgl/select/lvgl_select.h +3 -1
- esphome/components/lvgl/switch/__init__.py +2 -1
- esphome/components/lvgl/switch/lvgl_switch.h +3 -1
- esphome/components/lvgl/text/__init__.py +1 -0
- esphome/components/lvgl/text/lvgl_text.h +3 -1
- esphome/components/lvgl/trigger.py +3 -2
- esphome/components/lvgl/types.py +2 -1
- esphome/components/lvgl/widgets/__init__.py +23 -8
- esphome/components/lvgl/widgets/arc.py +5 -1
- esphome/components/lvgl/widgets/buttonmatrix.py +5 -1
- esphome/components/lvgl/widgets/checkbox.py +8 -3
- esphome/components/lvgl/widgets/meter.py +8 -1
- esphome/components/lvgl/widgets/msgbox.py +26 -15
- esphome/components/lvgl/widgets/page.py +51 -7
- esphome/components/lvgl/widgets/tileview.py +2 -8
- esphome/components/max31856/max31856.cpp +12 -1
- esphome/components/max31856/max31856.h +5 -2
- esphome/components/max31856/sensor.py +20 -0
- esphome/components/mcp9600/sensor.py +2 -2
- esphome/components/mdns/__init__.py +6 -6
- esphome/components/media_player/media_player.h +16 -0
- esphome/components/micro_wake_word/__init__.py +2 -25
- esphome/components/microphone/microphone.h +1 -1
- esphome/components/mics_4514/mics_4514.cpp +26 -36
- esphome/components/modbus_controller/__init__.py +6 -0
- esphome/components/modbus_controller/const.py +2 -0
- esphome/components/modbus_controller/modbus_controller.cpp +30 -27
- esphome/components/modbus_controller/modbus_controller.h +22 -4
- esphome/components/network/__init__.py +11 -8
- esphome/components/pipsolar/pipsolar.cpp +3 -0
- esphome/components/pipsolar/pipsolar.h +1 -0
- esphome/components/pipsolar/switch/__init__.py +2 -0
- esphome/components/prometheus/prometheus_handler.cpp +2 -0
- esphome/components/prometheus/prometheus_handler.h +3 -1
- esphome/components/rp2040/__init__.py +7 -8
- esphome/components/rpi_dpi_rgb/display.py +20 -17
- esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp +36 -6
- esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.h +4 -0
- esphome/components/socket/socket.cpp +2 -0
- esphome/components/socket/socket.h +2 -0
- esphome/components/speaker/speaker.h +1 -1
- esphome/components/st7701s/display.py +35 -37
- esphome/components/st7701s/st7701s.cpp +11 -6
- esphome/components/st7701s/st7701s.h +1 -0
- esphome/components/statsd/__init__.py +65 -0
- esphome/components/statsd/statsd.cpp +156 -0
- esphome/components/statsd/statsd.h +86 -0
- esphome/components/tuya/__init__.py +1 -0
- esphome/components/tuya/number/__init__.py +39 -2
- esphome/components/tuya/number/tuya_number.cpp +58 -2
- esphome/components/tuya/number/tuya_number.h +12 -3
- esphome/components/udp/__init__.py +158 -0
- esphome/components/udp/binary_sensor.py +27 -0
- esphome/components/udp/sensor.py +27 -0
- esphome/components/udp/udp_component.cpp +616 -0
- esphome/components/udp/udp_component.h +158 -0
- esphome/components/uponor_smatrix/uponor_smatrix.cpp +4 -6
- esphome/components/uponor_smatrix/uponor_smatrix.h +0 -1
- esphome/components/veml7700/sensor.py +2 -2
- esphome/components/voice_assistant/__init__.py +6 -0
- esphome/components/voice_assistant/voice_assistant.cpp +24 -2
- esphome/components/voice_assistant/voice_assistant.h +20 -0
- esphome/components/web_server/__init__.py +11 -11
- esphome/components/web_server/list_entities.cpp +2 -0
- esphome/components/web_server/list_entities.h +3 -1
- esphome/components/web_server/web_server.cpp +2 -1
- esphome/components/web_server/web_server.h +2 -0
- esphome/components/web_server_base/web_server_base.cpp +2 -0
- esphome/components/web_server_base/web_server_base.h +3 -1
- esphome/components/wifi/wifi_component_libretiny.cpp +15 -1
- esphome/components/wireguard/__init__.py +9 -6
- esphome/components/wireguard/wireguard.cpp +2 -1
- esphome/components/wireguard/wireguard.h +3 -1
- esphome/config_validation.py +8 -0
- esphome/const.py +8 -1
- esphome/core/bytebuffer.cpp +117 -84
- esphome/core/bytebuffer.h +69 -21
- esphome/core/config.py +0 -3
- esphome/core/defines.h +2 -0
- esphome/core/ring_buffer.cpp +13 -2
- esphome/core/ring_buffer.h +56 -0
- esphome/external_files.py +5 -3
- {esphome-2024.8.2.dist-info → esphome-2024.9.0.dist-info}/METADATA +1 -1
- {esphome-2024.8.2.dist-info → esphome-2024.9.0.dist-info}/RECORD +204 -169
- {esphome-2024.8.2.dist-info → esphome-2024.9.0.dist-info}/LICENSE +0 -0
- {esphome-2024.8.2.dist-info → esphome-2024.9.0.dist-info}/WHEEL +0 -0
- {esphome-2024.8.2.dist-info → esphome-2024.9.0.dist-info}/entry_points.txt +0 -0
- {esphome-2024.8.2.dist-info → esphome-2024.9.0.dist-info}/top_level.txt +0 -0
esphome/core/bytebuffer.cpp
CHANGED
@@ -1,19 +1,67 @@
|
|
1
1
|
#include "bytebuffer.h"
|
2
2
|
#include <cassert>
|
3
|
+
#include "esphome/core/helpers.h"
|
4
|
+
|
5
|
+
#include <list>
|
6
|
+
#include <vector>
|
3
7
|
|
4
8
|
namespace esphome {
|
5
9
|
|
6
|
-
ByteBuffer ByteBuffer::
|
7
|
-
|
8
|
-
|
10
|
+
ByteBuffer ByteBuffer::wrap(const uint8_t *ptr, size_t len, Endian endianness) {
|
11
|
+
// there is a double copy happening here, could be optimized but at cost of clarity.
|
12
|
+
std::vector<uint8_t> data(ptr, ptr + len);
|
13
|
+
ByteBuffer buffer = {data};
|
14
|
+
buffer.endianness_ = endianness;
|
15
|
+
return buffer;
|
9
16
|
}
|
10
17
|
|
11
|
-
ByteBuffer ByteBuffer::wrap(uint8_t
|
12
|
-
|
13
|
-
|
18
|
+
ByteBuffer ByteBuffer::wrap(std::vector<uint8_t> const &data, Endian endianness) {
|
19
|
+
ByteBuffer buffer = {data};
|
20
|
+
buffer.endianness_ = endianness;
|
21
|
+
return buffer;
|
22
|
+
}
|
23
|
+
|
24
|
+
ByteBuffer ByteBuffer::wrap(uint8_t value) {
|
25
|
+
ByteBuffer buffer = ByteBuffer(1);
|
26
|
+
buffer.put_uint8(value);
|
27
|
+
buffer.flip();
|
28
|
+
return buffer;
|
29
|
+
}
|
30
|
+
|
31
|
+
ByteBuffer ByteBuffer::wrap(uint16_t value, Endian endianness) {
|
32
|
+
ByteBuffer buffer = ByteBuffer(2, endianness);
|
33
|
+
buffer.put_uint16(value);
|
34
|
+
buffer.flip();
|
35
|
+
return buffer;
|
36
|
+
}
|
37
|
+
|
38
|
+
ByteBuffer ByteBuffer::wrap(uint32_t value, Endian endianness) {
|
39
|
+
ByteBuffer buffer = ByteBuffer(4, endianness);
|
40
|
+
buffer.put_uint32(value);
|
41
|
+
buffer.flip();
|
42
|
+
return buffer;
|
14
43
|
}
|
15
44
|
|
16
|
-
ByteBuffer ByteBuffer::wrap(
|
45
|
+
ByteBuffer ByteBuffer::wrap(uint64_t value, Endian endianness) {
|
46
|
+
ByteBuffer buffer = ByteBuffer(8, endianness);
|
47
|
+
buffer.put_uint64(value);
|
48
|
+
buffer.flip();
|
49
|
+
return buffer;
|
50
|
+
}
|
51
|
+
|
52
|
+
ByteBuffer ByteBuffer::wrap(float value, Endian endianness) {
|
53
|
+
ByteBuffer buffer = ByteBuffer(sizeof(float), endianness);
|
54
|
+
buffer.put_float(value);
|
55
|
+
buffer.flip();
|
56
|
+
return buffer;
|
57
|
+
}
|
58
|
+
|
59
|
+
ByteBuffer ByteBuffer::wrap(double value, Endian endianness) {
|
60
|
+
ByteBuffer buffer = ByteBuffer(sizeof(double), endianness);
|
61
|
+
buffer.put_double(value);
|
62
|
+
buffer.flip();
|
63
|
+
return buffer;
|
64
|
+
}
|
17
65
|
|
18
66
|
void ByteBuffer::set_limit(size_t limit) {
|
19
67
|
assert(limit <= this->get_capacity());
|
@@ -27,108 +75,93 @@ void ByteBuffer::clear() {
|
|
27
75
|
this->limit_ = this->get_capacity();
|
28
76
|
this->position_ = 0;
|
29
77
|
}
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
if (endianness_ == LITTLE) {
|
34
|
-
value = this->data_[this->position_++];
|
35
|
-
value |= this->data_[this->position_++] << 8;
|
36
|
-
} else {
|
37
|
-
value = this->data_[this->position_++] << 8;
|
38
|
-
value |= this->data_[this->position_++];
|
39
|
-
}
|
40
|
-
return value;
|
78
|
+
void ByteBuffer::flip() {
|
79
|
+
this->limit_ = this->position_;
|
80
|
+
this->position_ = 0;
|
41
81
|
}
|
42
82
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
value = this->data_[this->position_++];
|
48
|
-
value |= this->data_[this->position_++] << 8;
|
49
|
-
value |= this->data_[this->position_++] << 16;
|
50
|
-
value |= this->data_[this->position_++] << 24;
|
51
|
-
} else {
|
52
|
-
value = this->data_[this->position_++] << 24;
|
53
|
-
value |= this->data_[this->position_++] << 16;
|
54
|
-
value |= this->data_[this->position_++] << 8;
|
55
|
-
value |= this->data_[this->position_++];
|
56
|
-
}
|
57
|
-
return value;
|
83
|
+
/// Getters
|
84
|
+
uint8_t ByteBuffer::get_uint8() {
|
85
|
+
assert(this->get_remaining() >= 1);
|
86
|
+
return this->data_[this->position_++];
|
58
87
|
}
|
59
|
-
|
60
|
-
assert(this->get_remaining() >=
|
61
|
-
|
62
|
-
if (endianness_ == LITTLE) {
|
63
|
-
|
64
|
-
|
65
|
-
|
88
|
+
uint64_t ByteBuffer::get_uint(size_t length) {
|
89
|
+
assert(this->get_remaining() >= length);
|
90
|
+
uint64_t value = 0;
|
91
|
+
if (this->endianness_ == LITTLE) {
|
92
|
+
this->position_ += length;
|
93
|
+
auto index = this->position_;
|
94
|
+
while (length-- != 0) {
|
95
|
+
value <<= 8;
|
96
|
+
value |= this->data_[--index];
|
97
|
+
}
|
66
98
|
} else {
|
67
|
-
|
68
|
-
|
69
|
-
|
99
|
+
while (length-- != 0) {
|
100
|
+
value <<= 8;
|
101
|
+
value |= this->data_[this->position_++];
|
102
|
+
}
|
70
103
|
}
|
71
104
|
return value;
|
72
105
|
}
|
106
|
+
|
73
107
|
uint32_t ByteBuffer::get_int24() {
|
74
108
|
auto value = this->get_uint24();
|
75
|
-
uint32_t mask = (~(
|
109
|
+
uint32_t mask = (~static_cast<uint32_t>(0)) << 23;
|
76
110
|
if ((value & mask) != 0)
|
77
111
|
value |= mask;
|
78
112
|
return value;
|
79
113
|
}
|
80
|
-
uint8_t ByteBuffer::get_uint8() {
|
81
|
-
assert(this->get_remaining() >= 1);
|
82
|
-
return this->data_[this->position_++];
|
83
|
-
}
|
84
114
|
float ByteBuffer::get_float() {
|
85
|
-
|
86
|
-
return
|
115
|
+
assert(this->get_remaining() >= sizeof(float));
|
116
|
+
return bit_cast<float>(this->get_uint32());
|
117
|
+
}
|
118
|
+
double ByteBuffer::get_double() {
|
119
|
+
assert(this->get_remaining() >= sizeof(double));
|
120
|
+
return bit_cast<double>(this->get_uint64());
|
121
|
+
}
|
122
|
+
|
123
|
+
std::vector<uint8_t> ByteBuffer::get_vector(size_t length) {
|
124
|
+
assert(this->get_remaining() >= length);
|
125
|
+
auto start = this->data_.begin() + this->position_;
|
126
|
+
this->position_ += length;
|
127
|
+
return {start, start + length};
|
87
128
|
}
|
129
|
+
|
130
|
+
/// Putters
|
88
131
|
void ByteBuffer::put_uint8(uint8_t value) {
|
89
132
|
assert(this->get_remaining() >= 1);
|
90
133
|
this->data_[this->position_++] = value;
|
91
134
|
}
|
92
135
|
|
93
|
-
void ByteBuffer::
|
94
|
-
assert(this->get_remaining() >=
|
136
|
+
void ByteBuffer::put_uint(uint64_t value, size_t length) {
|
137
|
+
assert(this->get_remaining() >= length);
|
95
138
|
if (this->endianness_ == LITTLE) {
|
96
|
-
|
97
|
-
|
139
|
+
while (length-- != 0) {
|
140
|
+
this->data_[this->position_++] = static_cast<uint8_t>(value);
|
141
|
+
value >>= 8;
|
142
|
+
}
|
98
143
|
} else {
|
99
|
-
this->
|
100
|
-
this->
|
144
|
+
this->position_ += length;
|
145
|
+
auto index = this->position_;
|
146
|
+
while (length-- != 0) {
|
147
|
+
this->data_[--index] = static_cast<uint8_t>(value);
|
148
|
+
value >>= 8;
|
149
|
+
}
|
101
150
|
}
|
102
151
|
}
|
103
|
-
void ByteBuffer::
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
this->data_[this->position_++] = (uint8_t) (value >> 8);
|
108
|
-
this->data_[this->position_++] = (uint8_t) (value >> 16);
|
109
|
-
} else {
|
110
|
-
this->data_[this->position_++] = (uint8_t) (value >> 16);
|
111
|
-
this->data_[this->position_++] = (uint8_t) (value >> 8);
|
112
|
-
this->data_[this->position_++] = (uint8_t) value;
|
113
|
-
}
|
152
|
+
void ByteBuffer::put_float(float value) {
|
153
|
+
static_assert(sizeof(float) == sizeof(uint32_t), "Float sizes other than 32 bit not supported");
|
154
|
+
assert(this->get_remaining() >= sizeof(float));
|
155
|
+
this->put_uint32(bit_cast<uint32_t>(value));
|
114
156
|
}
|
115
|
-
void ByteBuffer::
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
this->data_[this->position_++] = (uint8_t) (value >> 8);
|
120
|
-
this->data_[this->position_++] = (uint8_t) (value >> 16);
|
121
|
-
this->data_[this->position_++] = (uint8_t) (value >> 24);
|
122
|
-
} else {
|
123
|
-
this->data_[this->position_++] = (uint8_t) (value >> 24);
|
124
|
-
this->data_[this->position_++] = (uint8_t) (value >> 16);
|
125
|
-
this->data_[this->position_++] = (uint8_t) (value >> 8);
|
126
|
-
this->data_[this->position_++] = (uint8_t) value;
|
127
|
-
}
|
157
|
+
void ByteBuffer::put_double(double value) {
|
158
|
+
static_assert(sizeof(double) == sizeof(uint64_t), "Double sizes other than 64 bit not supported");
|
159
|
+
assert(this->get_remaining() >= sizeof(double));
|
160
|
+
this->put_uint64(bit_cast<uint64_t>(value));
|
128
161
|
}
|
129
|
-
void ByteBuffer::
|
130
|
-
|
131
|
-
this->
|
132
|
-
this->position_
|
162
|
+
void ByteBuffer::put_vector(const std::vector<uint8_t> &value) {
|
163
|
+
assert(this->get_remaining() >= value.size());
|
164
|
+
std::copy(value.begin(), value.end(), this->data_.begin() + this->position_);
|
165
|
+
this->position_ += value.size();
|
133
166
|
}
|
134
167
|
} // namespace esphome
|
esphome/core/bytebuffer.h
CHANGED
@@ -15,55 +15,103 @@ enum Endian { LITTLE, BIG };
|
|
15
15
|
*
|
16
16
|
* There are three variables maintained pointing into the buffer:
|
17
17
|
*
|
18
|
-
*
|
19
|
-
*
|
20
|
-
* capacity: the maximum amount of data that can be stored
|
18
|
+
* capacity: the maximum amount of data that can be stored - set on construction and cannot be changed
|
21
19
|
* limit: the limit of the data currently available to get or put
|
22
20
|
* position: the current insert or extract position
|
23
21
|
*
|
22
|
+
* 0 <= position <= limit <= capacity
|
23
|
+
*
|
24
24
|
* In addition a mark can be set to the current position with mark(). A subsequent call to reset() will restore
|
25
25
|
* the position to the mark.
|
26
26
|
*
|
27
27
|
* The buffer can be marked to be little-endian (default) or big-endian. All subsequent operations will use that order.
|
28
28
|
*
|
29
|
+
* The flip() operation will reset the position to 0 and limit to the current position. This is useful for reading
|
30
|
+
* data from a buffer after it has been written.
|
31
|
+
*
|
29
32
|
*/
|
30
33
|
class ByteBuffer {
|
31
34
|
public:
|
35
|
+
// Default constructor (compatibility with TEMPLATABLE_VALUE)
|
36
|
+
ByteBuffer() : ByteBuffer(std::vector<uint8_t>()) {}
|
32
37
|
/**
|
33
38
|
* Create a new Bytebuffer with the given capacity
|
34
39
|
*/
|
35
|
-
|
40
|
+
ByteBuffer(size_t capacity, Endian endianness = LITTLE)
|
41
|
+
: data_(std::vector<uint8_t>(capacity)), endianness_(endianness), limit_(capacity){};
|
36
42
|
/**
|
37
|
-
* Wrap an existing vector in a
|
43
|
+
* Wrap an existing vector in a ByteBufffer
|
38
44
|
*/
|
39
|
-
static ByteBuffer wrap(std::vector<uint8_t> data);
|
45
|
+
static ByteBuffer wrap(std::vector<uint8_t> const &data, Endian endianness = LITTLE);
|
40
46
|
/**
|
41
|
-
* Wrap an existing array in a
|
47
|
+
* Wrap an existing array in a ByteBuffer. Note that this will create a copy of the data.
|
42
48
|
*/
|
43
|
-
static ByteBuffer wrap(uint8_t *ptr, size_t len);
|
49
|
+
static ByteBuffer wrap(const uint8_t *ptr, size_t len, Endian endianness = LITTLE);
|
50
|
+
// Convenience functions to create a ByteBuffer from a value
|
51
|
+
static ByteBuffer wrap(uint8_t value);
|
52
|
+
static ByteBuffer wrap(uint16_t value, Endian endianness = LITTLE);
|
53
|
+
static ByteBuffer wrap(uint32_t value, Endian endianness = LITTLE);
|
54
|
+
static ByteBuffer wrap(uint64_t value, Endian endianness = LITTLE);
|
55
|
+
static ByteBuffer wrap(int8_t value) { return wrap(static_cast<uint8_t>(value)); }
|
56
|
+
static ByteBuffer wrap(int16_t value, Endian endianness = LITTLE) {
|
57
|
+
return wrap(static_cast<uint16_t>(value), endianness);
|
58
|
+
}
|
59
|
+
static ByteBuffer wrap(int32_t value, Endian endianness = LITTLE) {
|
60
|
+
return wrap(static_cast<uint32_t>(value), endianness);
|
61
|
+
}
|
62
|
+
static ByteBuffer wrap(int64_t value, Endian endianness = LITTLE) {
|
63
|
+
return wrap(static_cast<uint64_t>(value), endianness);
|
64
|
+
}
|
65
|
+
static ByteBuffer wrap(float value, Endian endianness = LITTLE);
|
66
|
+
static ByteBuffer wrap(double value, Endian endianness = LITTLE);
|
67
|
+
static ByteBuffer wrap(bool value) { return wrap(static_cast<uint8_t>(value)); }
|
44
68
|
|
69
|
+
// Get an integral value from the buffer, increment position by length
|
70
|
+
uint64_t get_uint(size_t length);
|
45
71
|
// Get one byte from the buffer, increment position by 1
|
46
72
|
uint8_t get_uint8();
|
47
73
|
// Get a 16 bit unsigned value, increment by 2
|
48
|
-
uint16_t get_uint16();
|
74
|
+
uint16_t get_uint16() { return static_cast<uint16_t>(this->get_uint(sizeof(uint16_t))); };
|
49
75
|
// Get a 24 bit unsigned value, increment by 3
|
50
|
-
uint32_t get_uint24();
|
76
|
+
uint32_t get_uint24() { return static_cast<uint32_t>(this->get_uint(3)); };
|
51
77
|
// Get a 32 bit unsigned value, increment by 4
|
52
|
-
uint32_t get_uint32();
|
53
|
-
//
|
54
|
-
|
55
|
-
|
78
|
+
uint32_t get_uint32() { return static_cast<uint32_t>(this->get_uint(sizeof(uint32_t))); };
|
79
|
+
// Get a 64 bit unsigned value, increment by 8
|
80
|
+
uint64_t get_uint64() { return this->get_uint(sizeof(uint64_t)); };
|
81
|
+
// Signed versions of the get functions
|
82
|
+
uint8_t get_int8() { return static_cast<int8_t>(this->get_uint8()); };
|
83
|
+
int16_t get_int16() { return static_cast<int16_t>(this->get_uint(sizeof(int16_t))); }
|
56
84
|
uint32_t get_int24();
|
57
|
-
int32_t get_int32() { return (
|
85
|
+
int32_t get_int32() { return static_cast<int32_t>(this->get_uint(sizeof(int32_t))); }
|
86
|
+
int64_t get_int64() { return static_cast<int64_t>(this->get_uint(sizeof(int64_t))); }
|
58
87
|
// Get a float value, increment by 4
|
59
88
|
float get_float();
|
89
|
+
// Get a double value, increment by 8
|
90
|
+
double get_double();
|
91
|
+
// Get a bool value, increment by 1
|
92
|
+
bool get_bool() { return this->get_uint8(); }
|
93
|
+
// Get vector of bytes, increment by length
|
94
|
+
std::vector<uint8_t> get_vector(size_t length);
|
60
95
|
|
61
|
-
//
|
96
|
+
// Put values into the buffer, increment the position accordingly
|
97
|
+
// put any integral value, length represents the number of bytes
|
98
|
+
void put_uint(uint64_t value, size_t length);
|
62
99
|
void put_uint8(uint8_t value);
|
63
|
-
void put_uint16(uint16_t value);
|
64
|
-
void put_uint24(uint32_t value);
|
65
|
-
void put_uint32(uint32_t value);
|
100
|
+
void put_uint16(uint16_t value) { this->put_uint(value, sizeof(uint16_t)); }
|
101
|
+
void put_uint24(uint32_t value) { this->put_uint(value, 3); }
|
102
|
+
void put_uint32(uint32_t value) { this->put_uint(value, sizeof(uint32_t)); }
|
103
|
+
void put_uint64(uint64_t value) { this->put_uint(value, sizeof(uint64_t)); }
|
104
|
+
// Signed versions of the put functions
|
105
|
+
void put_int8(int8_t value) { this->put_uint8(static_cast<uint8_t>(value)); }
|
106
|
+
void put_int16(int32_t value) { this->put_uint(static_cast<uint16_t>(value), sizeof(uint16_t)); }
|
107
|
+
void put_int24(int32_t value) { this->put_uint(static_cast<uint32_t>(value), 3); }
|
108
|
+
void put_int32(int32_t value) { this->put_uint(static_cast<uint32_t>(value), sizeof(uint32_t)); }
|
109
|
+
void put_int64(int64_t value) { this->put_uint(static_cast<uint64_t>(value), sizeof(uint64_t)); }
|
110
|
+
// Extra put functions
|
66
111
|
void put_float(float value);
|
112
|
+
void put_double(double value);
|
113
|
+
void put_bool(bool value) { this->put_uint8(value); }
|
114
|
+
void put_vector(const std::vector<uint8_t> &value);
|
67
115
|
|
68
116
|
inline size_t get_capacity() const { return this->data_.size(); }
|
69
117
|
inline size_t get_position() const { return this->position_; }
|
@@ -80,12 +128,12 @@ class ByteBuffer {
|
|
80
128
|
// set limit to current position, postition to zero. Used when swapping from write to read operations.
|
81
129
|
void flip();
|
82
130
|
// retrieve a pointer to the underlying data.
|
83
|
-
uint8_t
|
131
|
+
std::vector<uint8_t> get_data() { return this->data_; };
|
84
132
|
void rewind() { this->position_ = 0; }
|
85
133
|
void reset() { this->position_ = this->mark_; }
|
86
134
|
|
87
135
|
protected:
|
88
|
-
ByteBuffer(std::vector<uint8_t> data) : data_(
|
136
|
+
ByteBuffer(std::vector<uint8_t> const &data) : data_(data), limit_(data.size()) {}
|
89
137
|
std::vector<uint8_t> data_;
|
90
138
|
Endian endianness_{LITTLE};
|
91
139
|
size_t position_{0};
|
esphome/core/config.py
CHANGED
esphome/core/defines.h
CHANGED
@@ -28,6 +28,7 @@
|
|
28
28
|
#define USE_DATETIME_DATETIME
|
29
29
|
#define USE_DATETIME_TIME
|
30
30
|
#define USE_DEEP_SLEEP
|
31
|
+
#define USE_DISPLAY
|
31
32
|
#define USE_EVENT
|
32
33
|
#define USE_FAN
|
33
34
|
#define USE_GRAPH
|
@@ -75,6 +76,7 @@
|
|
75
76
|
#define USE_VALVE
|
76
77
|
#define USE_WIFI
|
77
78
|
#define USE_WIFI_AP
|
79
|
+
#define USE_WIREGUARD
|
78
80
|
|
79
81
|
// Arduino-specific feature flags
|
80
82
|
#ifdef USE_ARDUINO
|
esphome/core/ring_buffer.cpp
CHANGED
@@ -20,13 +20,20 @@ std::unique_ptr<RingBuffer> RingBuffer::create(size_t len) {
|
|
20
20
|
return nullptr;
|
21
21
|
}
|
22
22
|
|
23
|
-
rb->handle_ = xStreamBufferCreateStatic(len + 1,
|
23
|
+
rb->handle_ = xStreamBufferCreateStatic(len + 1, 1, rb->storage_, &rb->structure_);
|
24
24
|
ESP_LOGD(TAG, "Created ring buffer with size %u", len);
|
25
25
|
return rb;
|
26
26
|
}
|
27
27
|
|
28
28
|
size_t RingBuffer::read(void *data, size_t len, TickType_t ticks_to_wait) {
|
29
|
-
|
29
|
+
if (ticks_to_wait > 0)
|
30
|
+
xStreamBufferSetTriggerLevel(this->handle_, len);
|
31
|
+
|
32
|
+
size_t bytes_read = xStreamBufferReceive(this->handle_, data, len, ticks_to_wait);
|
33
|
+
|
34
|
+
xStreamBufferSetTriggerLevel(this->handle_, 1);
|
35
|
+
|
36
|
+
return bytes_read;
|
30
37
|
}
|
31
38
|
|
32
39
|
size_t RingBuffer::write(void *data, size_t len) {
|
@@ -39,6 +46,10 @@ size_t RingBuffer::write(void *data, size_t len) {
|
|
39
46
|
return xStreamBufferSend(this->handle_, data, len, 0);
|
40
47
|
}
|
41
48
|
|
49
|
+
size_t RingBuffer::write_without_replacement(void *data, size_t len, TickType_t ticks_to_wait) {
|
50
|
+
return xStreamBufferSend(this->handle_, data, len, ticks_to_wait);
|
51
|
+
}
|
52
|
+
|
42
53
|
size_t RingBuffer::available() const { return xStreamBufferBytesAvailable(this->handle_); }
|
43
54
|
|
44
55
|
size_t RingBuffer::free() const { return xStreamBufferSpacesAvailable(this->handle_); }
|
esphome/core/ring_buffer.h
CHANGED
@@ -12,13 +12,69 @@ namespace esphome {
|
|
12
12
|
|
13
13
|
class RingBuffer {
|
14
14
|
public:
|
15
|
+
/**
|
16
|
+
* @brief Reads from the ring buffer, waiting up to a specified number of ticks if necessary.
|
17
|
+
*
|
18
|
+
* Available bytes are read into the provided data pointer. If not enough bytes are available,
|
19
|
+
* the function will wait up to `ticks_to_wait` FreeRTOS ticks before reading what is available.
|
20
|
+
*
|
21
|
+
* @param data Pointer to copy read data into
|
22
|
+
* @param len Number of bytes to read
|
23
|
+
* @param ticks_to_wait Maximum number of FreeRTOS ticks to wait (default: 0)
|
24
|
+
* @return Number of bytes read
|
25
|
+
*/
|
15
26
|
size_t read(void *data, size_t len, TickType_t ticks_to_wait = 0);
|
16
27
|
|
28
|
+
/**
|
29
|
+
* @brief Writes to the ring buffer, overwriting oldest data if necessary.
|
30
|
+
*
|
31
|
+
* The provided data is written to the ring buffer. If not enough space is available,
|
32
|
+
* the function will overwrite the oldest data in the ring buffer.
|
33
|
+
*
|
34
|
+
* @param data Pointer to data for writing
|
35
|
+
* @param len Number of bytes to write
|
36
|
+
* @return Number of bytes written
|
37
|
+
*/
|
17
38
|
size_t write(void *data, size_t len);
|
18
39
|
|
40
|
+
/**
|
41
|
+
* @brief Writes to the ring buffer without overwriting oldest data.
|
42
|
+
*
|
43
|
+
* The provided data is written to the ring buffer. If not enough space is available,
|
44
|
+
* the function will wait up to `ticks_to_wait` FreeRTOS ticks before writing as much as possible.
|
45
|
+
*
|
46
|
+
* @param data Pointer to data for writing
|
47
|
+
* @param len Number of bytes to write
|
48
|
+
* @param ticks_to_wait Maximum number of FreeRTOS ticks to wait (default: 0)
|
49
|
+
* @return Number of bytes written
|
50
|
+
*/
|
51
|
+
size_t write_without_replacement(void *data, size_t len, TickType_t ticks_to_wait = 0);
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @brief Returns the number of available bytes in the ring buffer.
|
55
|
+
*
|
56
|
+
* This function provides the number of bytes that can be read from the ring buffer
|
57
|
+
* without blocking the calling FreeRTOS task.
|
58
|
+
*
|
59
|
+
* @return Number of available bytes
|
60
|
+
*/
|
19
61
|
size_t available() const;
|
62
|
+
|
63
|
+
/**
|
64
|
+
* @brief Returns the number of free bytes in the ring buffer.
|
65
|
+
*
|
66
|
+
* This function provides the number of bytes that can be written to the ring buffer
|
67
|
+
* without overwriting data or blocking the calling FreeRTOS task.
|
68
|
+
*
|
69
|
+
* @return Number of free bytes
|
70
|
+
*/
|
20
71
|
size_t free() const;
|
21
72
|
|
73
|
+
/**
|
74
|
+
* @brief Resets the ring buffer, discarding all stored data.
|
75
|
+
*
|
76
|
+
* @return pdPASS if successful, pdFAIL otherwise
|
77
|
+
*/
|
22
78
|
BaseType_t reset();
|
23
79
|
|
24
80
|
static std::unique_ptr<RingBuffer> create(size_t len);
|
esphome/external_files.py
CHANGED
@@ -80,10 +80,10 @@ def compute_local_file_dir(domain: str) -> Path:
|
|
80
80
|
return base_directory
|
81
81
|
|
82
82
|
|
83
|
-
def download_content(url: str, path: Path, timeout=NETWORK_TIMEOUT) ->
|
83
|
+
def download_content(url: str, path: Path, timeout=NETWORK_TIMEOUT) -> bytes:
|
84
84
|
if not has_remote_file_changed(url, path):
|
85
85
|
_LOGGER.debug("Remote file has not changed %s", url)
|
86
|
-
return
|
86
|
+
return path.read_bytes()
|
87
87
|
|
88
88
|
_LOGGER.debug(
|
89
89
|
"Remote file has changed, downloading from %s to %s",
|
@@ -102,4 +102,6 @@ def download_content(url: str, path: Path, timeout=NETWORK_TIMEOUT) -> None:
|
|
102
102
|
raise cv.Invalid(f"Could not download from {url}: {e}")
|
103
103
|
|
104
104
|
path.parent.mkdir(parents=True, exist_ok=True)
|
105
|
-
|
105
|
+
data = req.content
|
106
|
+
path.write_bytes(data)
|
107
|
+
return data
|