esphome 2024.10.2__py3-none-any.whl → 2024.11.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.
Files changed (239) hide show
  1. esphome/__main__.py +22 -4
  2. esphome/automation.py +29 -2
  3. esphome/components/animation/__init__.py +5 -8
  4. esphome/components/animation/animation.cpp +1 -1
  5. esphome/components/audio/__init__.py +9 -0
  6. esphome/components/audio/audio.h +21 -0
  7. esphome/components/axs15231/__init__.py +6 -0
  8. esphome/components/axs15231/touchscreen/__init__.py +36 -0
  9. esphome/components/axs15231/touchscreen/axs15231_touchscreen.cpp +64 -0
  10. esphome/components/axs15231/touchscreen/axs15231_touchscreen.h +27 -0
  11. esphome/components/bme68x_bsec2/__init__.py +1 -1
  12. esphome/components/bme68x_bsec2/bme68x_bsec2.cpp +50 -47
  13. esphome/components/bme68x_bsec2/bme68x_bsec2.h +0 -2
  14. esphome/components/bytebuffer/__init__.py +5 -0
  15. esphome/components/bytebuffer/bytebuffer.h +421 -0
  16. esphome/components/climate/__init__.py +14 -13
  17. esphome/components/datetime/__init__.py +3 -3
  18. esphome/components/debug/debug_esp32.cpp +16 -8
  19. esphome/components/dfplayer/dfplayer.cpp +132 -6
  20. esphome/components/dfplayer/dfplayer.h +19 -53
  21. esphome/components/display/display.cpp +142 -0
  22. esphome/components/display/display.h +7 -0
  23. esphome/components/es8311/__init__.py +0 -0
  24. esphome/components/es8311/audio_dac.py +70 -0
  25. esphome/components/es8311/es8311.cpp +227 -0
  26. esphome/components/es8311/es8311.h +135 -0
  27. esphome/components/es8311/es8311_const.h +195 -0
  28. esphome/components/esp32/boards.py +199 -1
  29. esphome/components/esp32/gpio.py +3 -1
  30. esphome/components/esp32_ble/const_esp32c6.h +7 -0
  31. esphome/components/esp32_ble_client/ble_client_base.h +1 -1
  32. esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp +3 -0
  33. esphome/components/esp32_ble_tracker/esp32_ble_tracker.h +2 -1
  34. esphome/components/esp32_rmt_led_strip/led_strip.cpp +2 -2
  35. esphome/components/esp32_rmt_led_strip/led_strip.h +2 -0
  36. esphome/components/esp32_rmt_led_strip/light.py +3 -1
  37. esphome/components/esp8266/gpio.py +7 -5
  38. esphome/components/ethernet/__init__.py +55 -1
  39. esphome/components/ethernet/ethernet_component.cpp +14 -1
  40. esphome/components/ethernet/ethernet_component.h +7 -1
  41. esphome/components/font/__init__.py +213 -108
  42. esphome/components/gp8403/output/__init__.py +1 -1
  43. esphome/components/host/gpio.py +6 -4
  44. esphome/components/http_request/__init__.py +12 -0
  45. esphome/components/http_request/http_request.h +65 -3
  46. esphome/components/http_request/http_request_arduino.cpp +4 -3
  47. esphome/components/http_request/http_request_idf.cpp +12 -14
  48. esphome/components/http_request/ota/ota_http_request.cpp +1 -1
  49. esphome/components/http_request/update/http_request_update.cpp +1 -1
  50. esphome/components/i2c_device/__init__.py +26 -0
  51. esphome/components/i2c_device/i2c_device.cpp +17 -0
  52. esphome/components/i2c_device/i2c_device.h +18 -0
  53. esphome/components/i2s_audio/__init__.py +1 -3
  54. esphome/components/i2s_audio/speaker/__init__.py +12 -4
  55. esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +426 -200
  56. esphome/components/i2s_audio/speaker/i2s_audio_speaker.h +92 -33
  57. esphome/components/ili9xxx/display.py +5 -1
  58. esphome/components/image/__init__.py +5 -8
  59. esphome/components/image/image.cpp +14 -14
  60. esphome/components/image/image.h +20 -24
  61. esphome/components/internal_temperature/internal_temperature.cpp +51 -2
  62. esphome/components/internal_temperature/internal_temperature.h +1 -0
  63. esphome/components/ld2420/ld2420.cpp +1 -1
  64. esphome/components/libretiny/gpio.py +4 -2
  65. esphome/components/light/__init__.py +32 -1
  66. esphome/components/light/automation.py +39 -32
  67. esphome/components/light/effects.py +36 -36
  68. esphome/components/light/light_state.cpp +6 -16
  69. esphome/components/light/light_state.h +34 -0
  70. esphome/components/light/types.py +3 -1
  71. esphome/components/logger/logger_esp32.cpp +15 -0
  72. esphome/components/lvgl/__init__.py +202 -95
  73. esphome/components/lvgl/automation.py +42 -40
  74. esphome/components/lvgl/binary_sensor/__init__.py +8 -15
  75. esphome/components/lvgl/defines.py +14 -8
  76. esphome/components/lvgl/encoders.py +11 -8
  77. esphome/components/lvgl/keypads.py +77 -0
  78. esphome/components/lvgl/light/__init__.py +6 -8
  79. esphome/components/lvgl/lv_validation.py +2 -4
  80. esphome/components/lvgl/lvcode.py +3 -9
  81. esphome/components/lvgl/lvgl_esphome.cpp +210 -89
  82. esphome/components/lvgl/lvgl_esphome.h +113 -30
  83. esphome/components/lvgl/lvgl_proxy.h +17 -0
  84. esphome/components/lvgl/number/__init__.py +10 -15
  85. esphome/components/lvgl/schemas.py +4 -2
  86. esphome/components/lvgl/select/__init__.py +12 -37
  87. esphome/components/lvgl/select/lvgl_select.h +27 -33
  88. esphome/components/lvgl/sensor/__init__.py +8 -14
  89. esphome/components/lvgl/styles.py +3 -4
  90. esphome/components/lvgl/switch/__init__.py +8 -13
  91. esphome/components/lvgl/text/__init__.py +5 -6
  92. esphome/components/lvgl/text_sensor/__init__.py +15 -15
  93. esphome/components/lvgl/touchscreens.py +2 -3
  94. esphome/components/lvgl/trigger.py +7 -9
  95. esphome/components/lvgl/types.py +9 -3
  96. esphome/components/lvgl/widgets/__init__.py +32 -21
  97. esphome/components/lvgl/widgets/animimg.py +4 -3
  98. esphome/components/lvgl/widgets/dropdown.py +22 -10
  99. esphome/components/lvgl/widgets/img.py +2 -0
  100. esphome/components/lvgl/widgets/msgbox.py +6 -5
  101. esphome/components/lvgl/widgets/obj.py +4 -2
  102. esphome/components/lvgl/widgets/page.py +3 -2
  103. esphome/components/lvgl/widgets/qrcode.py +54 -0
  104. esphome/components/lvgl/widgets/roller.py +21 -14
  105. esphome/components/lvgl/widgets/tileview.py +2 -1
  106. esphome/components/max17043/__init__.py +1 -0
  107. esphome/components/max17043/automation.h +20 -0
  108. esphome/components/max17043/max17043.cpp +98 -0
  109. esphome/components/max17043/max17043.h +29 -0
  110. esphome/components/max17043/sensor.py +77 -0
  111. esphome/components/media_player/__init__.py +11 -0
  112. esphome/components/media_player/automation.h +10 -0
  113. esphome/components/media_player/media_player.cpp +4 -0
  114. esphome/components/midea/air_conditioner.cpp +17 -1
  115. esphome/components/mlx90393/sensor.py +1 -1
  116. esphome/components/modbus/modbus.cpp +24 -12
  117. esphome/components/modbus_controller/__init__.py +31 -1
  118. esphome/components/modbus_controller/automation.h +16 -0
  119. esphome/components/modbus_controller/const.py +2 -0
  120. esphome/components/modbus_controller/modbus_controller.cpp +14 -2
  121. esphome/components/modbus_controller/modbus_controller.h +9 -0
  122. esphome/components/mopeka_pro_check/mopeka_pro_check.cpp +40 -21
  123. esphome/components/mopeka_pro_check/mopeka_pro_check.h +9 -2
  124. esphome/components/mopeka_pro_check/sensor.py +41 -0
  125. esphome/components/mqtt/__init__.py +36 -0
  126. esphome/components/mqtt/mqtt_client.cpp +27 -3
  127. esphome/components/mqtt/mqtt_client.h +27 -2
  128. esphome/components/mqtt/mqtt_climate.cpp +4 -2
  129. esphome/components/mqtt/mqtt_component.cpp +6 -0
  130. esphome/components/mqtt/mqtt_component.h +4 -0
  131. esphome/components/mqtt/mqtt_const.h +6 -0
  132. esphome/components/online_image/online_image.cpp +2 -8
  133. esphome/components/online_image/online_image.h +2 -6
  134. esphome/components/opentherm/__init__.py +35 -9
  135. esphome/components/opentherm/binary_sensor/__init__.py +33 -0
  136. esphome/components/opentherm/const.py +11 -0
  137. esphome/components/opentherm/generate.py +142 -0
  138. esphome/components/opentherm/hub.cpp +130 -24
  139. esphome/components/opentherm/hub.h +62 -9
  140. esphome/components/opentherm/input.h +18 -0
  141. esphome/components/opentherm/input.py +51 -0
  142. esphome/components/opentherm/number/__init__.py +74 -0
  143. esphome/components/opentherm/number/number.cpp +40 -0
  144. esphome/components/opentherm/number/number.h +31 -0
  145. esphome/components/opentherm/opentherm.cpp +30 -0
  146. esphome/components/opentherm/opentherm.h +34 -2
  147. esphome/components/opentherm/opentherm_macros.h +151 -0
  148. esphome/components/opentherm/output/__init__.py +47 -0
  149. esphome/components/opentherm/output/output.cpp +18 -0
  150. esphome/components/opentherm/output/output.h +33 -0
  151. esphome/components/opentherm/schema.py +814 -0
  152. esphome/components/opentherm/sensor/__init__.py +51 -0
  153. esphome/components/opentherm/switch/__init__.py +43 -0
  154. esphome/components/opentherm/switch/switch.cpp +28 -0
  155. esphome/components/opentherm/switch/switch.h +20 -0
  156. esphome/components/opentherm/validate.py +31 -0
  157. esphome/components/pcd8544/display.py +8 -4
  158. esphome/components/prometheus/prometheus_handler.cpp +176 -14
  159. esphome/components/prometheus/prometheus_handler.h +25 -7
  160. esphome/components/qspi_amoled/display.py +1 -141
  161. esphome/components/qspi_dbi/display.py +185 -0
  162. esphome/components/qspi_dbi/models.py +64 -0
  163. esphome/components/{qspi_amoled/qspi_amoled.cpp → qspi_dbi/qspi_dbi.cpp} +95 -46
  164. esphome/components/{qspi_amoled/qspi_amoled.h → qspi_dbi/qspi_dbi.h} +26 -15
  165. esphome/components/rp2040/__init__.py +6 -3
  166. esphome/components/rp2040/gpio.py +5 -3
  167. esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp +20 -0
  168. esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.h +3 -2
  169. esphome/components/rtttl/rtttl.cpp +4 -1
  170. esphome/components/rtttl/rtttl.h +1 -0
  171. esphome/components/sdl/sdl_esphome.cpp +22 -5
  172. esphome/components/sdl/sdl_esphome.h +1 -0
  173. esphome/components/sdm_meter/sdm_meter.cpp +1 -1
  174. esphome/components/sensor/__init__.py +18 -8
  175. esphome/components/sensor/filter.cpp +19 -18
  176. esphome/components/sensor/filter.h +9 -10
  177. esphome/components/sgp4x/sgp4x.cpp +40 -74
  178. esphome/components/sgp4x/sgp4x.h +5 -3
  179. esphome/components/speaker/__init__.py +51 -5
  180. esphome/components/speaker/automation.h +25 -0
  181. esphome/components/speaker/speaker.h +72 -1
  182. esphome/components/spi/__init__.py +15 -14
  183. esphome/components/spi_device/__init__.py +4 -15
  184. esphome/components/ssd1306_spi/display.py +6 -2
  185. esphome/components/ssd1322_spi/display.py +6 -2
  186. esphome/components/ssd1325_spi/display.py +6 -2
  187. esphome/components/ssd1327_spi/display.py +6 -2
  188. esphome/components/ssd1331_spi/display.py +6 -2
  189. esphome/components/ssd1351_spi/display.py +6 -2
  190. esphome/components/st7567_spi/display.py +6 -2
  191. esphome/components/st7701s/display.py +5 -1
  192. esphome/components/st7735/display.py +10 -5
  193. esphome/components/st7789v/display.py +12 -7
  194. esphome/components/statsd/statsd.cpp +2 -0
  195. esphome/components/statsd/statsd.h +2 -0
  196. esphome/components/sun/sun.h +3 -0
  197. esphome/components/tc74/__init__.py +1 -0
  198. esphome/components/tc74/sensor.py +32 -0
  199. esphome/components/tc74/tc74.cpp +68 -0
  200. esphome/components/tc74/tc74.h +28 -0
  201. esphome/components/touchscreen/__init__.py +41 -50
  202. esphome/components/touchscreen/touchscreen.h +4 -8
  203. esphome/components/tuya/fan/tuya_fan.cpp +1 -1
  204. esphome/components/udp/udp_component.cpp +6 -3
  205. esphome/components/udp/udp_component.h +4 -2
  206. esphome/components/waveshare_epaper/display.py +6 -2
  207. esphome/components/web_server/web_server.cpp +22 -0
  208. esphome/components/web_server/web_server.h +3 -0
  209. esphome/components/weikai/weikai.h +2 -2
  210. esphome/components/wifi/wifi_component.cpp +2 -2
  211. esphome/components/wifi/wifi_component_esp32_arduino.cpp +4 -4
  212. esphome/components/wifi/wifi_component_esp8266.cpp +4 -4
  213. esphome/components/wifi/wifi_component_esp_idf.cpp +2 -2
  214. esphome/components/xpt2046/touchscreen/__init__.py +7 -32
  215. esphome/config_validation.py +3 -1
  216. esphome/const.py +9 -2
  217. esphome/core/defines.h +8 -2
  218. esphome/core/helpers.cpp +32 -17
  219. esphome/core/helpers.h +32 -16
  220. esphome/core/ring_buffer.cpp +2 -2
  221. esphome/core/ring_buffer.h +2 -2
  222. esphome/dashboard/core.py +25 -0
  223. esphome/dashboard/status/mdns.py +3 -4
  224. esphome/dashboard/web_server.py +54 -19
  225. esphome/espota2.py +36 -35
  226. esphome/helpers.py +68 -16
  227. esphome/mqtt.py +9 -2
  228. esphome/storage_json.py +4 -0
  229. esphome/writer.py +7 -18
  230. esphome/zeroconf.py +8 -6
  231. {esphome-2024.10.2.dist-info → esphome-2024.11.0.dist-info}/METADATA +7 -5
  232. {esphome-2024.10.2.dist-info → esphome-2024.11.0.dist-info}/RECORD +237 -191
  233. esphome/core/bytebuffer.cpp +0 -167
  234. esphome/core/bytebuffer.h +0 -144
  235. /esphome/components/{qspi_amoled → qspi_dbi}/__init__.py +0 -0
  236. {esphome-2024.10.2.dist-info → esphome-2024.11.0.dist-info}/LICENSE +0 -0
  237. {esphome-2024.10.2.dist-info → esphome-2024.11.0.dist-info}/WHEEL +0 -0
  238. {esphome-2024.10.2.dist-info → esphome-2024.11.0.dist-info}/entry_points.txt +0 -0
  239. {esphome-2024.10.2.dist-info → esphome-2024.11.0.dist-info}/top_level.txt +0 -0
@@ -1,167 +0,0 @@
1
- #include "bytebuffer.h"
2
- #include <cassert>
3
- #include "esphome/core/helpers.h"
4
-
5
- #include <list>
6
- #include <vector>
7
-
8
- namespace esphome {
9
-
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;
16
- }
17
-
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;
43
- }
44
-
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
- }
65
-
66
- void ByteBuffer::set_limit(size_t limit) {
67
- assert(limit <= this->get_capacity());
68
- this->limit_ = limit;
69
- }
70
- void ByteBuffer::set_position(size_t position) {
71
- assert(position <= this->get_limit());
72
- this->position_ = position;
73
- }
74
- void ByteBuffer::clear() {
75
- this->limit_ = this->get_capacity();
76
- this->position_ = 0;
77
- }
78
- void ByteBuffer::flip() {
79
- this->limit_ = this->position_;
80
- this->position_ = 0;
81
- }
82
-
83
- /// Getters
84
- uint8_t ByteBuffer::get_uint8() {
85
- assert(this->get_remaining() >= 1);
86
- return this->data_[this->position_++];
87
- }
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
- }
98
- } else {
99
- while (length-- != 0) {
100
- value <<= 8;
101
- value |= this->data_[this->position_++];
102
- }
103
- }
104
- return value;
105
- }
106
-
107
- uint32_t ByteBuffer::get_int24() {
108
- auto value = this->get_uint24();
109
- uint32_t mask = (~static_cast<uint32_t>(0)) << 23;
110
- if ((value & mask) != 0)
111
- value |= mask;
112
- return value;
113
- }
114
- float ByteBuffer::get_float() {
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};
128
- }
129
-
130
- /// Putters
131
- void ByteBuffer::put_uint8(uint8_t value) {
132
- assert(this->get_remaining() >= 1);
133
- this->data_[this->position_++] = value;
134
- }
135
-
136
- void ByteBuffer::put_uint(uint64_t value, size_t length) {
137
- assert(this->get_remaining() >= length);
138
- if (this->endianness_ == LITTLE) {
139
- while (length-- != 0) {
140
- this->data_[this->position_++] = static_cast<uint8_t>(value);
141
- value >>= 8;
142
- }
143
- } else {
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
- }
150
- }
151
- }
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));
156
- }
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));
161
- }
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();
166
- }
167
- } // namespace esphome
esphome/core/bytebuffer.h DELETED
@@ -1,144 +0,0 @@
1
- #pragma once
2
-
3
- #include <utility>
4
- #include <vector>
5
- #include <cinttypes>
6
- #include <cstddef>
7
-
8
- namespace esphome {
9
-
10
- enum Endian { LITTLE, BIG };
11
-
12
- /**
13
- * A class modelled on the Java ByteBuffer class. It wraps a vector of bytes and permits putting and getting
14
- * items of various sizes, with an automatically incremented position.
15
- *
16
- * There are three variables maintained pointing into the buffer:
17
- *
18
- * capacity: the maximum amount of data that can be stored - set on construction and cannot be changed
19
- * limit: the limit of the data currently available to get or put
20
- * position: the current insert or extract position
21
- *
22
- * 0 <= position <= limit <= capacity
23
- *
24
- * In addition a mark can be set to the current position with mark(). A subsequent call to reset() will restore
25
- * the position to the mark.
26
- *
27
- * The buffer can be marked to be little-endian (default) or big-endian. All subsequent operations will use that order.
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
- *
32
- */
33
- class ByteBuffer {
34
- public:
35
- // Default constructor (compatibility with TEMPLATABLE_VALUE)
36
- ByteBuffer() : ByteBuffer(std::vector<uint8_t>()) {}
37
- /**
38
- * Create a new Bytebuffer with the given capacity
39
- */
40
- ByteBuffer(size_t capacity, Endian endianness = LITTLE)
41
- : data_(std::vector<uint8_t>(capacity)), endianness_(endianness), limit_(capacity){};
42
- /**
43
- * Wrap an existing vector in a ByteBufffer
44
- */
45
- static ByteBuffer wrap(std::vector<uint8_t> const &data, Endian endianness = LITTLE);
46
- /**
47
- * Wrap an existing array in a ByteBuffer. Note that this will create a copy of the data.
48
- */
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)); }
68
-
69
- // Get an integral value from the buffer, increment position by length
70
- uint64_t get_uint(size_t length);
71
- // Get one byte from the buffer, increment position by 1
72
- uint8_t get_uint8();
73
- // Get a 16 bit unsigned value, increment by 2
74
- uint16_t get_uint16() { return static_cast<uint16_t>(this->get_uint(sizeof(uint16_t))); };
75
- // Get a 24 bit unsigned value, increment by 3
76
- uint32_t get_uint24() { return static_cast<uint32_t>(this->get_uint(3)); };
77
- // Get a 32 bit unsigned value, increment by 4
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))); }
84
- uint32_t get_int24();
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))); }
87
- // Get a float value, increment by 4
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);
95
-
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);
99
- void put_uint8(uint8_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
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);
115
-
116
- inline size_t get_capacity() const { return this->data_.size(); }
117
- inline size_t get_position() const { return this->position_; }
118
- inline size_t get_limit() const { return this->limit_; }
119
- inline size_t get_remaining() const { return this->get_limit() - this->get_position(); }
120
- inline Endian get_endianness() const { return this->endianness_; }
121
- inline void mark() { this->mark_ = this->position_; }
122
- inline void big_endian() { this->endianness_ = BIG; }
123
- inline void little_endian() { this->endianness_ = LITTLE; }
124
- void set_limit(size_t limit);
125
- void set_position(size_t position);
126
- // set position to 0, limit to capacity.
127
- void clear();
128
- // set limit to current position, postition to zero. Used when swapping from write to read operations.
129
- void flip();
130
- // retrieve a pointer to the underlying data.
131
- std::vector<uint8_t> get_data() { return this->data_; };
132
- void rewind() { this->position_ = 0; }
133
- void reset() { this->position_ = this->mark_; }
134
-
135
- protected:
136
- ByteBuffer(std::vector<uint8_t> const &data) : data_(data), limit_(data.size()) {}
137
- std::vector<uint8_t> data_;
138
- Endian endianness_{LITTLE};
139
- size_t position_{0};
140
- size_t mark_{0};
141
- size_t limit_{0};
142
- };
143
-
144
- } // namespace esphome