esphome 2024.12.3__py3-none-any.whl → 2025.2.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 (355) hide show
  1. esphome/__main__.py +16 -3
  2. esphome/components/adc/__init__.py +17 -11
  3. esphome/components/adc/adc_sensor.h +17 -0
  4. esphome/components/adc/adc_sensor_common.cpp +55 -0
  5. esphome/components/adc/adc_sensor_esp32.cpp +8 -5
  6. esphome/components/adc/adc_sensor_esp8266.cpp +10 -6
  7. esphome/components/adc/adc_sensor_libretiny.cpp +11 -6
  8. esphome/components/adc/adc_sensor_rp2040.cpp +13 -10
  9. esphome/components/adc/sensor.py +9 -3
  10. esphome/components/ads1115/ads1115.cpp +56 -7
  11. esphome/components/ads1115/ads1115.h +13 -1
  12. esphome/components/ads1115/sensor/__init__.py +16 -0
  13. esphome/components/ads1115/sensor/ads1115_sensor.cpp +2 -1
  14. esphome/components/ads1115/sensor/ads1115_sensor.h +2 -0
  15. esphome/components/animation/__init__.py +23 -261
  16. esphome/components/animation/animation.cpp +2 -2
  17. esphome/components/animation/animation.h +2 -1
  18. esphome/components/api/api_pb2.cpp +14 -0
  19. esphome/components/api/api_pb2.h +1 -0
  20. esphome/components/audio/__init__.py +112 -0
  21. esphome/components/audio/audio.cpp +67 -0
  22. esphome/components/audio/audio.h +125 -7
  23. esphome/components/audio/audio_decoder.cpp +361 -0
  24. esphome/components/audio/audio_decoder.h +135 -0
  25. esphome/components/audio/audio_reader.cpp +308 -0
  26. esphome/components/audio/audio_reader.h +85 -0
  27. esphome/components/audio/audio_resampler.cpp +159 -0
  28. esphome/components/audio/audio_resampler.h +101 -0
  29. esphome/components/audio/audio_transfer_buffer.cpp +165 -0
  30. esphome/components/audio/audio_transfer_buffer.h +139 -0
  31. esphome/components/audio_adc/__init__.py +41 -0
  32. esphome/components/audio_adc/audio_adc.h +17 -0
  33. esphome/components/audio_adc/automation.h +23 -0
  34. esphome/components/bk72xx/__init__.py +1 -0
  35. esphome/components/ble_client/ble_client.cpp +1 -2
  36. esphome/components/ble_client/sensor/__init__.py +1 -1
  37. esphome/components/ble_client/text_sensor/__init__.py +1 -1
  38. esphome/components/bluetooth_proxy/bluetooth_connection.cpp +5 -0
  39. esphome/components/bluetooth_proxy/bluetooth_connection.h +1 -0
  40. esphome/components/bluetooth_proxy/bluetooth_proxy.cpp +5 -0
  41. esphome/components/ch422g/ch422g.h +2 -0
  42. esphome/components/climate/__init__.py +1 -1
  43. esphome/components/climate_ir/climate_ir.cpp +2 -1
  44. esphome/components/coolix/coolix.cpp +2 -1
  45. esphome/components/custom/__init__.py +0 -3
  46. esphome/components/custom/binary_sensor/__init__.py +2 -28
  47. esphome/components/custom/climate/__init__.py +2 -27
  48. esphome/components/custom/cover/__init__.py +2 -27
  49. esphome/components/custom/light/__init__.py +2 -27
  50. esphome/components/custom/output/__init__.py +2 -58
  51. esphome/components/custom/sensor/__init__.py +2 -24
  52. esphome/components/custom/switch/__init__.py +2 -24
  53. esphome/components/custom/text_sensor/__init__.py +2 -29
  54. esphome/components/custom_component/__init__.py +3 -27
  55. esphome/components/daly_bms/daly_bms.cpp +6 -0
  56. esphome/components/daly_bms/daly_bms.h +2 -0
  57. esphome/components/daly_bms/sensor.py +6 -0
  58. esphome/components/debug/debug_component.cpp +4 -0
  59. esphome/components/debug/debug_component.h +14 -0
  60. esphome/components/debug/debug_esp32.cpp +154 -74
  61. esphome/components/dfplayer/dfplayer.cpp +15 -2
  62. esphome/components/dfrobot_sen0395/dfrobot_sen0395.cpp +2 -1
  63. esphome/components/dht/dht.cpp +2 -1
  64. esphome/components/display/__init__.py +18 -5
  65. esphome/components/display/display.cpp +2 -1
  66. esphome/components/display/rect.cpp +2 -1
  67. esphome/components/es7210/__init__.py +0 -0
  68. esphome/components/es7210/audio_adc.py +51 -0
  69. esphome/components/es7210/es7210.cpp +228 -0
  70. esphome/components/es7210/es7210.h +62 -0
  71. esphome/components/es7210/es7210_const.h +129 -0
  72. esphome/components/es7243e/__init__.py +0 -0
  73. esphome/components/es7243e/audio_adc.py +34 -0
  74. esphome/components/es7243e/es7243e.cpp +125 -0
  75. esphome/components/es7243e/es7243e.h +37 -0
  76. esphome/components/es7243e/es7243e_const.h +54 -0
  77. esphome/components/es8156/__init__.py +0 -0
  78. esphome/components/es8156/audio_dac.py +27 -0
  79. esphome/components/es8156/es8156.cpp +87 -0
  80. esphome/components/es8156/es8156.h +51 -0
  81. esphome/components/es8156/es8156_const.h +68 -0
  82. esphome/components/es8311/audio_dac.py +1 -2
  83. esphome/components/esp32/__init__.py +1 -0
  84. esphome/components/esp32/core.cpp +5 -1
  85. esphome/components/esp32/gpio.h +2 -0
  86. esphome/components/esp32_ble/__init__.py +39 -0
  87. esphome/components/esp32_ble/queue.h +4 -4
  88. esphome/components/esp32_ble_client/ble_client_base.cpp +46 -0
  89. esphome/components/esp32_ble_client/ble_client_base.h +2 -0
  90. esphome/components/esp32_ble_server/__init__.py +582 -12
  91. esphome/components/esp32_ble_server/ble_characteristic.cpp +48 -60
  92. esphome/components/esp32_ble_server/ble_characteristic.h +24 -17
  93. esphome/components/esp32_ble_server/ble_descriptor.cpp +21 -9
  94. esphome/components/esp32_ble_server/ble_descriptor.h +17 -6
  95. esphome/components/esp32_ble_server/ble_server.cpp +62 -67
  96. esphome/components/esp32_ble_server/ble_server.h +28 -32
  97. esphome/components/esp32_ble_server/ble_server_automations.cpp +77 -0
  98. esphome/components/esp32_ble_server/ble_server_automations.h +115 -0
  99. esphome/components/esp32_ble_server/ble_service.cpp +17 -15
  100. esphome/components/esp32_ble_server/ble_service.h +10 -14
  101. esphome/components/esp32_ble_tracker/__init__.py +6 -39
  102. esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp +33 -10
  103. esphome/components/esp32_ble_tracker/esp32_ble_tracker.h +8 -4
  104. esphome/components/esp32_improv/__init__.py +2 -8
  105. esphome/components/esp32_improv/esp32_improv_component.cpp +21 -20
  106. esphome/components/esp32_improv/esp32_improv_component.h +3 -4
  107. esphome/components/esp32_rmt/__init__.py +28 -3
  108. esphome/components/esp32_rmt_led_strip/led_strip.cpp +73 -6
  109. esphome/components/esp32_rmt_led_strip/led_strip.h +21 -3
  110. esphome/components/esp32_rmt_led_strip/light.py +72 -7
  111. esphome/components/esp32_touch/esp32_touch.cpp +5 -0
  112. esphome/components/esp8266/__init__.py +1 -0
  113. esphome/components/esp8266/gpio.h +1 -0
  114. esphome/components/ethernet/__init__.py +10 -10
  115. esphome/components/event/event.cpp +4 -2
  116. esphome/components/event/event.h +2 -0
  117. esphome/components/event_emitter/__init__.py +5 -0
  118. esphome/components/event_emitter/event_emitter.cpp +14 -0
  119. esphome/components/event_emitter/event_emitter.h +63 -0
  120. esphome/components/gcja5/gcja5.cpp +2 -1
  121. esphome/components/haier/haier_base.cpp +2 -1
  122. esphome/components/haier/hon_climate.cpp +2 -1
  123. esphome/components/heatpumpir/heatpumpir.cpp +2 -1
  124. esphome/components/host/__init__.py +1 -0
  125. esphome/components/host/gpio.h +1 -0
  126. esphome/components/http_request/http_request.h +2 -2
  127. esphome/components/http_request/http_request_arduino.cpp +1 -1
  128. esphome/components/http_request/http_request_idf.cpp +1 -1
  129. esphome/components/i2c/i2c_bus_esp_idf.cpp +4 -0
  130. esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp +7 -5
  131. esphome/components/i2s_audio/speaker/__init__.py +53 -6
  132. esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +92 -46
  133. esphome/components/i2s_audio/speaker/i2s_audio_speaker.h +8 -0
  134. esphome/components/ili9xxx/display.py +29 -11
  135. esphome/components/ili9xxx/ili9xxx_display.cpp +2 -5
  136. esphome/components/ili9xxx/ili9xxx_display.h +2 -1
  137. esphome/components/image/__init__.py +443 -255
  138. esphome/components/image/image.cpp +115 -61
  139. esphome/components/image/image.h +15 -24
  140. esphome/components/json/json_util.cpp +8 -34
  141. esphome/components/libretiny/__init__.py +1 -0
  142. esphome/components/libretiny/gpio_arduino.h +1 -0
  143. esphome/components/light/light_color_values.h +1 -1
  144. esphome/components/logger/__init__.py +43 -7
  145. esphome/components/logger/logger.cpp +16 -11
  146. esphome/components/logger/logger.h +11 -7
  147. esphome/components/logger/select/__init__.py +29 -0
  148. esphome/components/logger/select/logger_level_select.cpp +27 -0
  149. esphome/components/logger/select/logger_level_select.h +15 -0
  150. esphome/components/lvgl/__init__.py +96 -73
  151. esphome/components/lvgl/automation.py +39 -7
  152. esphome/components/lvgl/defines.py +8 -2
  153. esphome/components/lvgl/lvgl_esphome.cpp +8 -15
  154. esphome/components/lvgl/lvgl_esphome.h +20 -5
  155. esphome/components/lvgl/schemas.py +25 -14
  156. esphome/components/lvgl/trigger.py +27 -3
  157. esphome/components/lvgl/widgets/dropdown.py +1 -1
  158. esphome/components/lvgl/widgets/keyboard.py +8 -1
  159. esphome/components/lvgl/widgets/meter.py +2 -1
  160. esphome/components/lvgl/widgets/msgbox.py +1 -1
  161. esphome/components/lvgl/widgets/obj.py +1 -12
  162. esphome/components/lvgl/widgets/page.py +37 -2
  163. esphome/components/lvgl/widgets/tabview.py +1 -1
  164. esphome/components/max6956/max6956.h +2 -0
  165. esphome/components/mcp23016/mcp23016.h +2 -0
  166. esphome/components/mcp23xxx_base/mcp23xxx_base.h +2 -0
  167. esphome/components/mdns/__init__.py +1 -1
  168. esphome/components/media_player/__init__.py +37 -8
  169. esphome/components/media_player/automation.h +11 -2
  170. esphome/components/media_player/media_player.cpp +8 -0
  171. esphome/components/media_player/media_player.h +8 -4
  172. esphome/components/micronova/switch/micronova_switch.cpp +4 -2
  173. esphome/components/midea/ac_automations.h +3 -1
  174. esphome/components/midea/air_conditioner.cpp +7 -5
  175. esphome/components/midea/air_conditioner.h +1 -1
  176. esphome/components/midea/climate.py +4 -2
  177. esphome/components/midea/ir_transmitter.h +36 -5
  178. esphome/components/mixer/__init__.py +0 -0
  179. esphome/components/mixer/speaker/__init__.py +172 -0
  180. esphome/components/mixer/speaker/automation.h +19 -0
  181. esphome/components/mixer/speaker/mixer_speaker.cpp +624 -0
  182. esphome/components/mixer/speaker/mixer_speaker.h +207 -0
  183. esphome/components/mpr121/mpr121.h +2 -0
  184. esphome/components/mqtt/__init__.py +1 -1
  185. esphome/components/mqtt/mqtt_client.cpp +7 -1
  186. esphome/components/mqtt/mqtt_client.h +1 -1
  187. esphome/components/mqtt/mqtt_climate.cpp +2 -2
  188. esphome/components/network/ip_address.h +2 -0
  189. esphome/components/nextion/automation.h +17 -0
  190. esphome/components/nextion/display.py +42 -17
  191. esphome/components/nextion/nextion.cpp +4 -10
  192. esphome/components/nextion/nextion.h +89 -82
  193. esphome/components/nextion/nextion_commands.cpp +10 -10
  194. esphome/components/ntc/sensor.py +2 -4
  195. esphome/components/online_image/__init__.py +98 -46
  196. esphome/components/online_image/bmp_image.cpp +101 -0
  197. esphome/components/online_image/bmp_image.h +40 -0
  198. esphome/components/online_image/image_decoder.cpp +28 -2
  199. esphome/components/online_image/image_decoder.h +24 -15
  200. esphome/components/online_image/jpeg_image.cpp +90 -0
  201. esphome/components/online_image/jpeg_image.h +34 -0
  202. esphome/components/online_image/online_image.cpp +112 -53
  203. esphome/components/online_image/online_image.h +24 -7
  204. esphome/components/online_image/png_image.cpp +7 -3
  205. esphome/components/online_image/png_image.h +2 -1
  206. esphome/components/opentherm/__init__.py +73 -7
  207. esphome/components/opentherm/automation.h +25 -0
  208. esphome/components/opentherm/const.py +1 -0
  209. esphome/components/opentherm/generate.py +39 -6
  210. esphome/components/opentherm/hub.cpp +117 -79
  211. esphome/components/opentherm/hub.h +31 -15
  212. esphome/components/opentherm/opentherm.cpp +47 -23
  213. esphome/components/opentherm/opentherm.h +27 -6
  214. esphome/components/opentherm/opentherm_macros.h +11 -0
  215. esphome/components/opentherm/schema.py +78 -1
  216. esphome/components/opentherm/validate.py +7 -2
  217. esphome/components/pca6416a/pca6416a.h +2 -0
  218. esphome/components/pca9554/pca9554.h +2 -0
  219. esphome/components/pcf8574/pcf8574.h +2 -0
  220. esphome/components/preferences/__init__.py +2 -4
  221. esphome/components/preferences/syncer.h +10 -3
  222. esphome/components/prometheus/prometheus_handler.cpp +313 -0
  223. esphome/components/prometheus/prometheus_handler.h +48 -7
  224. esphome/components/psram/psram.cpp +8 -1
  225. esphome/components/pulse_counter/pulse_counter_sensor.cpp +14 -9
  226. esphome/components/pulse_counter/pulse_counter_sensor.h +4 -4
  227. esphome/components/pulse_meter/pulse_meter_sensor.cpp +2 -0
  228. esphome/components/qspi_dbi/__init__.py +3 -0
  229. esphome/components/qspi_dbi/display.py +74 -47
  230. esphome/components/qspi_dbi/models.py +245 -2
  231. esphome/components/qspi_dbi/qspi_dbi.cpp +9 -16
  232. esphome/components/qspi_dbi/qspi_dbi.h +2 -2
  233. esphome/components/remote_base/__init__.py +77 -25
  234. esphome/components/remote_base/remote_base.cpp +1 -1
  235. esphome/components/remote_base/remote_base.h +20 -2
  236. esphome/components/remote_base/toto_protocol.cpp +100 -0
  237. esphome/components/remote_base/toto_protocol.h +45 -0
  238. esphome/components/remote_receiver/__init__.py +55 -10
  239. esphome/components/remote_receiver/remote_receiver.h +36 -3
  240. esphome/components/remote_receiver/remote_receiver_esp32.cpp +145 -6
  241. esphome/components/remote_transmitter/__init__.py +62 -4
  242. esphome/components/remote_transmitter/remote_transmitter.h +21 -2
  243. esphome/components/remote_transmitter/remote_transmitter_esp32.cpp +140 -4
  244. esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp +3 -3
  245. esphome/components/remote_transmitter/remote_transmitter_libretiny.cpp +3 -3
  246. esphome/components/resampler/__init__.py +0 -0
  247. esphome/components/resampler/speaker/__init__.py +103 -0
  248. esphome/components/resampler/speaker/resampler_speaker.cpp +318 -0
  249. esphome/components/resampler/speaker/resampler_speaker.h +107 -0
  250. esphome/components/resistance/resistance_sensor.h +2 -3
  251. esphome/components/resistance/sensor.py +2 -9
  252. esphome/components/rotary_encoder/rotary_encoder.cpp +8 -4
  253. esphome/components/rp2040/__init__.py +1 -0
  254. esphome/components/rp2040/gpio.h +1 -0
  255. esphome/components/rtl87xx/__init__.py +2 -0
  256. esphome/components/sdl/binary_sensor.py +270 -0
  257. esphome/components/sdl/sdl_esphome.cpp +16 -0
  258. esphome/components/sdl/sdl_esphome.h +9 -0
  259. esphome/components/seeed_mr60bha2/binary_sensor.py +25 -0
  260. esphome/components/seeed_mr60bha2/seeed_mr60bha2.cpp +26 -2
  261. esphome/components/seeed_mr60bha2/seeed_mr60bha2.h +9 -20
  262. esphome/components/seeed_mr60bha2/sensor.py +9 -1
  263. esphome/components/sn74hc165/sn74hc165.h +3 -0
  264. esphome/components/sn74hc595/sn74hc595.h +3 -0
  265. esphome/components/speaker/__init__.py +5 -4
  266. esphome/components/speaker/media_player/__init__.py +458 -0
  267. esphome/components/speaker/media_player/audio_pipeline.cpp +568 -0
  268. esphome/components/speaker/media_player/audio_pipeline.h +159 -0
  269. esphome/components/speaker/media_player/automation.h +26 -0
  270. esphome/components/speaker/media_player/speaker_media_player.cpp +577 -0
  271. esphome/components/speaker/media_player/speaker_media_player.h +160 -0
  272. esphome/components/speaker/speaker.h +20 -0
  273. esphome/components/spi/__init__.py +1 -5
  274. esphome/components/spi/spi.cpp +7 -1
  275. esphome/components/spi/spi.h +21 -2
  276. esphome/components/spi_led_strip/light.py +3 -5
  277. esphome/components/spi_led_strip/spi_led_strip.cpp +67 -0
  278. esphome/components/spi_led_strip/spi_led_strip.h +8 -60
  279. esphome/components/sprinkler/sprinkler.cpp +3 -1
  280. esphome/components/sx1509/sx1509_gpio_pin.h +2 -0
  281. esphome/components/tca9555/tca9555.h +2 -0
  282. esphome/components/toshiba/toshiba.cpp +2 -1
  283. esphome/components/tuya/light/tuya_light.cpp +4 -2
  284. esphome/components/uart/uart_component_esp32_arduino.cpp +2 -2
  285. esphome/components/uart/uart_component_esp_idf.cpp +2 -2
  286. esphome/components/udp/__init__.py +8 -2
  287. esphome/components/udp/udp_component.cpp +25 -56
  288. esphome/components/udp/udp_component.h +3 -0
  289. esphome/components/uponor_smatrix/sensor/__init__.py +14 -4
  290. esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.cpp +5 -0
  291. esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.h +1 -0
  292. esphome/components/uptime/text_sensor/__init__.py +19 -0
  293. esphome/components/uptime/text_sensor/uptime_text_sensor.cpp +63 -0
  294. esphome/components/uptime/text_sensor/uptime_text_sensor.h +25 -0
  295. esphome/components/voice_assistant/voice_assistant.cpp +24 -14
  296. esphome/components/voice_assistant/voice_assistant.h +8 -0
  297. esphome/components/waveshare_epaper/display.py +22 -1
  298. esphome/components/waveshare_epaper/waveshare_213v3.cpp +9 -3
  299. esphome/components/waveshare_epaper/waveshare_epaper.cpp +1155 -44
  300. esphome/components/waveshare_epaper/waveshare_epaper.h +208 -7
  301. esphome/components/web_server/web_server.cpp +28 -6
  302. esphome/components/weikai/weikai.h +2 -0
  303. esphome/components/wifi/__init__.py +6 -6
  304. esphome/components/wifi/wifi_component.cpp +1 -1
  305. esphome/components/wifi/wifi_component_esp32_arduino.cpp +30 -1
  306. esphome/components/wireguard/__init__.py +2 -2
  307. esphome/components/xl9535/xl9535.h +2 -0
  308. esphome/components/xxtea/__init__.py +3 -0
  309. esphome/components/xxtea/xxtea.cpp +46 -0
  310. esphome/components/xxtea/xxtea.h +26 -0
  311. esphome/components/yashima/yashima.cpp +2 -1
  312. esphome/config.py +9 -5
  313. esphome/config_validation.py +55 -17
  314. esphome/const.py +7 -10
  315. esphome/core/__init__.py +6 -13
  316. esphome/core/base_automation.h +1 -0
  317. esphome/core/config.py +57 -72
  318. esphome/core/defines.h +9 -1
  319. esphome/core/gpio.h +7 -0
  320. esphome/core/helpers.cpp +19 -15
  321. esphome/core/helpers.h +57 -8
  322. esphome/core/log.h +9 -7
  323. esphome/cpp_generator.py +2 -2
  324. esphome/espota2.py +3 -2
  325. esphome/loader.py +12 -4
  326. esphome/log.py +5 -7
  327. esphome/yaml_util.py +2 -2
  328. {esphome-2024.12.3.dist-info → esphome-2025.2.0b1.dist-info}/METADATA +12 -7
  329. {esphome-2024.12.3.dist-info → esphome-2025.2.0b1.dist-info}/RECORD +338 -289
  330. esphome/components/custom/binary_sensor/custom_binary_sensor.cpp +0 -16
  331. esphome/components/custom/binary_sensor/custom_binary_sensor.h +0 -26
  332. esphome/components/custom/climate/custom_climate.h +0 -22
  333. esphome/components/custom/cover/custom_cover.h +0 -21
  334. esphome/components/custom/light/custom_light_output.h +0 -24
  335. esphome/components/custom/output/custom_output.h +0 -37
  336. esphome/components/custom/sensor/custom_sensor.cpp +0 -16
  337. esphome/components/custom/sensor/custom_sensor.h +0 -24
  338. esphome/components/custom/switch/custom_switch.cpp +0 -16
  339. esphome/components/custom/switch/custom_switch.h +0 -24
  340. esphome/components/custom/text_sensor/custom_text_sensor.cpp +0 -16
  341. esphome/components/custom/text_sensor/custom_text_sensor.h +0 -26
  342. esphome/components/custom_component/custom_component.h +0 -28
  343. esphome/components/esp32_ble_server/ble_2901.cpp +0 -18
  344. esphome/components/esp32_ble_server/ble_2901.h +0 -19
  345. esphome/components/resistance_sampler/__init__.py +0 -6
  346. esphome/components/resistance_sampler/resistance_sampler.h +0 -10
  347. esphome/components/uptime/{sensor.py → sensor/__init__.py} +3 -3
  348. /esphome/components/uptime/{uptime_seconds_sensor.cpp → sensor/uptime_seconds_sensor.cpp} +0 -0
  349. /esphome/components/uptime/{uptime_seconds_sensor.h → sensor/uptime_seconds_sensor.h} +0 -0
  350. /esphome/components/uptime/{uptime_timestamp_sensor.cpp → sensor/uptime_timestamp_sensor.cpp} +0 -0
  351. /esphome/components/uptime/{uptime_timestamp_sensor.h → sensor/uptime_timestamp_sensor.h} +0 -0
  352. {esphome-2024.12.3.dist-info → esphome-2025.2.0b1.dist-info}/LICENSE +0 -0
  353. {esphome-2024.12.3.dist-info → esphome-2025.2.0b1.dist-info}/WHEEL +0 -0
  354. {esphome-2024.12.3.dist-info → esphome-2025.2.0b1.dist-info}/entry_points.txt +0 -0
  355. {esphome-2024.12.3.dist-info → esphome-2025.2.0b1.dist-info}/top_level.txt +0 -0
esphome/__main__.py CHANGED
@@ -758,6 +758,14 @@ def parse_args(argv):
758
758
  options_parser.add_argument(
759
759
  "-q", "--quiet", help="Disable all ESPHome logs.", action="store_true"
760
760
  )
761
+ options_parser.add_argument(
762
+ "-l",
763
+ "--log-level",
764
+ help="Set the log level.",
765
+ default=os.getenv("ESPHOME_LOG_LEVEL", "INFO"),
766
+ action="store",
767
+ choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
768
+ )
761
769
  options_parser.add_argument(
762
770
  "--dashboard", help=argparse.SUPPRESS, action="store_true"
763
771
  )
@@ -987,11 +995,16 @@ def run_esphome(argv):
987
995
  args = parse_args(argv)
988
996
  CORE.dashboard = args.dashboard
989
997
 
998
+ # Override log level if verbose is set
999
+ if args.verbose:
1000
+ args.log_level = "DEBUG"
1001
+ elif args.quiet:
1002
+ args.log_level = "CRITICAL"
1003
+
990
1004
  setup_log(
991
- args.verbose,
992
- args.quiet,
1005
+ log_level=args.log_level,
993
1006
  # Show timestamp for dashboard access logs
994
- args.command == "dashboard",
1007
+ include_timestamp=args.command == "dashboard",
995
1008
  )
996
1009
 
997
1010
  if args.command in PRE_CONFIG_ACTIONS:
@@ -1,11 +1,6 @@
1
- import esphome.codegen as cg
2
- import esphome.config_validation as cv
3
1
  from esphome import pins
4
- from esphome.const import CONF_ANALOG, CONF_INPUT, CONF_NUMBER
5
-
6
- from esphome.core import CORE
2
+ import esphome.codegen as cg
7
3
  from esphome.components.esp32 import get_esp32_variant
8
- from esphome.const import PLATFORM_ESP8266
9
4
  from esphome.components.esp32.const import (
10
5
  VARIANT_ESP32,
11
6
  VARIANT_ESP32C2,
@@ -15,6 +10,9 @@ from esphome.components.esp32.const import (
15
10
  VARIANT_ESP32S2,
16
11
  VARIANT_ESP32S3,
17
12
  )
13
+ import esphome.config_validation as cv
14
+ from esphome.const import CONF_ANALOG, CONF_INPUT, CONF_NUMBER, PLATFORM_ESP8266
15
+ from esphome.core import CORE
18
16
 
19
17
  CODEOWNERS = ["@esphome/core"]
20
18
 
@@ -38,6 +36,14 @@ ATTENUATION_MODES = {
38
36
  "auto": "auto",
39
37
  }
40
38
 
39
+ sampling_mode = adc_ns.enum("SamplingMode", is_class=True)
40
+
41
+ SAMPLING_MODES = {
42
+ "avg": sampling_mode.AVG,
43
+ "min": sampling_mode.MIN,
44
+ "max": sampling_mode.MAX,
45
+ }
46
+
41
47
  adc1_channel_t = cg.global_ns.enum("adc1_channel_t")
42
48
  adc2_channel_t = cg.global_ns.enum("adc2_channel_t")
43
49
 
@@ -102,11 +108,11 @@ ESP32_VARIANT_ADC1_PIN_TO_CHANNEL = {
102
108
  6: adc1_channel_t.ADC1_CHANNEL_6,
103
109
  },
104
110
  VARIANT_ESP32H2: {
105
- 0: adc1_channel_t.ADC1_CHANNEL_0,
106
- 1: adc1_channel_t.ADC1_CHANNEL_1,
107
- 2: adc1_channel_t.ADC1_CHANNEL_2,
108
- 3: adc1_channel_t.ADC1_CHANNEL_3,
109
- 4: adc1_channel_t.ADC1_CHANNEL_4,
111
+ 1: adc1_channel_t.ADC1_CHANNEL_0,
112
+ 2: adc1_channel_t.ADC1_CHANNEL_1,
113
+ 3: adc1_channel_t.ADC1_CHANNEL_2,
114
+ 4: adc1_channel_t.ADC1_CHANNEL_3,
115
+ 5: adc1_channel_t.ADC1_CHANNEL_4,
110
116
  },
111
117
  }
112
118
 
@@ -28,6 +28,21 @@ static const adc_atten_t ADC_ATTEN_DB_12_COMPAT = ADC_ATTEN_DB_11;
28
28
  #endif
29
29
  #endif // USE_ESP32
30
30
 
31
+ enum class SamplingMode : uint8_t { AVG = 0, MIN = 1, MAX = 2 };
32
+ const LogString *sampling_mode_to_str(SamplingMode mode);
33
+
34
+ class Aggregator {
35
+ public:
36
+ void add_sample(uint32_t value);
37
+ uint32_t aggregate();
38
+ Aggregator(SamplingMode mode);
39
+
40
+ protected:
41
+ SamplingMode mode_{SamplingMode::AVG};
42
+ uint32_t aggr_{0};
43
+ uint32_t samples_{0};
44
+ };
45
+
31
46
  class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage_sampler::VoltageSampler {
32
47
  public:
33
48
  #ifdef USE_ESP32
@@ -54,6 +69,7 @@ class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage
54
69
  void set_pin(InternalGPIOPin *pin) { this->pin_ = pin; }
55
70
  void set_output_raw(bool output_raw) { this->output_raw_ = output_raw; }
56
71
  void set_sample_count(uint8_t sample_count);
72
+ void set_sampling_mode(SamplingMode sampling_mode);
57
73
  float sample() override;
58
74
 
59
75
  #ifdef USE_ESP8266
@@ -68,6 +84,7 @@ class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage
68
84
  InternalGPIOPin *pin_;
69
85
  bool output_raw_{false};
70
86
  uint8_t sample_count_{1};
87
+ SamplingMode sampling_mode_{SamplingMode::AVG};
71
88
 
72
89
  #ifdef USE_RP2040
73
90
  bool is_temperature_{false};
@@ -6,6 +6,59 @@ namespace adc {
6
6
 
7
7
  static const char *const TAG = "adc.common";
8
8
 
9
+ const LogString *sampling_mode_to_str(SamplingMode mode) {
10
+ switch (mode) {
11
+ case SamplingMode::AVG:
12
+ return LOG_STR("average");
13
+ case SamplingMode::MIN:
14
+ return LOG_STR("minimum");
15
+ case SamplingMode::MAX:
16
+ return LOG_STR("maximum");
17
+ }
18
+ return LOG_STR("unknown");
19
+ }
20
+
21
+ Aggregator::Aggregator(SamplingMode mode) {
22
+ this->mode_ = mode;
23
+ // set to max uint if mode is "min"
24
+ if (mode == SamplingMode::MIN) {
25
+ this->aggr_ = UINT32_MAX;
26
+ }
27
+ }
28
+
29
+ void Aggregator::add_sample(uint32_t value) {
30
+ this->samples_ += 1;
31
+
32
+ switch (this->mode_) {
33
+ case SamplingMode::AVG:
34
+ this->aggr_ += value;
35
+ break;
36
+
37
+ case SamplingMode::MIN:
38
+ if (value < this->aggr_) {
39
+ this->aggr_ = value;
40
+ }
41
+ break;
42
+
43
+ case SamplingMode::MAX:
44
+ if (value > this->aggr_) {
45
+ this->aggr_ = value;
46
+ }
47
+ }
48
+ }
49
+
50
+ uint32_t Aggregator::aggregate() {
51
+ if (this->mode_ == SamplingMode::AVG) {
52
+ if (this->samples_ == 0) {
53
+ return this->aggr_;
54
+ }
55
+
56
+ return (this->aggr_ + (this->samples_ >> 1)) / this->samples_; // NOLINT(clang-analyzer-core.DivideZero)
57
+ }
58
+
59
+ return this->aggr_;
60
+ }
61
+
9
62
  void ADCSensor::update() {
10
63
  float value_v = this->sample();
11
64
  ESP_LOGV(TAG, "'%s': Got voltage=%.4fV", this->get_name().c_str(), value_v);
@@ -18,6 +71,8 @@ void ADCSensor::set_sample_count(uint8_t sample_count) {
18
71
  }
19
72
  }
20
73
 
74
+ void ADCSensor::set_sampling_mode(SamplingMode sampling_mode) { this->sampling_mode_ = sampling_mode; }
75
+
21
76
  float ADCSensor::get_setup_priority() const { return setup_priority::DATA; }
22
77
 
23
78
  } // namespace adc
@@ -78,12 +78,14 @@ void ADCSensor::dump_config() {
78
78
  }
79
79
  }
80
80
  ESP_LOGCONFIG(TAG, " Samples: %i", this->sample_count_);
81
+ ESP_LOGCONFIG(TAG, " Sampling mode: %s", LOG_STR_ARG(sampling_mode_to_str(this->sampling_mode_)));
81
82
  LOG_UPDATE_INTERVAL(this);
82
83
  }
83
84
 
84
85
  float ADCSensor::sample() {
85
86
  if (!this->autorange_) {
86
- uint32_t sum = 0;
87
+ auto aggr = Aggregator(this->sampling_mode_);
88
+
87
89
  for (uint8_t sample = 0; sample < this->sample_count_; sample++) {
88
90
  int raw = -1;
89
91
  if (this->channel1_ != ADC1_CHANNEL_MAX) {
@@ -94,13 +96,14 @@ float ADCSensor::sample() {
94
96
  if (raw == -1) {
95
97
  return NAN;
96
98
  }
97
- sum += raw;
99
+
100
+ aggr.add_sample(raw);
98
101
  }
99
- sum = (sum + (this->sample_count_ >> 1)) / this->sample_count_; // NOLINT(clang-analyzer-core.DivideZero)
100
102
  if (this->output_raw_) {
101
- return sum;
103
+ return aggr.aggregate();
102
104
  }
103
- uint32_t mv = esp_adc_cal_raw_to_voltage(sum, &this->cal_characteristics_[(int32_t) this->attenuation_]);
105
+ uint32_t mv =
106
+ esp_adc_cal_raw_to_voltage(aggr.aggregate(), &this->cal_characteristics_[(int32_t) this->attenuation_]);
104
107
  return mv / 1000.0f;
105
108
  }
106
109
 
@@ -31,23 +31,27 @@ void ADCSensor::dump_config() {
31
31
  LOG_PIN(" Pin: ", this->pin_);
32
32
  #endif // USE_ADC_SENSOR_VCC
33
33
  ESP_LOGCONFIG(TAG, " Samples: %i", this->sample_count_);
34
+ ESP_LOGCONFIG(TAG, " Sampling mode: %s", LOG_STR_ARG(sampling_mode_to_str(this->sampling_mode_)));
34
35
  LOG_UPDATE_INTERVAL(this);
35
36
  }
36
37
 
37
38
  float ADCSensor::sample() {
38
- uint32_t raw = 0;
39
+ auto aggr = Aggregator(this->sampling_mode_);
40
+
39
41
  for (uint8_t sample = 0; sample < this->sample_count_; sample++) {
42
+ uint32_t raw = 0;
40
43
  #ifdef USE_ADC_SENSOR_VCC
41
- raw += ESP.getVcc(); // NOLINT(readability-static-accessed-through-instance)
44
+ raw = ESP.getVcc(); // NOLINT(readability-static-accessed-through-instance)
42
45
  #else
43
- raw += analogRead(this->pin_->get_pin()); // NOLINT
46
+ raw = analogRead(this->pin_->get_pin()); // NOLINT
44
47
  #endif // USE_ADC_SENSOR_VCC
48
+ aggr.add_sample(raw);
45
49
  }
46
- raw = (raw + (this->sample_count_ >> 1)) / this->sample_count_; // NOLINT(clang-analyzer-core.DivideZero)
50
+
47
51
  if (this->output_raw_) {
48
- return raw;
52
+ return aggr.aggregate();
49
53
  }
50
- return raw / 1024.0f;
54
+ return aggr.aggregate() / 1024.0f;
51
55
  }
52
56
 
53
57
  std::string ADCSensor::unique_id() { return get_mac_address() + "-adc"; }
@@ -23,23 +23,28 @@ void ADCSensor::dump_config() {
23
23
  LOG_PIN(" Pin: ", this->pin_);
24
24
  #endif // USE_ADC_SENSOR_VCC
25
25
  ESP_LOGCONFIG(TAG, " Samples: %i", this->sample_count_);
26
+ ESP_LOGCONFIG(TAG, " Sampling mode: %s", LOG_STR_ARG(sampling_mode_to_str(this->sampling_mode_)));
26
27
  LOG_UPDATE_INTERVAL(this);
27
28
  }
28
29
 
29
30
  float ADCSensor::sample() {
30
31
  uint32_t raw = 0;
32
+ auto aggr = Aggregator(this->sampling_mode_);
33
+
31
34
  if (this->output_raw_) {
32
35
  for (uint8_t sample = 0; sample < this->sample_count_; sample++) {
33
- raw += analogRead(this->pin_->get_pin()); // NOLINT
36
+ raw = analogRead(this->pin_->get_pin()); // NOLINT
37
+ aggr.add_sample(raw);
34
38
  }
35
- raw = (raw + (this->sample_count_ >> 1)) / this->sample_count_; // NOLINT(clang-analyzer-core.DivideZero)
36
- return raw;
39
+ return aggr.aggregate();
37
40
  }
41
+
38
42
  for (uint8_t sample = 0; sample < this->sample_count_; sample++) {
39
- raw += analogReadVoltage(this->pin_->get_pin()); // NOLINT
43
+ raw = analogReadVoltage(this->pin_->get_pin()); // NOLINT
44
+ aggr.add_sample(raw);
40
45
  }
41
- raw = (raw + (this->sample_count_ >> 1)) / this->sample_count_; // NOLINT(clang-analyzer-core.DivideZero)
42
- return raw / 1000.0f;
46
+
47
+ return aggr.aggregate() / 1000.0f;
43
48
  }
44
49
 
45
50
  } // namespace adc
@@ -34,24 +34,28 @@ void ADCSensor::dump_config() {
34
34
  #endif // USE_ADC_SENSOR_VCC
35
35
  }
36
36
  ESP_LOGCONFIG(TAG, " Samples: %i", this->sample_count_);
37
+ ESP_LOGCONFIG(TAG, " Sampling mode: %s", LOG_STR_ARG(sampling_mode_to_str(this->sampling_mode_)));
37
38
  LOG_UPDATE_INTERVAL(this);
38
39
  }
39
40
 
40
41
  float ADCSensor::sample() {
42
+ uint32_t raw = 0;
43
+ auto aggr = Aggregator(this->sampling_mode_);
44
+
41
45
  if (this->is_temperature_) {
42
46
  adc_set_temp_sensor_enabled(true);
43
47
  delay(1);
44
48
  adc_select_input(4);
45
- uint32_t raw = 0;
49
+
46
50
  for (uint8_t sample = 0; sample < this->sample_count_; sample++) {
47
- raw += adc_read();
51
+ raw = adc_read();
52
+ aggr.add_sample(raw);
48
53
  }
49
- raw = (raw + (this->sample_count_ >> 1)) / this->sample_count_; // NOLINT(clang-analyzer-core.DivideZero)
50
54
  adc_set_temp_sensor_enabled(false);
51
55
  if (this->output_raw_) {
52
- return raw;
56
+ return aggr.aggregate();
53
57
  }
54
- return raw * 3.3f / 4096.0f;
58
+ return aggr.aggregate() * 3.3f / 4096.0f;
55
59
  }
56
60
 
57
61
  uint8_t pin = this->pin_->get_pin();
@@ -68,11 +72,10 @@ float ADCSensor::sample() {
68
72
  adc_gpio_init(pin);
69
73
  adc_select_input(pin - 26);
70
74
 
71
- uint32_t raw = 0;
72
75
  for (uint8_t sample = 0; sample < this->sample_count_; sample++) {
73
- raw += adc_read();
76
+ raw = adc_read();
77
+ aggr.add_sample(raw);
74
78
  }
75
- raw = (raw + (this->sample_count_ >> 1)) / this->sample_count_; // NOLINT(clang-analyzer-core.DivideZero)
76
79
 
77
80
  #ifdef CYW43_USES_VSYS_PIN
78
81
  if (pin == PICO_VSYS_PIN) {
@@ -81,10 +84,10 @@ float ADCSensor::sample() {
81
84
  #endif // CYW43_USES_VSYS_PIN
82
85
 
83
86
  if (this->output_raw_) {
84
- return raw;
87
+ return aggr.aggregate();
85
88
  }
86
89
  float coeff = pin == PICO_VSYS_PIN ? 3.0f : 1.0f;
87
- return raw * 3.3f / 4096.0f * coeff;
90
+ return aggr.aggregate() * 3.3f / 4096.0f * coeff;
88
91
  }
89
92
 
90
93
  } // namespace adc
@@ -1,11 +1,9 @@
1
1
  import logging
2
2
 
3
3
  import esphome.codegen as cg
4
- import esphome.config_validation as cv
5
- import esphome.final_validate as fv
6
- from esphome.core import CORE
7
4
  from esphome.components import sensor, voltage_sampler
8
5
  from esphome.components.esp32 import get_esp32_variant
6
+ import esphome.config_validation as cv
9
7
  from esphome.const import (
10
8
  CONF_ATTENUATION,
11
9
  CONF_ID,
@@ -17,10 +15,14 @@ from esphome.const import (
17
15
  STATE_CLASS_MEASUREMENT,
18
16
  UNIT_VOLT,
19
17
  )
18
+ from esphome.core import CORE
19
+ import esphome.final_validate as fv
20
+
20
21
  from . import (
21
22
  ATTENUATION_MODES,
22
23
  ESP32_VARIANT_ADC1_PIN_TO_CHANNEL,
23
24
  ESP32_VARIANT_ADC2_PIN_TO_CHANNEL,
25
+ SAMPLING_MODES,
24
26
  adc_ns,
25
27
  validate_adc_pin,
26
28
  )
@@ -30,9 +32,11 @@ _LOGGER = logging.getLogger(__name__)
30
32
  AUTO_LOAD = ["voltage_sampler"]
31
33
 
32
34
  CONF_SAMPLES = "samples"
35
+ CONF_SAMPLING_MODE = "sampling_mode"
33
36
 
34
37
 
35
38
  _attenuation = cv.enum(ATTENUATION_MODES, lower=True)
39
+ _sampling_mode = cv.enum(SAMPLING_MODES, lower=True)
36
40
 
37
41
 
38
42
  def validate_config(config):
@@ -88,6 +92,7 @@ CONFIG_SCHEMA = cv.All(
88
92
  cv.only_on_esp32, _attenuation
89
93
  ),
90
94
  cv.Optional(CONF_SAMPLES, default=1): cv.int_range(min=1, max=255),
95
+ cv.Optional(CONF_SAMPLING_MODE, default="avg"): _sampling_mode,
91
96
  }
92
97
  )
93
98
  .extend(cv.polling_component_schema("60s")),
@@ -112,6 +117,7 @@ async def to_code(config):
112
117
 
113
118
  cg.add(var.set_output_raw(config[CONF_RAW]))
114
119
  cg.add(var.set_sample_count(config[CONF_SAMPLES]))
120
+ cg.add(var.set_sampling_mode(config[CONF_SAMPLING_MODE]))
115
121
 
116
122
  if attenuation := config.get(CONF_ATTENUATION):
117
123
  if attenuation == "auto":
@@ -9,8 +9,6 @@ static const char *const TAG = "ads1115";
9
9
  static const uint8_t ADS1115_REGISTER_CONVERSION = 0x00;
10
10
  static const uint8_t ADS1115_REGISTER_CONFIG = 0x01;
11
11
 
12
- static const uint8_t ADS1115_DATA_RATE_860_SPS = 0b111; // 3300_SPS for ADS1015
13
-
14
12
  void ADS1115Component::setup() {
15
13
  ESP_LOGCONFIG(TAG, "Setting up ADS1115...");
16
14
  uint16_t value;
@@ -43,9 +41,9 @@ void ADS1115Component::setup() {
43
41
  config |= 0b0000000100000000;
44
42
  }
45
43
 
46
- // Set data rate - 860 samples per second (we're in singleshot mode)
44
+ // Set data rate - 860 samples per second
47
45
  // 0bxxxxxxxx100xxxxx
48
- config |= ADS1115_DATA_RATE_860_SPS << 5;
46
+ config |= ADS1115_860SPS << 5;
49
47
 
50
48
  // Set comparator mode - hysteresis
51
49
  // 0bxxxxxxxxxxx0xxxx
@@ -77,7 +75,7 @@ void ADS1115Component::dump_config() {
77
75
  }
78
76
  }
79
77
  float ADS1115Component::request_measurement(ADS1115Multiplexer multiplexer, ADS1115Gain gain,
80
- ADS1115Resolution resolution) {
78
+ ADS1115Resolution resolution, ADS1115Samplerate samplerate) {
81
79
  uint16_t config = this->prev_config_;
82
80
  // Multiplexer
83
81
  // 0bxBBBxxxxxxxxxxxx
@@ -89,6 +87,11 @@ float ADS1115Component::request_measurement(ADS1115Multiplexer multiplexer, ADS1
89
87
  config &= 0b1111000111111111;
90
88
  config |= (gain & 0b111) << 9;
91
89
 
90
+ // Sample rate
91
+ // 0bxxxxxxxxBBBxxxxx
92
+ config &= 0b1111111100011111;
93
+ config |= (samplerate & 0b111) << 5;
94
+
92
95
  if (!this->continuous_mode_) {
93
96
  // Start conversion
94
97
  config |= 0b1000000000000000;
@@ -101,8 +104,54 @@ float ADS1115Component::request_measurement(ADS1115Multiplexer multiplexer, ADS1
101
104
  }
102
105
  this->prev_config_ = config;
103
106
 
104
- // about 1.2 ms with 860 samples per second
105
- delay(2);
107
+ // Delay calculated as: ceil((1000/SPS)+.5)
108
+ if (resolution == ADS1015_12_BITS) {
109
+ switch (samplerate) {
110
+ case ADS1115_8SPS:
111
+ delay(9);
112
+ break;
113
+ case ADS1115_16SPS:
114
+ delay(5);
115
+ break;
116
+ case ADS1115_32SPS:
117
+ delay(3);
118
+ break;
119
+ case ADS1115_64SPS:
120
+ case ADS1115_128SPS:
121
+ delay(2);
122
+ break;
123
+ default:
124
+ delay(1);
125
+ break;
126
+ }
127
+ } else {
128
+ switch (samplerate) {
129
+ case ADS1115_8SPS:
130
+ delay(126); // NOLINT
131
+ break;
132
+ case ADS1115_16SPS:
133
+ delay(63); // NOLINT
134
+ break;
135
+ case ADS1115_32SPS:
136
+ delay(32);
137
+ break;
138
+ case ADS1115_64SPS:
139
+ delay(17);
140
+ break;
141
+ case ADS1115_128SPS:
142
+ delay(9);
143
+ break;
144
+ case ADS1115_250SPS:
145
+ delay(5);
146
+ break;
147
+ case ADS1115_475SPS:
148
+ delay(3);
149
+ break;
150
+ case ADS1115_860SPS:
151
+ delay(2);
152
+ break;
153
+ }
154
+ }
106
155
 
107
156
  // in continuous mode, conversion will always be running, rely on the delay
108
157
  // to ensure conversion is taking place with the correct settings
@@ -33,6 +33,17 @@ enum ADS1115Resolution {
33
33
  ADS1015_12_BITS = 12,
34
34
  };
35
35
 
36
+ enum ADS1115Samplerate {
37
+ ADS1115_8SPS = 0b000,
38
+ ADS1115_16SPS = 0b001,
39
+ ADS1115_32SPS = 0b010,
40
+ ADS1115_64SPS = 0b011,
41
+ ADS1115_128SPS = 0b100,
42
+ ADS1115_250SPS = 0b101,
43
+ ADS1115_475SPS = 0b110,
44
+ ADS1115_860SPS = 0b111
45
+ };
46
+
36
47
  class ADS1115Component : public Component, public i2c::I2CDevice {
37
48
  public:
38
49
  void setup() override;
@@ -42,7 +53,8 @@ class ADS1115Component : public Component, public i2c::I2CDevice {
42
53
  void set_continuous_mode(bool continuous_mode) { continuous_mode_ = continuous_mode; }
43
54
 
44
55
  /// Helper method to request a measurement from a sensor.
45
- float request_measurement(ADS1115Multiplexer multiplexer, ADS1115Gain gain, ADS1115Resolution resolution);
56
+ float request_measurement(ADS1115Multiplexer multiplexer, ADS1115Gain gain, ADS1115Resolution resolution,
57
+ ADS1115Samplerate samplerate);
46
58
 
47
59
  protected:
48
60
  uint16_t prev_config_{0};
@@ -5,6 +5,7 @@ from esphome.const import (
5
5
  CONF_GAIN,
6
6
  CONF_MULTIPLEXER,
7
7
  CONF_RESOLUTION,
8
+ CONF_SAMPLE_RATE,
8
9
  DEVICE_CLASS_VOLTAGE,
9
10
  STATE_CLASS_MEASUREMENT,
10
11
  UNIT_VOLT,
@@ -43,6 +44,17 @@ RESOLUTION = {
43
44
  "12_BITS": ADS1115Resolution.ADS1015_12_BITS,
44
45
  }
45
46
 
47
+ ADS1115Samplerate = ads1115_ns.enum("ADS1115Samplerate")
48
+ SAMPLERATE = {
49
+ "8": ADS1115Samplerate.ADS1115_8SPS,
50
+ "16": ADS1115Samplerate.ADS1115_16SPS,
51
+ "32": ADS1115Samplerate.ADS1115_32SPS,
52
+ "64": ADS1115Samplerate.ADS1115_64SPS,
53
+ "128": ADS1115Samplerate.ADS1115_128SPS,
54
+ "250": ADS1115Samplerate.ADS1115_250SPS,
55
+ "475": ADS1115Samplerate.ADS1115_475SPS,
56
+ "860": ADS1115Samplerate.ADS1115_860SPS,
57
+ }
46
58
 
47
59
  ADS1115Sensor = ads1115_ns.class_(
48
60
  "ADS1115Sensor", sensor.Sensor, cg.PollingComponent, voltage_sampler.VoltageSampler
@@ -64,6 +76,9 @@ CONFIG_SCHEMA = (
64
76
  cv.Optional(CONF_RESOLUTION, default="16_BITS"): cv.enum(
65
77
  RESOLUTION, upper=True, space="_"
66
78
  ),
79
+ cv.Optional(CONF_SAMPLE_RATE, default="860"): cv.enum(
80
+ SAMPLERATE, string=True
81
+ ),
67
82
  }
68
83
  )
69
84
  .extend(cv.polling_component_schema("60s"))
@@ -79,3 +94,4 @@ async def to_code(config):
79
94
  cg.add(var.set_multiplexer(config[CONF_MULTIPLEXER]))
80
95
  cg.add(var.set_gain(config[CONF_GAIN]))
81
96
  cg.add(var.set_resolution(config[CONF_RESOLUTION]))
97
+ cg.add(var.set_samplerate(config[CONF_SAMPLE_RATE]))
@@ -8,7 +8,7 @@ namespace ads1115 {
8
8
  static const char *const TAG = "ads1115.sensor";
9
9
 
10
10
  float ADS1115Sensor::sample() {
11
- return this->parent_->request_measurement(this->multiplexer_, this->gain_, this->resolution_);
11
+ return this->parent_->request_measurement(this->multiplexer_, this->gain_, this->resolution_, this->samplerate_);
12
12
  }
13
13
 
14
14
  void ADS1115Sensor::update() {
@@ -24,6 +24,7 @@ void ADS1115Sensor::dump_config() {
24
24
  ESP_LOGCONFIG(TAG, " Multiplexer: %u", this->multiplexer_);
25
25
  ESP_LOGCONFIG(TAG, " Gain: %u", this->gain_);
26
26
  ESP_LOGCONFIG(TAG, " Resolution: %u", this->resolution_);
27
+ ESP_LOGCONFIG(TAG, " Sample rate: %u", this->samplerate_);
27
28
  }
28
29
 
29
30
  } // namespace ads1115
@@ -21,6 +21,7 @@ class ADS1115Sensor : public sensor::Sensor,
21
21
  void set_multiplexer(ADS1115Multiplexer multiplexer) { this->multiplexer_ = multiplexer; }
22
22
  void set_gain(ADS1115Gain gain) { this->gain_ = gain; }
23
23
  void set_resolution(ADS1115Resolution resolution) { this->resolution_ = resolution; }
24
+ void set_samplerate(ADS1115Samplerate samplerate) { this->samplerate_ = samplerate; }
24
25
  float sample() override;
25
26
 
26
27
  void dump_config() override;
@@ -29,6 +30,7 @@ class ADS1115Sensor : public sensor::Sensor,
29
30
  ADS1115Multiplexer multiplexer_;
30
31
  ADS1115Gain gain_;
31
32
  ADS1115Resolution resolution_;
33
+ ADS1115Samplerate samplerate_;
32
34
  };
33
35
 
34
36
  } // namespace ads1115